Skip to content

Commit ca2d64a

Browse files
committed
[build-script] Add infrastructure for passing host-specific variables.
- This isn't yet used, but we need an easy way for `build-script` to pass host-specific variables down to `build-script-impl`. - I don't think it is worth complicating the main argument parsing logic with a syntax for passing associative arrays on the command line, so this just passes them via environment variables. - Part of SR-237.
1 parent c03943c commit ca2d64a

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

utils/build-script

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ from swift_build_support.cmake import CMake # noqa (E402)
5050
import swift_build_support.workspace # noqa (E402)
5151

5252

53-
def call_without_sleeping(command, dry_run=False):
53+
def call_without_sleeping(command, env=None, dry_run=False):
5454
"""
5555
Execute a command during which system sleep is disabled.
5656
@@ -62,7 +62,7 @@ def call_without_sleeping(command, dry_run=False):
6262
# Don't mutate the caller's copy of the arguments.
6363
command = ["caffeinate"] + list(command)
6464

65-
shell.call(command, dry_run=dry_run, echo=False)
65+
shell.call(command, env=env, dry_run=dry_run)
6666

6767

6868
class BuildScriptInvocation(object):
@@ -322,10 +322,10 @@ class BuildScriptInvocation(object):
322322
self.toolchain.ninja = ninja_build.ninja_bin_path
323323

324324
def convert_to_impl_arguments(self):
325-
"""convert_to_impl_arguments() -> args
325+
"""convert_to_impl_arguments() -> (env, args)
326326
327-
Convert the invocation to a list of arguments suitable for invoking
328-
`build-script-impl`.
327+
Convert the invocation to an environment and list of arguments suitable
328+
for invoking `build-script-impl`.
329329
"""
330330

331331
# Create local shadows, for convenience.
@@ -540,7 +540,26 @@ class BuildScriptInvocation(object):
540540
if args.dry_run:
541541
impl_args += ["--dry-run"]
542542

543-
return impl_args
543+
# Compute the set of host-specific variables, which we pass through to
544+
# the build script via environment variables.
545+
host_specific_variables = self.compute_host_specific_variables()
546+
impl_env = {}
547+
for (host_target, options) in host_specific_variables.items():
548+
for (name, value) in options.items():
549+
# We mangle into an environment variable we can easily evaluate
550+
# from the `build-script-impl`.
551+
impl_env["HOST_VARIABLE_{}__{}".format(
552+
host_target.replace("-", "_"), name)] = value
553+
554+
return (impl_env, impl_args)
555+
556+
def compute_host_specific_variables(self):
557+
"""compute_host_specific_variables(args) -> dict
558+
559+
Compute the host-specific options, organized as a dictionary keyed by
560+
host of options.
561+
"""
562+
return {}
544563

545564

546565
# Main entry point for the preset mode.
@@ -1551,10 +1570,12 @@ details of the setups of other systems or automated environments.""")
15511570
invocation.build_ninja()
15521571

15531572
# Convert to a build-script-impl invocation.
1554-
build_script_impl_args = invocation.convert_to_impl_arguments()
1573+
(build_script_impl_env,build_script_impl_args) = \
1574+
invocation.convert_to_impl_arguments()
15551575

15561576
# Execute the underlying build script implementation.
1557-
call_without_sleeping([build_script_impl] + build_script_impl_args)
1577+
call_without_sleeping([build_script_impl] + build_script_impl_args,
1578+
env=build_script_impl_env)
15581579

15591580
if args.symbols_package:
15601581
print('--- Creating symbols package ---')

utils/build-script-impl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,19 @@ if [[ ! "${SKIP_BUILD_SWIFTPM}" ]] ; then
11381138
PRODUCTS=("${PRODUCTS[@]}" swiftpm)
11391139
fi
11401140

1141+
# get_host_specific_variable(host, name)
1142+
#
1143+
# Get the value of a host-specific variable expected to have been passed by the
1144+
# `build-script`.
1145+
#
1146+
# This is a total hack, and is part of the SR-237 migration.
1147+
function get_host_specific_variable() {
1148+
local host="$1"
1149+
local name="$2"
1150+
local envvar_name="HOST_VARIABLE_${host//-/_}__${name}"
1151+
echo "${!envvar_name}"
1152+
}
1153+
11411154
function calculate_targets_for_host() {
11421155
local host=$1
11431156

0 commit comments

Comments
 (0)