Build system: redo how version number tracking works

* Remove the "version suffix" and BUILD_INFO.txt mechanisms, which I
   believe no one uses except winpty itself.  Instead, a suffix can be
   added in the VERSION.txt file.

 * Instead of passing the version and commit info as a preprocessor macro
   when building every C++ file, write the info into a GenVersion.h
   header that is only included by WinptyVersion.cc.

 * Instead of writing a BUILD_INFO.txt in ship.py, pass COMMIT_HASH=<hash>
   to make.

These changes accomplish two things:

 * People who build a tag from source won't see a "<ver>-dev" suffix
   anymore.

 * Changing the version or the commit will correctly rebuild the version
   object files (and only those object files).  It will also relink every
   binary.

Fixes https://github.com/rprichard/winpty/issues/72
This commit is contained in:
Ryan Prichard 2017-01-17 23:39:14 -06:00
parent 643e14894a
commit 67a34b6c03
15 changed files with 83 additions and 85 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ winpty.opensdf
/ship/packages
/src/Default
/src/Release
/src/gen

View File

@ -45,15 +45,12 @@ ifeq "$(wildcard config.mk)" ""
endif
include config.mk
VERSION_TXT_CONTENT := $(shell cat VERSION.txt | tr -d '\r\n')
COMMON_CXXFLAGS += \
-DWINPTY_VERSION=$(VERSION_TXT_CONTENT) \
-DWINPTY_VERSION_SUFFIX=$(VERSION_SUFFIX) \
-DWINPTY_COMMIT_HASH=$(COMMIT_HASH) \
-MMD -Wall \
-DUNICODE \
-D_UNICODE \
-D_WIN32_WINNT=0x0501
-D_WIN32_WINNT=0x0501 \
-Ibuild/gen
UNIX_CXXFLAGS += \
$(COMMON_CXXFLAGS)
@ -73,6 +70,11 @@ else
PCH_DEP :=
endif
build/gen/GenVersion.h : VERSION.txt $(COMMIT_HASH_DEP) | $$(@D)/.mkdir
$(info Updating build/gen/GenVersion.h)
@echo "const char GenVersion_Version[] = \"$(shell cat VERSION.txt | tr -d '\r\n')\";" > build/gen/GenVersion.h
@echo "const char GenVersion_Commit[] = \"$(COMMIT_HASH)\";" >> build/gen/GenVersion.h
build/mingw/PrecompiledHeader.h : src/shared/PrecompiledHeader.h | $$(@D)/.mkdir
$(info Copying $< to $@)
@cp $< $@
@ -84,13 +86,13 @@ build/mingw/PrecompiledHeader.h.gch : build/mingw/PrecompiledHeader.h | $$(@D)/.
-include build/mingw/PrecompiledHeader.h.d
define def_unix_target
build/$1/%.o : src/%.cc VERSION.txt | $$$$(@D)/.mkdir
build/$1/%.o : src/%.cc | $$$$(@D)/.mkdir
$$(info Compiling $$<)
@$$(UNIX_CXX) $$(UNIX_CXXFLAGS) $2 -I src/include -c -o $$@ $$<
endef
define def_mingw_target
build/$1/%.o : src/%.cc VERSION.txt $$(PCH_DEP) | $$$$(@D)/.mkdir
build/$1/%.o : src/%.cc $$(PCH_DEP) | $$$$(@D)/.mkdir
$$(info Compiling $$<)
@$$(MINGW_CXX) $$(MINGW_CXXFLAGS) $2 -I src/include -c -o $$@ $$<
endef
@ -147,7 +149,7 @@ clean :
.PHONY : clean-msvc
clean-msvc :
rm -fr src/Default src/Release src/.vs
rm -fr src/Default src/Release src/.vs src/gen
rm -f src/*.vcxproj src/*.vcxproj.filters src/*.sln src/*.sdf
.PHONY : distclean

View File

@ -1 +1 @@
0.4.2
0.4.2-dev

22
configure vendored
View File

@ -156,22 +156,12 @@ if test $IS_MSYS1 = 1; then
echo MINGW_ENABLE_CXX11_FLAG := -std=gnu++11 >> config.mk
fi
# Figure out how to embed build info (e.g. git commit) into the binary.
if test -f BUILD_INFO.txt; then
echo "Build info: source package"
eval $(grep '^VERSION_SUFFIX=' BUILD_INFO.txt | tr -d '\r')
eval $(grep '^COMMIT_HASH=' BUILD_INFO.txt | tr -d '\r')
echo "VERSION_SUFFIX := ${VERSION_SUFFIX}" >> config.mk
echo "COMMIT_HASH := ${COMMIT_HASH}" >> config.mk
echo "BUILD_INFO_DEP := config.mk" >> config.mk
elif test -d .git && git rev-parse HEAD >&/dev/null; then
echo "Build info: git"
echo 'VERSION_SUFFIX := -dev' >> config.mk
echo 'COMMIT_HASH := $(shell git rev-parse HEAD)' >> config.mk
echo 'BUILD_INFO_DEP := config.mk .git/HEAD' >> config.mk
if test -d .git -a -f .git/HEAD -a -f .git/index && git rev-parse HEAD >&/dev/null; then
echo "Commit info: git"
echo 'COMMIT_HASH = $(shell git rev-parse HEAD)' >> config.mk
echo 'COMMIT_HASH_DEP := config.mk .git/HEAD .git/index' >> config.mk
else
echo "Build info: none"
echo 'VERSION_SUFFIX := -dev' >> config.mk
echo "Commit info: none"
echo 'COMMIT_HASH := none' >> config.mk
echo 'BUILD_INFO_DEP := config.mk' >> config.mk
echo 'COMMIT_HASH_DEP := config.mk' >> config.mk
fi

View File

@ -16,11 +16,6 @@ topDir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
with open(topDir + "/VERSION.txt", "rt") as f:
winptyVersion = f.read().strip()
def writeBuildInfo():
with open(topDir + "/BUILD_INFO.txt", "w") as f:
f.write("VERSION_SUFFIX=__none__\n")
f.write("COMMIT_HASH=" + commitHash + "\n")
def rmrf(patterns):
for pattern in patterns:
for path in glob.glob(pattern):

View File

@ -88,7 +88,7 @@ def checkoutGyp():
def cleanMsvc():
common_ship.rmrf("""
src/Release src/.vs
src/Release src/.vs src/gen
src/*.vcxproj src/*.vcxproj.filters src/*.sln src/*.sdf
""".split())
@ -106,7 +106,6 @@ def build(arch, packageDir, xp=False):
'"' + devCmdPath + '" && '
" vcbuild.bat" +
" --gyp-msvs-version " + versionInfo["gyp_version"] +
" --version-suffix __none__" +
" --msvc-platform " + archInfo["msvc_platform"]
)

View File

@ -77,13 +77,17 @@ def buildTarget(target):
oldPath = os.environ["PATH"]
os.environ["PATH"] = target["path"] + ";" + common_ship.defaultPathEnviron
subprocess.check_call(["sh.exe", "configure"])
subprocess.check_call(["make.exe", "clean"])
makeBinary = target.get("make_binary", "make.exe")
buildArgs = [makeBinary, "USE_PCH=0", "all", "tests"]
buildArgs += ["-j%d" % multiprocessing.cpu_count()]
subprocess.check_call(buildArgs)
subprocess.check_call([makeBinary, "clean"])
makeBaseCmd = [
makeBinary,
"USE_PCH=0",
"COMMIT_HASH=" + common_ship.commitHash,
"PREFIX=ship/packages/" + packageName
]
subprocess.check_call(makeBaseCmd + ["all", "tests", "-j%d" % multiprocessing.cpu_count()])
subprocess.check_call(["build\\trivial_test.exe"])
subprocess.check_call([makeBinary, "USE_PCH=0", "PREFIX=ship/packages/" + packageName, "install"])
subprocess.check_call(makeBaseCmd + ["install"])
subprocess.check_call(["tar.exe", "cvfz",
packageName + ".tar.gz",
packageName], cwd=os.path.join(os.getcwd(), "ship", "packages"))
@ -91,19 +95,15 @@ def buildTarget(target):
os.environ["PATH"] = oldPath
def main():
try:
common_ship.writeBuildInfo()
if os.path.exists("ship\\packages"):
shutil.rmtree("ship\\packages")
oldPath = os.environ["PATH"]
for t in BUILD_TARGETS:
os.environ["PATH"] = t["path"] + ";" + common_ship.defaultPathEnviron
subprocess.check_output(["tar.exe", "--help"])
subprocess.check_output(["make.exe", "--help"])
for t in BUILD_TARGETS:
buildTarget(t)
finally:
os.remove("BUILD_INFO.txt")
if os.path.exists("ship\\packages"):
shutil.rmtree("ship\\packages")
oldPath = os.environ["PATH"]
for t in BUILD_TARGETS:
os.environ["PATH"] = t["path"] + ";" + common_ship.defaultPathEnviron
subprocess.check_output(["tar.exe", "--help"])
subprocess.check_output(["make.exe", "--help"])
for t in BUILD_TARGETS:
buildTarget(t)
if __name__ == "__main__":
main()

View File

@ -52,6 +52,8 @@ AGENT_OBJECTS = \
build/agent/shared/WinptyException.o \
build/agent/shared/WinptyVersion.o
build/agent/shared/WinptyVersion.o : build/gen/GenVersion.h
build/winpty-agent.exe : $(AGENT_OBJECTS)
$(info Linking $@)
@$(MINGW_CXX) $(MINGW_LDFLAGS) -o $@ $^

View File

@ -32,6 +32,8 @@ DEBUGSERVER_OBJECTS = \
build/debugserver/shared/WinptyAssert.o \
build/debugserver/shared/WinptyException.o
build/debugserver/shared/WindowsVersion.o : build/gen/GenVersion.h
build/winpty-debugserver.exe : $(DEBUGSERVER_OBJECTS)
$(info Linking $@)
@$(MINGW_CXX) $(MINGW_LDFLAGS) -o $@ $^

View File

@ -37,6 +37,8 @@ LIBWINPTY_OBJECTS = \
build/libwinpty/shared/WinptyException.o \
build/libwinpty/shared/WinptyVersion.o
build/libwinpty/shared/WinptyVersion.o : build/gen/GenVersion.h
build/winpty.dll : $(LIBWINPTY_OBJECTS)
$(info Linking $@)
@$(MINGW_CXX) $(MINGW_LDFLAGS) -shared -o $@ $^ -Wl,--out-implib,build/winpty.lib

24
src/shared/UpdateGenVersion.bat Executable file
View File

@ -0,0 +1,24 @@
@echo off
rem -- Echo the git commit hash. If git isn't available for some reason,
rem -- output nothing instead.
mkdir ..\gen 2>nul
set /p VERSION=<..\..\VERSION.txt
git rev-parse HEAD >nul 2>nul && (
for /F "delims=" %%i IN ('git rev-parse HEAD') DO set COMMIT=%%i
) || (
set COMMIT=none
)
echo // AUTO-GENERATED BY %0>..\gen\GenVersion.h
echo const char GenVersion_Version[] = "%VERSION%";>>..\gen\GenVersion.h
echo const char GenVersion_Commit[] = "%COMMIT%";>>..\gen\GenVersion.h
rem -- The winpty.gyp file expects the script to output the include directory,
rem -- relative to src.
echo gen
rem -- Set ERRORLEVEL to 0 using this cryptic syntax.
(call )

View File

@ -25,25 +25,18 @@
#include "DebugClient.h"
#define XSTRINGIFY(x) #x
#define STRINGIFY(x) XSTRINGIFY(x)
static const char *versionSuffix() {
const char *ret = STRINGIFY(WINPTY_VERSION_SUFFIX);
if (!strcmp(ret, "__none__")) {
return "";
}
return ret;
}
// This header is auto-generated by either the Makefile (Unix) or
// UpdateGenVersion.bat (gyp). It is placed in a 'gen' directory, which is
// added to the search path.
#include "GenVersion.h"
void dumpVersionToStdout() {
printf("winpty version %s%s\n", STRINGIFY(WINPTY_VERSION), versionSuffix());
printf("commit %s\n", STRINGIFY(WINPTY_COMMIT_HASH));
printf("winpty version %s\n", GenVersion_Version);
printf("commit %s\n", GenVersion_Commit);
}
void dumpVersionToTrace() {
trace("winpty version %s%s (commit %s)",
STRINGIFY(WINPTY_VERSION),
versionSuffix(),
STRINGIFY(WINPTY_COMMIT_HASH));
trace("winpty version %s (commit %s)",
GenVersion_Version,
GenVersion_Commit);
}

View File

@ -32,6 +32,8 @@ UNIX_ADAPTER_OBJECTS = \
build/unix-adapter/shared/WinptyAssert.o \
build/unix-adapter/shared/WinptyVersion.o
build/unix-adapter/shared/WinptyVersion.o : build/gen/GenVersion.h
build/$(UNIX_ADAPTER_EXE) : $(UNIX_ADAPTER_OBJECTS) build/winpty.dll
$(info Linking $@)
@$(UNIX_CXX) $(UNIX_LDFLAGS) -o $@ $^

View File

@ -1,8 +1,4 @@
{
# Pass -D VERSION_SUFFIX=<something> to gyp to override the suffix.
#
# The winpty.gyp file ignores the BUILD_INFO.txt file, if it exists.
#
# The MSVC generator is the default. Select the compiler version by
# passing -G msvs_version=<ver> to gyp. <ver> is a string like 2013e.
# See gyp\pylib\gyp\MSVSVersion.py for sample version strings. You
@ -13,18 +9,17 @@
# can be configured by passing variables to make, e.g.:
# make -j4 CXX=i686-w64-mingw32-g++ LDFLAGS="-static -static-libgcc -static-libstdc++"
'variables' : {
'VERSION_SUFFIX%' : '-dev',
},
'target_defaults' : {
'defines' : [
'UNICODE',
'_UNICODE',
'_WIN32_WINNT=0x0501',
'NOMINMAX',
'WINPTY_VERSION=<!(cmd /c "cd .. && type VERSION.txt")',
'WINPTY_VERSION_SUFFIX=<(VERSION_SUFFIX)',
'WINPTY_COMMIT_HASH=<!(cmd /c "cd shared && GetCommitHash.cmd")',
],
'include_dirs': [
# Add the 'src/gen' directory to the include path and force gyp to
# run the script (re)generating the version header.
'<!(cmd /c "cd shared && UpdateGenVersion.bat")',
],
},
'targets' : [

View File

@ -43,15 +43,6 @@ if "%1" == "--toolset" (
shift && shift
goto :ParamLoop
)
if "%1" == "--version-suffix" (
if x%2 == x"" (
set GYP_ARGS=%GYP_ARGS% -D VERSION_SUFFIX=__none__
) else (
set GYP_ARGS=%GYP_ARGS% -D VERSION_SUFFIX=%2
)
shift && shift
goto :ParamLoop
)
echo error: Unrecognized argument: %1
exit /b 1
:ParamDone