Skip to content

Commit 97e6e52

Browse files
committed
build: Improve Documentation build performance
The documentation build was slow, and often pathologically slow. The root of the slowness ties back to all the circumstances in which `cargo run` would be invoked. In the worst cases, `cargo run` would be run for each man page *and* those `cargo run`'s would rebuild all of StGit. One change is to capture the StGit version using `cargo metadata` instead of by running `stg` with `cargo run`. Running `cargo metadata` does not have a side effect of building `stg` and is thus always fast. Additionally, the version is now captured as a simply expanded make variable instead of recursively expanded variable which ensures that `cargo metadata` will only be run once per make invocation. A consequence of this change is that man pages now simply reflect the StGit version as identified in Cargo.toml, without the supplemental git hash when building from a non-tagged and/or dirty tree. Another change is to change the dependency chain for how/when the stg-*.txt asciidoc files are generated. Previously the STG_COMMANDS_TXT variable would invoke `cargo run completion list commands` each time it was recursively expanded. The new strategy is to piggyback on doc.dep to ensure that stg-*.txt are generated, where txt-stamp is the proxy for stg-*.txt. With this approach, the stg-*.txt files are generated only when necessary and they are found by make via $(wildcard). With these updates, the `clean` target no longer triggers `cargo run` and thus avoids the previous pathology when running `make clean` on an already clean repo would first build stg. Fixes: #229
1 parent a32891b commit 97e6e52

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Documentation/Makefile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,12 @@ CARGO ?= cargo --locked
5050
CARGO_OFFLINE = $(CARGO) --offline
5151
CARGO_RUN = $(CARGO_OFFLINE) --quiet run --profile=$(STG_PROFILE)
5252
STG_COMMANDS_SRC = $(shell find ../src/cmd -name '*.rs')
53-
STG_COMMANDS = $(shell $(CARGO_RUN) completion list commands)
54-
STG_COMMANDS_TXT = $(patsubst %,stg-%.txt,$(STG_COMMANDS))
53+
STG_COMMANDS_TXT = $(wildcard stg-*.txt)
5554

56-
# STGIT_VERSION = $(shell $(CARGO) --quiet metadata --format-version=1 --no-deps | \
57-
# jq -r '.packages[].version')
58-
# STGIT_VERSION = $(shell $(CARGO) --quiet metadata --format-version=1 --no-deps | \
59-
# grep -Eo '"version":"[^"]+"' | \
60-
# sed -Ee 's/"version":"([^"]+)"/\1/g')
61-
STGIT_VERSION = $(shell $(CARGO_RUN) version --short | sed -e 's/stg //g')
55+
STGIT_VERSION := $(shell $(CARGO) metadata --format-version=1 --no-deps | \
56+
grep -Eo '"version":"[^"]+"' | \
57+
sed -Ee 's/"version":"([^"]+)"/\1/g')
58+
# STGIT_VERSION := $(shell $(CARGO_RUN) version --short | sed -e 's/stg //g')
6259

6360
MAN1_TXT += stg.txt
6461
MAN1_TXT += $(STG_COMMANDS_TXT)
@@ -200,7 +197,7 @@ $(DOC_HTML) $(DOC_MAN1): asciidoc.conf
200197
#
201198
# Determine "include::" file references in asciidoc files.
202199
#
203-
doc.dep : $(DOC_DEP_TXT) build-docdep.perl
200+
doc.dep : txt-stamp $(DOC_DEP_TXT) build-docdep.perl
204201
$(QUIET_GEN)$(PERL_PATH) ./build-docdep.perl >$@ $(QUIET_STDERR)
205202

206203
ifneq ($(MAKECMDGOALS),clean)
@@ -223,7 +220,8 @@ clean:
223220
$(RM) doc.dep
224221
$(RM) manpage-base-url.xsl
225222
$(RM) GIT-ASCIIDOCFLAGS
226-
$(RM) $(STG_COMMANDS_TXT) command-list.txt
223+
$(RM) stg-*.txt
224+
$(RM) command-list.txt
227225
$(RM) txt-stamp
228226

229227
$(MAN_HTML): %.html : %.txt $(ASCIIDOC_DEPS)

0 commit comments

Comments
 (0)