scalar: include in standard Git build & installation

Move 'scalar' out of 'contrib/' and into the root of the Git tree. The goal of this change is to build 'scalar' as part of the standard Git build & install processes. This patch includes both the physical move of Scalar's files out of 'contrib/' ('scalar.c', 'scalar.txt', and 't9xxx-scalar.sh'), and the changes to the build definitions in 'Makefile' and 'CMakelists.txt' to accommodate the new program. At a high level, Scalar is built so that: - there is a 'scalar-objs' target (similar to those created in 029bac01a8 (Makefile: add {program,xdiff,test,git,fuzz}-objs & objects targets, 2021-02-23)) for debugging purposes. - it appears in the root of the install directory (rather than the gitexecdir). - it is included in the 'bin-wrappers/' directory for use in tests. - it receives a platform-specific executable suffix (e.g., '.exe'), if applicable. - 'scalar.txt' is installed as 'man1' documentation. - the 'clean' target removes the 'scalar' executable. Additionally, update the root level '.gitignore' file to ignore the Scalar executable. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Victoria Dye committed Sep 2, 2022 at 15:56 UTC 7b5c93c6c6847b4b6037e38418bc8bbb8c2eada8
10 files changed +28 -142
.gitignore
+1
@@ -185,6 +185,7 @@
185 /git-whatchanged
186 /git-worktree
187 /git-write-tree
188 +/scalar
189 /git-core-*/?*
190 /git.res
191 /gitweb/GITWEB-BUILD-OPTIONS
Documentation/Makefile
+1
@@ -21,6 +21,7 @@ MAN1_TXT += $(filter-out \
21 MAN1_TXT += git.txt
22 MAN1_TXT += gitk.txt
23 MAN1_TXT += gitweb.txt
24 +MAN1_TXT += scalar.txt
25
26 # man5 / man7 guides (note: new guides should also be added to command-list.txt)
27 MAN5_TXT += gitattributes.txt
Documentation/scalar.txt renamed
Makefile
+18 -13
@@ -608,7 +608,9 @@ FUZZ_OBJS =
608 FUZZ_PROGRAMS =
609 GIT_OBJS =
610 LIB_OBJS =
611 +SCALAR_OBJS =
612 OBJECTS =
613 +OTHER_PROGRAMS =
614 PROGRAM_OBJS =
615 PROGRAMS =
616 EXCLUDED_PROGRAMS =
@@ -821,10 +823,12 @@ BUILT_INS += git-switch$X
823 BUILT_INS += git-whatchanged$X
824
825 # what 'all' will build but not install in gitexecdir
824 -OTHER_PROGRAMS = git$X
826 +OTHER_PROGRAMS += git$X
827 +OTHER_PROGRAMS += scalar$X
828
829 # what test wrappers are needed and 'install' will install, in bindir
830 BINDIR_PROGRAMS_NEED_X += git
831 +BINDIR_PROGRAMS_NEED_X += scalar
832 BINDIR_PROGRAMS_NEED_X += git-receive-pack
833 BINDIR_PROGRAMS_NEED_X += git-shell
834 BINDIR_PROGRAMS_NEED_X += git-upload-archive
@@ -2222,7 +2226,7 @@ profile-fast: profile-clean
2226
2227 all:: $(ALL_COMMANDS_TO_INSTALL) $(SCRIPT_LIB) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
2228 ifneq (,$X)
2225 - $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) git$X)), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
2229 + $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
2230 endif
2231
2232 all::
@@ -2545,7 +2549,12 @@ GIT_OBJS += git.o
2549 .PHONY: git-objs
2550 git-objs: $(GIT_OBJS)
2551
2552 +SCALAR_OBJS += scalar.o
2553 +.PHONY: scalar-objs
2554 +scalar-objs: $(SCALAR_OBJS)
2555 +
2556 OBJECTS += $(GIT_OBJS)
2557 +OBJECTS += $(SCALAR_OBJS)
2558 OBJECTS += $(PROGRAM_OBJS)
2559 OBJECTS += $(TEST_OBJS)
2560 OBJECTS += $(XDIFF_OBJS)
@@ -2556,10 +2565,6 @@ ifndef NO_CURL
2565 OBJECTS += http.o http-walker.o remote-curl.o
2566 endif
2567
2559 -SCALAR_SOURCES := contrib/scalar/scalar.c
2560 -SCALAR_OBJECTS := $(SCALAR_SOURCES:c=o)
2561 -OBJECTS += $(SCALAR_OBJECTS)
2562 -
2568 .PHONY: objects
2569 objects: $(OBJECTS)
2570
@@ -2691,7 +2696,7 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS
2696 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2697 $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
2698
2694 -contrib/scalar/scalar$X: $(SCALAR_OBJECTS) GIT-LDFLAGS $(GITLIBS)
2699 +scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
2700 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
2701 $(filter %.o,$^) $(LIBS)
2702
@@ -2747,8 +2752,7 @@ XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
2752 XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
2753 --keyword=__ --keyword=N__ --keyword="__n:1,2"
2754 MSGMERGE_FLAGS = --add-location --backup=off --update
2750 -LOCALIZED_C = $(sort $(FOUND_C_SOURCES) $(FOUND_H_SOURCES) $(SCALAR_SOURCES) \
2751 - $(GENERATED_H))
2755 +LOCALIZED_C = $(sort $(FOUND_C_SOURCES) $(FOUND_H_SOURCES) $(GENERATED_H))
2756 LOCALIZED_SH = $(sort $(SCRIPT_SH) git-sh-setup.sh)
2757 LOCALIZED_PERL = $(sort $(SCRIPT_PERL))
2758
@@ -3062,7 +3066,7 @@ bin-wrappers/%: wrap-for-bin.sh
3066 $(call mkdir_p_parent_template)
3067 $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
3068 -e 's|@@BUILD_DIR@@|$(shell pwd)|' \
3065 - -e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%$(X),$(@F))$(patsubst git%,$(X),$(filter $(@F),$(BINDIR_PROGRAMS_NEED_X)))|' < $< > $@ && \
3069 + -e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%,$(@F))$(if $(filter-out $(BINDIR_PROGRAMS_NO_X),$(@F)),$(X),)|' < $< > $@ && \
3070 chmod +x $@
3071
3072 # GNU make supports exporting all variables by "export" without parameters.
@@ -3276,14 +3280,14 @@ ifndef NO_TCLTK
3280 $(MAKE) -C git-gui gitexecdir='$(gitexec_instdir_SQ)' install
3281 endif
3282 ifneq (,$X)
3279 - $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) git$X)), test '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p' -ef '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p$X' || $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
3283 + $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), test '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p' -ef '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p$X' || $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
3284 endif
3285
3286 bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
3287 execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
3288 destdir_from_execdir_SQ=$$(echo '$(gitexecdir_relative_SQ)' | sed -e 's|[^/][^/]*|..|g') && \
3289 { test "$$bindir/" = "$$execdir/" || \
3286 - for p in git$X $(filter $(install_bindir_programs),$(ALL_PROGRAMS)); do \
3290 + for p in $(OTHER_PROGRAMS) $(filter $(install_bindir_programs),$(ALL_PROGRAMS)); do \
3291 $(RM) "$$execdir/$$p" && \
3292 test -n "$(INSTALL_SYMLINKS)" && \
3293 ln -s "$$destdir_from_execdir_SQ/$(bindir_relative_SQ)/$$p" "$$execdir/$$p" || \
@@ -3458,7 +3462,7 @@ clean: profile-clean coverage-clean cocciclean
3462 $(RM) git.res
3463 $(RM) $(OBJECTS)
3464 $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
3461 - $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
3465 + $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)
3466 $(RM) $(TEST_PROGRAMS)
3467 $(RM) $(FUZZ_PROGRAMS)
3468 $(RM) $(SP_OBJ)
@@ -3509,6 +3513,7 @@ ALL_COMMANDS += git-citool
3513 ALL_COMMANDS += git-gui
3514 ALL_COMMANDS += gitk
3515 ALL_COMMANDS += gitweb
3516 +ALL_COMMANDS += scalar
3517
3518 .PHONY: check-docs
3519 check-docs::
contrib/buildsystems/CMakeLists.txt
+6 -3
@@ -610,7 +610,7 @@ unset(CMAKE_REQUIRED_INCLUDES)
610 #programs
611 set(PROGRAMS_BUILT
612 git git-daemon git-http-backend git-sh-i18n--envsubst
613 - git-shell)
613 + git-shell scalar)
614
615 if(NOT CURL_FOUND)
616 list(APPEND excluded_progs git-http-fetch git-http-push)
@@ -757,6 +757,9 @@ target_link_libraries(git-sh-i18n--envsubst common-main)
757 add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c)
758 target_link_libraries(git-shell common-main)
759
760 +add_executable(scalar ${CMAKE_SOURCE_DIR}/scalar.c)
761 +target_link_libraries(scalar common-main)
762 +
763 if(CURL_FOUND)
764 add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c)
765
@@ -903,7 +906,7 @@ list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
906
907 #install
908 foreach(program ${PROGRAMS_BUILT})
906 -if(program STREQUAL "git" OR program STREQUAL "git-shell")
909 +if(program MATCHES "^(git|git-shell|scalar)$")
910 install(TARGETS ${program}
911 RUNTIME DESTINATION bin)
912 else()
@@ -977,7 +980,7 @@ endif()
980
981 #wrapper scripts
982 set(wrapper_scripts
980 - git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext)
983 + git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext scalar)
984
985 set(wrapper_test_scripts
986 test-fake-ssh test-tool)
contrib/scalar/.gitignore deleted
-2
@@ -1,2 +0,0 @@
1 -/*.exe
2 -/scalar
contrib/scalar/Makefile deleted
-35
@@ -1,35 +0,0 @@
1 -# The default target of this Makefile is...
2 -all::
3 -
4 -# Import tree-wide shared Makefile behavior and libraries
5 -include ../../shared.mak
6 -
7 -include ../../config.mak.uname
8 --include ../../config.mak.autogen
9 --include ../../config.mak
10 -
11 -TARGETS = scalar$(X) scalar.o
12 -GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a
13 -
14 -all:: scalar$(X) ../../bin-wrappers/scalar
15 -
16 -$(GITLIBS):
17 - $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@)
18 -
19 -$(TARGETS): $(GITLIBS) scalar.c
20 - $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@)
21 -
22 -clean:
23 - $(RM) $(TARGETS) ../../bin-wrappers/scalar
24 -
25 -../../bin-wrappers/scalar: ../../wrap-for-bin.sh Makefile
26 - @mkdir -p ../../bin-wrappers
27 - $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
28 - -e 's|@@BUILD_DIR@@|$(shell cd ../.. && pwd)|' \
29 - -e 's|@@PROG@@|contrib/scalar/scalar$(X)|' < $< > $@ && \
30 - chmod +x $@
31 -
32 -test: all
33 - $(MAKE) -C t
34 -
35 -.PHONY: $(GITLIBS) all clean test FORCE
contrib/scalar/t/Makefile deleted
-81
@@ -1,81 +0,0 @@
1 -# Import tree-wide shared Makefile behavior and libraries
2 -include ../../../shared.mak
3 -
4 -# Run scalar tests
5 -#
6 -# Copyright (c) 2005,2021 Junio C Hamano, Johannes Schindelin
7 -#
8 -
9 --include ../../../config.mak.autogen
10 --include ../../../config.mak
11 -
12 -SHELL_PATH ?= $(SHELL)
13 -PERL_PATH ?= /usr/bin/perl
14 -RM ?= rm -f
15 -PROVE ?= prove
16 -DEFAULT_TEST_TARGET ?= test
17 -TEST_LINT ?= test-lint
18 -
19 -ifdef TEST_OUTPUT_DIRECTORY
20 -TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
21 -else
22 -TEST_RESULTS_DIRECTORY = ../../../t/test-results
23 -endif
24 -
25 -# Shell quote;
26 -SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
27 -PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
28 -TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
29 -
30 -T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
31 -
32 -all: $(DEFAULT_TEST_TARGET)
33 -
34 -test: $(TEST_LINT)
35 - $(MAKE) aggregate-results-and-cleanup
36 -
37 -prove: $(TEST_LINT)
38 - @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
39 - $(MAKE) clean-except-prove-cache
40 -
41 -$(T):
42 - @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
43 -
44 -clean-except-prove-cache:
45 - $(RM) -r 'trash directory'.*
46 - $(RM) -r valgrind/bin
47 -
48 -clean: clean-except-prove-cache
49 - $(RM) .prove
50 -
51 -test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax
52 -
53 -test-lint-duplicates:
54 - @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
55 - test -z "$$dups" || { \
56 - echo >&2 "duplicate test numbers:" $$dups; exit 1; }
57 -
58 -test-lint-executable:
59 - @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \
60 - test -z "$$bad" || { \
61 - echo >&2 "non-executable tests:" $$bad; exit 1; }
62 -
63 -test-lint-shell-syntax:
64 - @'$(PERL_PATH_SQ)' ../../../t/check-non-portable-shell.pl $(T)
65 -
66 -aggregate-results-and-cleanup: $(T)
67 - $(MAKE) aggregate-results
68 - $(MAKE) clean
69 -
70 -aggregate-results:
71 - for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
72 - echo "$$f"; \
73 - done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh
74 -
75 -valgrind:
76 - $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
77 -
78 -test-results:
79 - mkdir -p test-results
80 -
81 -.PHONY: $(T) aggregate-results clean valgrind
scalar.c renamed
t/t9210-scalar.sh renamed
+2 -8
@@ -2,15 +2,9 @@
2
3 test_description='test the `scalar` command'
4
5 -TEST_DIRECTORY=$PWD/../../../t
6 -export TEST_DIRECTORY
5 +. ./test-lib.sh
6
8 -# Make it work with --no-bin-wrappers
9 -PATH=$PWD/..:$PATH
10 -
11 -. ../../../t/test-lib.sh
12 -
13 -GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt,launchctl:true,schtasks:true"
7 +GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
8 export GIT_TEST_MAINT_SCHEDULER
9
10 test_expect_success 'scalar shows a usage' '