diff --git a/.gitignore b/.gitignore index c9eb8a1..89e60bd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ winpty.opensdf /ship/packages /src/Default /src/Release +/src/gen diff --git a/Makefile b/Makefile index e7464f2..8b3d0ae 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/VERSION.txt b/VERSION.txt index 2b7c5ae..7532512 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.4.2 +0.4.2-dev diff --git a/configure b/configure index e677c6b..6d37d65 100755 --- a/configure +++ b/configure @@ -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 diff --git a/ship/common_ship.py b/ship/common_ship.py index fa229d5..b46cd5b 100644 --- a/ship/common_ship.py +++ b/ship/common_ship.py @@ -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): diff --git a/ship/make_msvc_package.py b/ship/make_msvc_package.py index f8d3716..90eea3e 100755 --- a/ship/make_msvc_package.py +++ b/ship/make_msvc_package.py @@ -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"] ) diff --git a/ship/ship.py b/ship/ship.py index f355559..d9e08ee 100755 --- a/ship/ship.py +++ b/ship/ship.py @@ -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() diff --git a/src/agent/subdir.mk b/src/agent/subdir.mk index f8037bc..1c7d37e 100644 --- a/src/agent/subdir.mk +++ b/src/agent/subdir.mk @@ -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 $@ $^ diff --git a/src/debugserver/subdir.mk b/src/debugserver/subdir.mk index 7f30c81..beed1bd 100644 --- a/src/debugserver/subdir.mk +++ b/src/debugserver/subdir.mk @@ -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 $@ $^ diff --git a/src/libwinpty/subdir.mk b/src/libwinpty/subdir.mk index 0ba65fb..ba32bad 100644 --- a/src/libwinpty/subdir.mk +++ b/src/libwinpty/subdir.mk @@ -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 diff --git a/src/shared/UpdateGenVersion.bat b/src/shared/UpdateGenVersion.bat new file mode 100755 index 0000000..cab3520 --- /dev/null +++ b/src/shared/UpdateGenVersion.bat @@ -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 ) diff --git a/src/shared/WinptyVersion.cc b/src/shared/WinptyVersion.cc index ccc9ac0..76bb8a5 100644 --- a/src/shared/WinptyVersion.cc +++ b/src/shared/WinptyVersion.cc @@ -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); } diff --git a/src/unix-adapter/subdir.mk b/src/unix-adapter/subdir.mk index ce2cd08..200193a 100644 --- a/src/unix-adapter/subdir.mk +++ b/src/unix-adapter/subdir.mk @@ -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 $@ $^ diff --git a/src/winpty.gyp b/src/winpty.gyp index ed5287f..f4aae21 100644 --- a/src/winpty.gyp +++ b/src/winpty.gyp @@ -1,8 +1,4 @@ { - # Pass -D VERSION_SUFFIX= 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= to gyp. 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=