git-gui: Gracefully handle bad TCL_PATH at compile time
Petr Baudis pointed out the main git.git repository's Makefile dies now if git-gui 0.7.0-rc1 or later is being used and TCL_PATH was not set to a working tclsh program path. This breaks people who may have a working build configuration today and suddenly upgrade to the latest git release. The tclIndex is required for git-gui to load its associated lib files, but using the Tcl auto_load procedure to source only the files we need is a performance optimization. We can emulate the auto_load by just source'ing every file in that directory, assuming we source class.tcl first to initialize our crude class system. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
May 17, 2007 at 18:01 UTC
b9e7efb8b5f7d424466dd1ce61fd20658f60543f
2 files changed
+44
-4
Makefile
+16
-3
@@ -11,6 +11,7 @@ SCRIPT_SH = git-gui.sh
11
GITGUI_BUILT_INS = git-citool
12
ALL_PROGRAMS = $(GITGUI_BUILT_INS) $(patsubst %.sh,%,$(SCRIPT_SH))
13
ALL_LIBFILES = $(wildcard lib/*.tcl)
14
+PRELOAD_FILES = lib/class.tcl
15
16
ifndef SHELL_PATH
17
SHELL_PATH = /bin/sh
@@ -32,6 +33,7 @@ ifndef V
33
QUIET_GEN = @echo ' ' GEN $@;
34
QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
35
QUIET_INDEX = @echo ' ' INDEX $(dir $@);
36
+ QUIET_2DEVNULL = 2>/dev/null
37
endif
38
39
TCL_PATH ?= tclsh
@@ -45,6 +47,7 @@ endif
47
DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
48
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
49
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
50
+TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH))
51
TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
52
53
libdir ?= $(sharedir)/git-gui/lib
@@ -64,16 +67,26 @@ $(GITGUI_BUILT_INS): git-gui
67
$(QUIET_BUILT_IN)rm -f $@ && ln git-gui $@
68
69
lib/tclIndex: $(ALL_LIBFILES)
67
- $(QUIET_INDEX)echo \
68
- source lib/class.tcl \; \
70
+ $(QUIET_INDEX)if echo \
71
+ $(foreach p,$(PRELOAD_FILES),source $p\;) \
72
auto_mkindex lib '*.tcl' \
70
- | $(TCL_PATH)
73
+ | $(TCL_PATH) $(QUIET_2DEVNULL); then : ok; \
74
+ else \
75
+ echo 1>&2 " * $(TCL_PATH) failed; using unoptimized loading"; \
76
+ rm -f $@ ; \
77
+ echo '# Autogenerated by git-gui Makefile' >$@ && \
78
+ echo >>$@ && \
79
+ $(foreach p,$(PRELOAD_FILES) $(ALL_LIBFILES),echo '$(subst lib/,,$p)' >>$@ &&) \
80
+ echo >>$@ ; \
81
+ fi
82
83
# These can record GITGUI_VERSION
84
$(patsubst %.sh,%,$(SCRIPT_SH)): GIT-VERSION-FILE GIT-GUI-VARS
85
+lib/tclIndex: GIT-GUI-VARS
86
87
TRACK_VARS = \
88
$(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
89
+ $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
90
$(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
91
$(subst ','\'',libdir='$(libdir_SQ)') \
92
#end TRACK_VARS
git-gui.sh
+28
-1
@@ -28,7 +28,34 @@ set oguilib {@@GITGUI_LIBDIR@@}
28
if {[string match @@* $oguilib]} {
29
set oguilib [file join [file dirname [file normalize $argv0]] lib]
30
}
31
-set auto_path [concat [list $oguilib] $auto_path]
31
+set idx [file join $oguilib tclIndex]
32
+catch {
33
+ set fd [open $idx r]
34
+ if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
35
+ set idx [list]
36
+ while {[gets $fd n] >= 0} {
37
+ if {$n ne {} && ![string match #* $n]} {
38
+ lappend idx $n
39
+ }
40
+ }
41
+ } else {
42
+ set idx {}
43
+ }
44
+ close $fd
45
+}
46
+if {$idx ne {}} {
47
+ set loaded [list]
48
+ foreach p $idx {
49
+ if {[lsearch -exact $loaded $p] >= 0} continue
50
+ puts $p
51
+ source [file join $oguilib $p]
52
+ lappend loaded $p
53
+ }
54
+ unset loaded p
55
+} else {
56
+ set auto_path [concat [list $oguilib] $auto_path]
57
+}
58
+unset -nocomplain fd idx
59
60
if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
61
unset _verbose