]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/doc-unit-tests-with-cmake'
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Dec 2023 00:37:47 +0000 (16:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Dec 2023 00:37:47 +0000 (16:37 -0800)
Update the base topic to work with CMake builds.

* js/doc-unit-tests-with-cmake:
  cmake: handle also unit tests
  cmake: use test names instead of full paths
  cmake: fix typo in variable name
  artifacts-tar: when including `.dll` files, don't forget the unit-tests
  unit-tests: do show relative file paths
  unit-tests: do not mistake `.pdb` files for being executable
  cmake: also build unit tests

1  2 
Makefile
contrib/buildsystems/CMakeLists.txt

diff --combined Makefile
index 36b65d7db5e60a1c944b24e139c307be8c4ffb08,e15c34e506a2ae175b646d0266c744e00d2fa744..f7f7ef0167c45558b2a78fc35ea1e0a592c1be7d
+++ b/Makefile
@@@ -803,7 -803,6 +803,7 @@@ TEST_BUILTINS_OBJS += test-dump-untrack
  TEST_BUILTINS_OBJS += test-env-helper.o
  TEST_BUILTINS_OBJS += test-example-decorate.o
  TEST_BUILTINS_OBJS += test-fast-rebase.o
 +TEST_BUILTINS_OBJS += test-find-pack.o
  TEST_BUILTINS_OBJS += test-fsmonitor-client.o
  TEST_BUILTINS_OBJS += test-genrandom.o
  TEST_BUILTINS_OBJS += test-genzeros.o
@@@ -812,6 -811,7 +812,6 @@@ TEST_BUILTINS_OBJS += test-hash-speed.
  TEST_BUILTINS_OBJS += test-hash.o
  TEST_BUILTINS_OBJS += test-hashmap.o
  TEST_BUILTINS_OBJS += test-hexdump.o
 -TEST_BUILTINS_OBJS += test-index-version.o
  TEST_BUILTINS_OBJS += test-json-writer.o
  TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
  TEST_BUILTINS_OBJS += test-match-trees.o
@@@ -855,7 -855,6 +855,7 @@@ TEST_BUILTINS_OBJS += test-submodule-ne
  TEST_BUILTINS_OBJS += test-submodule.o
  TEST_BUILTINS_OBJS += test-subprocess.o
  TEST_BUILTINS_OBJS += test-trace2.o
 +TEST_BUILTINS_OBJS += test-truncate.o
  TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
  TEST_BUILTINS_OBJS += test-userdiff.o
  TEST_BUILTINS_OBJS += test-wildmatch.o
@@@ -1044,7 -1043,6 +1044,7 @@@ LIB_OBJS += hash-lookup.
  LIB_OBJS += hashmap.o
  LIB_OBJS += help.o
  LIB_OBJS += hex.o
 +LIB_OBJS += hex-ll.o
  LIB_OBJS += hook.o
  LIB_OBJS += ident.o
  LIB_OBJS += json-writer.o
@@@ -1056,6 -1054,7 +1056,6 @@@ LIB_OBJS += linear-assignment.
  LIB_OBJS += list-objects-filter-options.o
  LIB_OBJS += list-objects-filter.o
  LIB_OBJS += list-objects.o
 -LIB_OBJS += ll-merge.o
  LIB_OBJS += lockfile.o
  LIB_OBJS += log-tree.o
  LIB_OBJS += ls-refs.o
@@@ -1064,7 -1063,6 +1064,7 @@@ LIB_OBJS += mailmap.
  LIB_OBJS += match-trees.o
  LIB_OBJS += mem-pool.o
  LIB_OBJS += merge-blobs.o
 +LIB_OBJS += merge-ll.o
  LIB_OBJS += merge-ort.o
  LIB_OBJS += merge-ort-wrappers.o
  LIB_OBJS += merge-recursive.o
@@@ -1095,7 -1093,6 +1095,7 @@@ LIB_OBJS += pack-write.
  LIB_OBJS += packfile.o
  LIB_OBJS += pager.o
  LIB_OBJS += parallel-checkout.o
 +LIB_OBJS += parse.o
  LIB_OBJS += parse-options-cb.o
  LIB_OBJS += parse-options.o
  LIB_OBJS += patch-delta.o
@@@ -1148,7 -1145,6 +1148,7 @@@ LIB_OBJS += sigchain.
  LIB_OBJS += sparse-index.o
  LIB_OBJS += split-index.o
  LIB_OBJS += stable-qsort.o
 +LIB_OBJS += statinfo.o
  LIB_OBJS += strbuf.o
  LIB_OBJS += streaming.o
  LIB_OBJS += string-list.o
@@@ -1964,7 -1960,7 +1964,7 @@@ endi
        BASIC_CFLAGS += \
                -DSHA1DC_NO_STANDARD_INCLUDES \
                -DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
 -              -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
 +              -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"git-compat-util.h\"" \
                -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
  endif
  endif
@@@ -2756,8 -2752,8 +2756,8 @@@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTR
        '-DBINDIR="$(bindir_relative_SQ)"' \
        '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
  
 -builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
 -builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
 +setup.sp setup.s setup.o: GIT-PREFIX
 +setup.sp setup.s setup.o: EXTRA_CPPFLAGS = \
        -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
  
  config.sp config.s config.o: GIT-PREFIX
@@@ -2792,13 -2788,6 +2792,13 @@@ compat/nedmalloc/nedmalloc.sp compat/ne
  compat/nedmalloc/nedmalloc.sp: SP_EXTRA_FLAGS += -Wno-non-pointer-null
  endif
  
 +headless-git.o: compat/win32/headless.c GIT-CFLAGS
 +      $(QUIET_CC)$(CC) $(ALL_CFLAGS) $(COMPAT_CFLAGS) \
 +              -fno-stack-protector -o $@ -c -Wall -Wwrite-strings $<
 +
 +headless-git$X: headless-git.o git.res GIT-LDFLAGS
 +      $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -mwindows -o $@ $< git.res
 +
  git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
  
@@@ -3236,12 -3225,6 +3236,12 @@@ $(SP_OBJ): %.sp: %.c %.
  sparse: $(SP_OBJ)
  
  EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%
 +ifndef OPENSSL_SHA1
 +      EXCEPT_HDRS += sha1/openssl.h
 +endif
 +ifndef OPENSSL_SHA256
 +      EXCEPT_HDRS += sha256/openssl.h
 +endif
  ifndef NETTLE_SHA256
        EXCEPT_HDRS += sha256/nettle.h
  endif
@@@ -3614,7 -3597,7 +3614,7 @@@ rpm:
  .PHONY: rpm
  
  ifneq ($(INCLUDE_DLLS_IN_ARTIFACTS),)
- OTHER_PROGRAMS += $(shell echo *.dll t/helper/*.dll)
+ OTHER_PROGRAMS += $(shell echo *.dll t/helper/*.dll t/unit-tests/bin/*.dll)
  endif
  
  artifacts-tar:: $(ALL_COMMANDS_TO_INSTALL) $(SCRIPT_LIB) $(OTHER_PROGRAMS) \
@@@ -3678,7 -3661,6 +3678,7 @@@ clean: profile-clean coverage-clean coc
        $(RM) po/git.pot po/git-core.pot
        $(RM) git.res
        $(RM) $(OBJECTS)
 +      $(RM) headless-git.o
        $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
        $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)
        $(RM) $(TEST_PROGRAMS) $(UNIT_TEST_PROGS)
@@@ -3707,7 -3689,6 +3707,7 @@@ endi
        $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
  ifdef MSVC
        $(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
 +      $(RM) headless-git.o.pdb
        $(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
        $(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
        $(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
index 6b819e2fbdf357f8401a29b5f8daa29e43284cfe,671c7ead75381dfb0ef84a97091404b18e388ff5..804629c525b1b1978512c9d15b710bfebeef185e
@@@ -227,7 -227,7 +227,7 @@@ add_compile_definitions(GIT_HOST_CPU="$
  add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
  add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
                        SHA1DC_INIT_SAFE_HASH_DEFAULT=0
 -                      SHA1DC_CUSTOM_INCLUDE_SHA1_C="cache.h"
 +                      SHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"
                        SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
  list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)
  
@@@ -738,15 -738,6 +738,15 @@@ if(WIN32
        else()
                message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
        endif()
 +
 +      add_executable(headless-git ${CMAKE_SOURCE_DIR}/compat/win32/headless.c)
 +      if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
 +              target_link_options(headless-git PUBLIC -municode -Wl,-subsystem,windows)
 +      elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
 +              target_link_options(headless-git PUBLIC /NOLOGO /ENTRY:wWinMainCRTStartup /SUBSYSTEM:WINDOWS)
 +      else()
 +              message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
 +      endif()
  elseif(UNIX)
        target_link_libraries(common-main pthread rt)
  endif()
@@@ -974,6 -965,35 +974,35 @@@ target_link_libraries(test-fake-ssh com
  parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
  list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
  
+ #unit-tests
+ add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
+ parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "")
+ foreach(unit_test ${unit_test_PROGRAMS})
+       add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c")
+       target_link_libraries("${unit_test}" unit-test-lib common-main)
+       set_target_properties("${unit_test}"
+               PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+       if(MSVC)
+               set_target_properties("${unit_test}"
+                       PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+               set_target_properties("${unit_test}"
+                       PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+       endif()
+       list(APPEND PROGRAMS_BUILT "${unit_test}")
+       # t-basic intentionally fails tests, to validate the unit-test infrastructure.
+       # Therefore, it should only be run as part of t0080, which verifies that it
+       # fails only in the expected ways.
+       #
+       # All other unit tests should be run.
+       if(NOT ${unit_test} STREQUAL "t-basic")
+               add_test(NAME "t.unit-tests.${unit_test}"
+                       COMMAND "./${unit_test}"
+                       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t/unit-tests/bin)
+       endif()
+ endforeach()
  #test-tool
  parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
  
@@@ -1093,17 -1113,18 +1122,18 @@@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.t
        file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
  endif()
  
- file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
+ file(GLOB test_scripts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
  
  #test
- foreach(tsh ${test_scipts})
-       add_test(NAME ${tsh}
+ foreach(tsh ${test_scripts})
+       string(REGEX REPLACE ".*/(.*)\\.sh" "\\1" test_name ${tsh})
+       add_test(NAME "t.suite.${test_name}"
                COMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
  endforeach()
  
  # This test script takes an extremely long time and is known to time out even
  # on fast machines because it requires in excess of one hour to run
- set_tests_properties("${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh" PROPERTIES TIMEOUT 4000)
+ set_tests_properties("t.suite.t7112-reset-submodule" PROPERTIES TIMEOUT 4000)
  
  endif()#BUILD_TESTING