Skip to content

Commit e3858d3

Browse files
committed
[build-script] Use the build-script-impl from the swift repo that invoked build-script.
In the past if one wanted to be able to develop using multiple swift repos, one was often stymied by build-script always using build-script-impl from the swift directory. This includes the case where one invokes the build-script from a hypothetical directory called swift-2.
1 parent 268cbba commit e3858d3

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

utils/SwiftBuildSupport.py

+20
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ def _get_default_source_root():
6868
"SWIFT_BUILD_ROOT", os.path.join(SWIFT_SOURCE_ROOT, "build"))
6969

7070

71+
def _get_default_swift_repo_name():
72+
result = ""
73+
74+
# Are we in a Swift checkout? Start from this file and check its parent
75+
# directories.
76+
#
77+
# $SWIFT_SOURCE_ROOT/$SWIFT_REPO_NAME/utils/SwiftBuildSupport.py
78+
(swift_path, parent_dirname) = os.path.split(os.path.dirname(__file__))
79+
if parent_dirname != "utils":
80+
return result
81+
if not os.path.exists(os.path.join(swift_path, 'CMakeLists.txt')):
82+
return result
83+
return swift_path
84+
85+
# Set SWIFT_REPO_NAME in your environment to control the name of the swift
86+
# directory name that is used.
87+
SWIFT_REPO_NAME = os.environ.get(
88+
"SWIFT_REPO_NAME", _get_default_swift_repo_name())
89+
90+
7191
def _load_preset_files_impl(preset_file_names, substitutions={}):
7292
config = ConfigParser.SafeConfigParser(substitutions, allow_no_value=True)
7393
if config.read(preset_file_names) == []:

utils/build-script

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sys.path.append(os.path.dirname(__file__))
3030
from SwiftBuildSupport import (
3131
HOME,
3232
SWIFT_BUILD_ROOT,
33+
SWIFT_REPO_NAME,
3334
SWIFT_SOURCE_ROOT,
3435
get_all_preset_names,
3536
get_preset_options,
@@ -54,7 +55,7 @@ import swift_build_support.workspace # noqa (E402)
5455

5556

5657
build_script_impl = os.path.join(
57-
SWIFT_SOURCE_ROOT, "swift", "utils", "build-script-impl")
58+
SWIFT_SOURCE_ROOT, SWIFT_REPO_NAME, "utils", "build-script-impl")
5859

5960

6061
def exit_rejecting_arguments(message, parser=None):
@@ -1096,7 +1097,8 @@ def main_preset():
10961097
args.preset_file_names = [
10971098
os.path.join(HOME, ".swift-build-presets"),
10981099
os.path.join(
1099-
SWIFT_SOURCE_ROOT, "swift", "utils", "build-presets.ini")
1100+
SWIFT_SOURCE_ROOT, SWIFT_REPO_NAME, "utils",
1101+
"build-presets.ini")
11001102
]
11011103

11021104
if args.show_presets:

utils/python_lint.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)