summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2020-03-21 13:43:26 -0700
committerWilliam Deegan <bill@baddogconsulting.com>2020-04-09 13:47:32 -0700
commit23197f27e50f9f66d9f7263fbac5c38855731922 (patch)
treec225812f4de5dfec08bbe0847aa25ca6050c00ee /site_scons
parent7c466f714b9892d953ff2b91c7b0214180417000 (diff)
downloadscons-git-23197f27e50f9f66d9f7263fbac5c38855731922.tar.gz
First pass of refactor. Moved command line argument processing into site_scons/BuildCommandLine.py. Sorted out all changes caused by that.
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/BuildCommandLine.py144
-rw-r--r--site_scons/epydoc.py4
-rw-r--r--site_scons/site_init.py10
3 files changed, 155 insertions, 3 deletions
diff --git a/site_scons/BuildCommandLine.py b/site_scons/BuildCommandLine.py
new file mode 100644
index 000000000..4694472fe
--- /dev/null
+++ b/site_scons/BuildCommandLine.py
@@ -0,0 +1,144 @@
+import time
+import os
+import socket
+
+from SCons.Script import ARGUMENTS
+
+class BuildCommandLine(object):
+
+ git = None
+
+ def init_command_line_variables(self):
+ self.command_line_variables = [
+ ("BUILDDIR=", "The directory in which to build the packages. " +
+ "The default is the './build' subdirectory."),
+
+ ("BUILD_ID=", "An identifier for the specific build." +
+ "The default is the Subversion revision number."),
+
+ ("BUILD_SYSTEM=", "The system on which the packages were built. " +
+ "The default is whatever hostname is returned " +
+ "by socket.gethostname(). If SOURCE_DATE_EPOCH " +
+ "env var is set, '_reproducible' is the default."),
+
+ ("CHECKPOINT=", "The specific checkpoint release being packaged, " +
+ "which will be appended to the VERSION string. " +
+ "A value of CHECKPOINT=d will generate a string " +
+ "of 'd' plus today's date in the format YYYMMDD. " +
+ "A value of CHECKPOINT=r will generate a " +
+ "string of 'r' plus the Subversion revision " +
+ "number. Any other CHECKPOINT= string will be " +
+ "used as is. There is no default value."),
+
+ ("DATE=", "The date string representing when the packaging " +
+ "build occurred. The default is the day and time " +
+ "the SConstruct file was invoked, in the format " +
+ "YYYY/MM/DD HH:MM:SS."),
+
+ ("DEVELOPER=", "The developer who created the packages. " +
+ "The default is the first set environment " +
+ "variable from the list $USERNAME, $LOGNAME, $USER." +
+ "If the SOURCE_DATE_EPOCH env var is set, " +
+ "'_reproducible' is the default."),
+
+ ("REVISION=", "The revision number of the source being built. " +
+ "The default is the git hash returned " +
+ "'git rev-parse HEAD', with an appended string of " +
+ "'[MODIFIED]' if there are any changes in the " +
+ "working copy."),
+
+ ("VERSION=", "The SCons version being packaged. The default " +
+ "is the hard-coded value '%s' " % self.default_version +
+ "from this SConstruct file."),
+
+ ("SKIP_DOC=", "Skip building all documents. The default is False (build docs)"),
+ ]
+
+ def __init__(self, default_version="99.99.99"):
+ self.date = None
+ self.default_version = default_version
+ self.developer = None
+ self.build_dir = None
+ self.build_system = None
+ self.version = None
+ self.revision = None
+ self.git_status_lines = []
+ self.git_hash = None
+
+ self.init_command_line_variables()
+
+ def process_command_line_vars(self):
+ #
+ # Now grab the information that we "build" into the files.
+ #
+ self.date = ARGUMENTS.get('DATE')
+ if not self.date:
+ self.date = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))))
+
+ self.developer = ARGUMENTS.get('DEVELOPER')
+ if not self.developer:
+ for variable in ['USERNAME', 'LOGNAME', 'USER']:
+ self.developer = os.environ.get(variable)
+ if self.developer:
+ break
+ if os.environ.get('SOURCE_DATE_EPOCH'):
+ self.developer = '_reproducible'
+
+ self.build_system = ARGUMENTS.get('BUILD_SYSTEM')
+ if not self.build_system:
+ if os.environ.get('SOURCE_DATE_EPOCH'):
+ self.build_system = '_reproducible'
+ else:
+ self.build_system = socket.gethostname().split('.')[0]
+
+ self.version = ARGUMENTS.get('VERSION', '')
+ if not self.version:
+ self.version = self.default_version
+
+ if BuildCommandLine.git:
+ cmd = "%s ls-files 2> /dev/null" % BuildCommandLine.git
+ with os.popen(cmd, "r") as p:
+ self.git_status_lines = p.readlines()
+
+ self.revision = ARGUMENTS.get('REVISION', '')
+
+ def generate_build_id(revision):
+ return revision
+
+ if not self.revision and BuildCommandLine.git:
+ with os.popen("%s rev-parse HEAD 2> /dev/null" % BuildCommandLine.git, "r") as p:
+ self.git_hash = p.read().strip()
+
+ def generate_build_id(revision):
+ result = self.git_hash
+ if [l for l in self.git_status_lines if 'modified' in l]:
+ result = result + '[MODIFIED]'
+ return result
+
+ self.revision = self.git_hash
+
+ self.checkpoint = ARGUMENTS.get('CHECKPOINT', '')
+ if self.checkpoint:
+ if self.checkpoint == 'd':
+ cself.heckpoint = time.strftime('%Y%m%d', time.localtime(time.time()))
+ elif self.checkpoint == 'r':
+ self.checkpoint = 'r' + self.revision
+ self.version = self.version + '.beta.' + self.checkpoint
+
+ self.build_id = ARGUMENTS.get('BUILD_ID')
+ if self.build_id is None:
+ if self.revision:
+ self.build_id = generate_build_id(self.revision)
+ else:
+ self.build_id = ''
+
+ # Re-exporting LD_LIBRARY_PATH is necessary if the Python version was
+ # built with the --enable-shared option.
+ self.ENV = {'PATH': os.environ['PATH']}
+ for key in ['LOGNAME', 'PYTHONPATH', 'LD_LIBRARY_PATH']:
+ if key in os.environ:
+ self.ENV[key] = os.environ[key]
+
+ self.build_dir = ARGUMENTS.get('BUILDDIR', 'build')
+ if not os.path.isabs(self.build_dir):
+ self.build_dir = os.path.normpath(os.path.join(os.getcwd(), self.build_dir))
diff --git a/site_scons/epydoc.py b/site_scons/epydoc.py
index 149e9dced..da74d9cdd 100644
--- a/site_scons/epydoc.py
+++ b/site_scons/epydoc.py
@@ -28,7 +28,6 @@ from SCons.Script import Delete, Touch, WhereIs
epydoc_cli = WhereIs('epydoc')
-
if not epydoc_cli:
try:
import epydoc
@@ -92,7 +91,8 @@ if not epydoc_cli:
Touch('$TARGET'),
]
-else: # epydoc_cli is found
+else:
+ # epydoc_cli is found
epydoc_commands = [
Delete('$OUTDIR'),
'$EPYDOC $EPYDOCFLAGS --debug --output $OUTDIR --docformat=restructuredText --name SCons --url http://www.scons.org/ $SOURCES',
diff --git a/site_scons/site_init.py b/site_scons/site_init.py
index d4df47363..7e7c569ba 100644
--- a/site_scons/site_init.py
+++ b/site_scons/site_init.py
@@ -2,4 +2,12 @@ from SConsRevision import SCons_revision
from Utilities import is_windows, whereis, platform, deb_date
from zip_utils import unzipit, zipit, zcat
from soe_utils import soelim, soscan, soelimbuilder
-from epydoc import epydoc_cli, epydoc_commands \ No newline at end of file
+from epydoc import epydoc_cli, epydoc_commands
+from BuildCommandLine import BuildCommandLine
+
+gzip = whereis('gzip')
+git = os.path.exists('.git') and whereis('git')
+unzip = whereis('unzip')
+zip_path = whereis('zip')
+
+BuildCommandLine.git = git \ No newline at end of file