diff options
author | Mats Wichmann <mats@linux.com> | 2023-04-27 15:29:42 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2023-07-19 16:39:25 (GMT) |
commit | 3beb6a408671c5030c5cfd805d0318981c666434 (patch) | |
tree | 9845debeb67a281e46be47f7e74ac78e6b843fb2 /site_scons/BuildCommandLine.py | |
parent | 461c21374f5053133498294d6aa8bea5c36cfe7d (diff) | |
download | SCons-3beb6a408671c5030c5cfd805d0318981c666434.zip SCons-3beb6a408671c5030c5cfd805d0318981c666434.tar.gz SCons-3beb6a408671c5030c5cfd805d0318981c666434.tar.bz2 |
Cleanup the SCons build a bit
* Removes the old bootstrap.py file. The still-used manifest parser
is moved inline into doc/SConscript
* Some reformatting and license text updates, as well as fstringinfying.
* Help text is modified, adding the recent zipapp option, and indent
changes let more stuff fit on the screen.
* Aliases added for most of the build targets listed in the help msg.
The ones now listed all work when given as cli targets, except the
the two full source balls:
scons: *** Do not know how to make File target `src-tar-gz' (/home/mats/github/scons/src-tar-gz). Stop.
scons: *** Do not know how to make File target `src-zip' (/home/mats/github/scons/src-zip). Stop.
Should these two be removed from the listing? I think we get the former
directly from github, and the latter hasn't been around for a while.
Fixes #4341
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'site_scons/BuildCommandLine.py')
-rw-r--r-- | site_scons/BuildCommandLine.py | 153 |
1 files changed, 103 insertions, 50 deletions
diff --git a/site_scons/BuildCommandLine.py b/site_scons/BuildCommandLine.py index 14bc279..d401aed 100644 --- a/site_scons/BuildCommandLine.py +++ b/site_scons/BuildCommandLine.py @@ -1,57 +1,84 @@ -import time +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + +"""Command-line processing for building SCons.""" + import os -import socket +import platform +import time +import SCons.Errors from SCons.Script import ARGUMENTS + class BuildCommandLine: 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)"), + ( + "BUILDDIR=", + "The directory to build the packages in. " + "The default is './build'." + ), + ( + "BUILD_ID=", + "An identifier for the specific build. " + "The default is to generate an id from 'git rev-parse'." + ), + ( + "BUILD_SYSTEM=", + "The system on which the packages were built. " + "The default is the inspected hostname. " + "If env var SOURCE_DATE_EPOCH is set, " + "defaults to '_reproducible'." + ), + ( + "CHECKPOINT=", + "Indicates a checkpoint release, " + "which will be appended to the VERSION string. " + "A value of 'd' selects a date checkpoint " + "(a string of 'd' plus today's date in the format YYYMMDD). " + "A value of 'r' selects a revision checkpoint " + "(string of 'r' plus the revision number). " + "Any other value will be used as is. There is no default." + ), + ( + "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. If env var SOURCE_DATE_EPOCH is set, " + "its value (must be a UNIX-style timestamp) is used." + ), + ( + "DEVELOPER=", + "The developer who created the packages. " + "The default is the first set environment " + "variable from the list $USERNAME, $LOGNAME, $USER." + "If env var SOURCE_DATE_EPOCH is set, " + "defaults to '_reproducible'." + ), + ( + "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 " + f"is the hard-coded value '{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"): @@ -77,8 +104,32 @@ class BuildCommandLine: min = (time.daylight and time.altzone or time.timezone) // 60 hr = min // 60 min = -(min % 60 + hr * 100) - self.date = (time.strftime('%a, %d %b %Y %X', time.localtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))) - + ' %+.4d' % min) + # TODO: is it better to take the date of last rev? Externally: + # SOURCE_DATE_EPOCH =`git log -1 --pretty=%ct` + self.date = ( + time.strftime( + '%a, %d %b %Y %X', + time.localtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))), + ) + + ' %+.4d' % min + ) + # Alternate proposal: + # from datetime import datetime, timezone + # timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', time.time())) + # try: + # dt = datetime.fromtimestamp(timestamp, timezone.utc) + # except (OverflowError, OSError): + # # SOURCE_DATE_EPOCH spec: If the value is malformed, + # # the build process SHOULD exit with a non-zero error code. + # # Python: This may raise OverflowError, if the timestamp is out + # # of the range of values supported by the platform C gmtime() + # # function, and OSError on gmtime() failure. It’s common for + # # this to be restricted to years in 1970 through 2038. + # raise SCons.Errors.UserError( + # "Invalid value for SOURCE_DATE_EPOCH environment var, " + # "please correct to a valid timestamp" + # ) + # self.date = dt.strftime("%a, %d %b %Y %X %Z") # or %z for numeric def process_command_line_vars(self): # @@ -102,14 +153,14 @@ class BuildCommandLine: if os.environ.get('SOURCE_DATE_EPOCH'): self.build_system = '_reproducible' else: - self.build_system = socket.gethostname().split('.')[0] + self.build_system = platform.node().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 + cmd = f"{BuildCommandLine.git} ls-files 2> /dev/null" with os.popen(cmd, "r") as p: self.git_status_lines = p.readlines() @@ -118,10 +169,12 @@ class BuildCommandLine: def _generate_build_id(revision): return revision - generate_build_id=_generate_build_id + generate_build_id = _generate_build_id if not self.revision and BuildCommandLine.git: - with os.popen("%s rev-parse HEAD 2> /dev/null" % BuildCommandLine.git, "r") as p: + with os.popen( + f"{BuildCommandLine.git} rev-parse HEAD 2> /dev/null", "r" + ) as p: self.git_hash = p.read().strip() def _generate_build_id_git(revision): |