winpty/ship/common_ship.py
Ryan Prichard 67a34b6c03 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
2017-01-17 23:39:14 -06:00

54 lines
1.7 KiB
Python

import os
import sys
if os.name != "nt":
sys.exit("Error: ship scripts require native Python 2.7. (wrong os.name)")
if sys.version_info[0:2] != (2,7):
sys.exit("Error: ship scripts require native Python 2.7. (wrong version)")
import glob
import shutil
import subprocess
from distutils.spawn import find_executable
topDir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
with open(topDir + "/VERSION.txt", "rt") as f:
winptyVersion = f.read().strip()
def rmrf(patterns):
for pattern in patterns:
for path in glob.glob(pattern):
if os.path.isdir(path) and not os.path.islink(path):
print "+ rm -r " + path
sys.stdout.flush()
shutil.rmtree(path)
elif os.path.isfile(path):
print "+ rm " + path
sys.stdout.flush()
os.remove(path)
def mkdir(path):
if not os.path.isdir(path):
os.makedirs(path)
def requireExe(name, guesses):
if find_executable(name) is None:
for guess in guesses:
if os.path.exists(guess):
newDir = os.path.dirname(guess)
print "Adding " + newDir + " to Path to provide " + name
os.environ["Path"] = newDir + ";" + os.environ["Path"]
ret = find_executable(name)
if ret is None:
sys.exit("Error: required EXE is missing from Path: " + name)
return ret
requireExe("git.exe", [
"C:\\Program Files\\Git\\cmd\\git.exe",
"C:\\Program Files (x86)\\Git\\cmd\\git.exe"
])
commitHash = subprocess.check_output(["git.exe", "rev-parse", "HEAD"]).decode().strip()
defaultPathEnviron = "C:\\Windows\\System32;C:\\Windows"