From e828fc36efb34f262bab5a9b07d1cf60e46fa89e Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Thu, 3 Mar 2016 17:18:27 +0100 Subject: [PATCH] Allow out-of-vcs builds --- HACKING.BUILD.md | 4 +++- Makefile.in | 2 +- commit.h.gen | 12 ++++++++++++ gen-origtar | 13 +++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/HACKING.BUILD.md b/HACKING.BUILD.md index 8847484..f09f127 100644 --- a/HACKING.BUILD.md +++ b/HACKING.BUILD.md @@ -11,6 +11,7 @@ This list was previously maintained as [issue #242](https://github.com/majn/tele 1. Any changes due to `make -C tgl` must cause all necessary rebuilds in telegram-purple during the same invocation of make. ("Too often" is acceptable as long as `make && make` isn't violated.) 1. If `tgl/Makefile.in` is missing, explain that we need submodules, and stop. 1. `make -j12` must work fine +1. Must support out-of-CVS builds. ## While ensuring that: @@ -20,12 +21,13 @@ This list was previously maintained as [issue #242](https://github.com/majn/tele ## Approach: -- `commit.h` is a regular file which depends on a .PHONY target `commit`. Building `commit.h` *only* touches `commit.h` if necessary. (=> 1 & 2) +- `commit.h` is a regular file which depends on a .PHONY target `commit`. Building `commit.h` *only* touches `commit.h` if necessary and possible. (=> 1, 2, half of 8) - Have a target `tgl/Makefile` which depends on `Makefile`. (=> 3) - The central target `${PRPL_LIBNAME}` shall depend on the .PHONY `submade`, which depends on `tgl/Makefile`, and essentially executes `make -C tgl`. (=> 4, time constraint of 5) - All objects of telegram-purple depend on `tgl/libs/libtgl.a`. Rationale: if `tgl/libs/libtgl.a` stays the same, then nothing in tgl changed. If `tgl/libs/libtgl.a` changes, then due to lots of black preprocessor magic within tgl, it can't be safely determined which, if any, objects of telegram-purple can be re-used. Also, if tgl got recompiled (~ 1 minute), then tgp can be recompiled, too (~ 5 seconds). (=> dependency constraint of 5) - Let `tgl/Makefile` depend on `tgl/Makefile.in`, and put the warning into the rule for the latter. (=> 6) - The above already implies a dependency DAG that is completely known to make; except at one point: let `tgl/libs/libtgl.a` depend on `submade`, without any own code. Now make ensure thread-safety on it's own. (=> 7) +- Bundle commit.h into the origtar (=> other half of 8) ## Side effects: diff --git a/Makefile.in b/Makefile.in index d5eac51..3b157e4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -215,7 +215,7 @@ check-clean: .git # Feel free to remove the "check-clean" dependency if you know what you're doing. .PHONY: dist -dist: check-clean .git create_dirs +dist: check-clean commit.h .git create_dirs ./gen-origtar diff --git a/commit.h.gen b/commit.h.gen index 8cb0295..5ef4548 100755 --- a/commit.h.gen +++ b/commit.h.gen @@ -20,6 +20,18 @@ set -e +if ! (command -v git && git status) >/dev/null 2>&1 +then + if test -r commit.h + then + echo "No git available. Assuming everything is up-to-date." + exit 0 + else + echo >&2 "No git available. Can't reconstruct commit.h" + exit 1 + fi +fi + GIT_COMMIT=`git rev-parse HEAD | cut -c1-10` if grep -scq "${GIT_COMMIT}" commit.h diff --git a/gen-origtar b/gen-origtar index b01d024..99217e6 100755 --- a/gen-origtar +++ b/gen-origtar @@ -21,17 +21,26 @@ set -e # -- Cleanup possibly left-over artifacts -rm -f bin/tgl_tl-parser.tar bin/tgl.tar bin/result.tar bin/result.tar.gz +rm -f bin/tgl_tl-parser.tar bin/tgl.tar bin/commit.h.tar bin/result.tar bin/result.tar.gz # -- Create parts # Abuse the "bin" dir for temporary files. ( cd tgl/tl-parser && git archive --prefix=telegram-purple/tgl/tl-parser/ --output=../../bin/tgl_tl-parser.tar HEAD ) ( cd tgl && git archive --prefix=telegram-purple/tgl/ --output=../bin/tgl.tar HEAD ) git archive --prefix=telegram-purple/ --output=bin/result.tar HEAD +# This is a lot of options. Here's why. +# --sort --mtime --owner --group => be reproducible (same commit produces binarily identical files) +# --transform => be in the same "tar-folder" as the rest +# (absence of --numeric-ids) => have identical behavior as git-archive +# --mode=664 => have identical behavior as git-archive +# http://www.gelato.unsw.edu.au/archives/git/0701/36326.html +# This is hacky. TODO: Find a better way to unify permissions. +tar --sort=name --mtime="1970-01-01 00:00Z" --owner=root --group=root --transform s%^%telegram-purple/% --mode=664 -cf bin/commit.h.tar commit.h # -- Concatenate it all tar --concatenate -f bin/result.tar bin/tgl.tar tar --concatenate -f bin/result.tar bin/tgl_tl-parser.tar +tar --concatenate -f bin/result.tar bin/commit.h.tar gzip -n bin/result.tar # -- Determine name and move @@ -41,4 +50,4 @@ echo mv -f bin/result.tar.gz $TARNAME mv -f bin/result.tar.gz $TARNAME # -- Cleanup (never fail) -rm -f bin/tgl_tl-parser.tar bin/tgl.tar bin/result.tar bin/result.tar.gz || true +rm -f bin/tgl_tl-parser.tar bin/tgl.tar bin/commit.h.tar bin/result.tar bin/result.tar.gz || true