Skip to content

Commit 2ce8a18

Browse files
committed
Remove SWIFT_BUILD_TOOL and SPM_INSTALL_PATH
These were untested and causing trouble in some configurations. We now *only* support installations in a Toolchain form. The bootstrap script was adapted to make a fake toolchain with symlinks.
1 parent 61a750a commit 2ce8a18

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

Sources/POSIX/system.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ func posix_spawnp(path: String, args: [String], environment: [String: String] =
4949
defer { for arg in argv { free(arg) } }
5050

5151
var environment = environment
52-
for key in ["PATH", "SDKROOT", "TOOLCHAINS", "HOME", "SWIFT_EXEC",
53-
// FIXME these
54-
"SPM_INSTALL_PATH", "SWIFT_BUILD_TOOL"] {
52+
for key in ["PATH", "SDKROOT", "TOOLCHAINS", "HOME", "SWIFT_EXEC"] {
5553
if environment[key] == nil {
5654
environment[key] = POSIX.getenv(key)
5755
}

Utilities/bootstrap

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ def error(message):
5454
sys.stdout.flush()
5555
raise SystemExit(1)
5656

57+
def symlink_force(target, link_name):
58+
if os.path.isdir(link_name):
59+
link_name = os.path.join(link_name, os.path.basename(target))
60+
try:
61+
os.symlink(target, link_name)
62+
except OSError, e:
63+
if e.errno == errno.EEXIST:
64+
os.remove(link_name)
65+
os.symlink(target, link_name)
66+
else:
67+
raise e
5768

5869
def mkdir_p(path):
5970
"""
@@ -449,15 +460,11 @@ def get_swift_build_tool_path():
449460
if os.path.exists(sbt_path):
450461
return sbt_path
451462

452-
if os.environ.get("SWIFT_BUILD_TOOL"):
453-
return os.environ.get("SWIFT_BUILD_TOOL")
454-
455-
# Next, search for it in PATH.
456-
try:
457-
return subprocess.check_output(["which", "swift-build-tool"],
458-
universal_newlines=True).strip()
459-
except:
460-
pass
463+
SWIFT_EXEC = os.getenv("SWIFT_EXEC")
464+
if SWIFT_EXEC:
465+
maybe_path = os.path.join(SWIFT_EXEC, "../swift-build-tool")
466+
if exists(maybe_path):
467+
return maybe_path
461468

462469
# If that failed, on Darwin use xcrun to search for the tool.
463470
if platform.system() == 'Darwin':
@@ -469,11 +476,28 @@ def get_swift_build_tool_path():
469476
return sbt_path
470477
except subprocess.CalledProcessError:
471478
pass
479+
else:
480+
# Otherwise, search for it in PATH.
481+
try:
482+
return subprocess.check_output(["which", "swift-build-tool"],
483+
universal_newlines=True).strip()
484+
except:
485+
pass
472486

473487
# If all else failed, report an error.
474488
error("unable to find 'swift-build-tool' tool for bootstrap build")
475489

476490

491+
def get_swiftc_path():
492+
path = os.getenv("SWIFT_EXEC")
493+
if path:
494+
return os.realpath(path)
495+
else:
496+
if platform.system() == 'Darwin':
497+
return subprocess.check_output(["xcrun", "--find", "swiftc"], stderr=subprocess.PIPE, universal_newlines=True).strip()
498+
else:
499+
return subprocess.check_output(["which", args.swiftc_path], universal_newlines=True).strip()
500+
477501
def main():
478502
parser = argparse.ArgumentParser(
479503
usage="%(prog)s [options] [clean|all|test|install]",
@@ -487,7 +511,7 @@ def main():
487511
nargs="*", default=["all"])
488512
parser.add_argument("--swiftc", dest="swiftc_path",
489513
help="path to the swift compiler [%(default)s]",
490-
default=os.getenv("SWIFT_EXEC") or "swiftc",
514+
default=get_swiftc_path(),
491515
metavar="PATH")
492516
parser.add_argument("--sbt", dest="sbt_path",
493517
help="path to the 'swift-build-tool' tool "
@@ -511,7 +535,7 @@ def main():
511535
help="Path to XCTest build directory")
512536
args = parser.parse_args()
513537
build_actions = set(args.build_actions)
514-
538+
515539
# Validate the build actions.
516540
for action in build_actions:
517541
if action not in ("clean", "all", "test", "install"):
@@ -545,12 +569,6 @@ def main():
545569
args.sbt_path = os.path.abspath(
546570
args.sbt_path or get_swift_build_tool_path())
547571

548-
# Due to bug in Xcode where SWIFT_EXEC is not set correctly by downloadable
549-
# toolchain
550-
if os.getenv("XCODE_DEFAULT_TOOLCHAIN_OVERRIDE"):
551-
args.swiftc = os.path.join(
552-
os.getenv("XCODE_DEFAULT_TOOLCHAIN_OVERRIDE"), "usr/bin/swiftc")
553-
554572
# Create or update the bootstrap files.
555573
create_bootstrap_files(sandbox_path, args)
556574

@@ -569,25 +587,19 @@ def main():
569587
runtime_module_path, runtime_lib_path = process_runtime_libraries(
570588
sandbox_path, args, bootstrap=True)
571589

572-
# Symlink the expected lib location so that we don't yet
573-
# have to support installation logic in SwiftPM proper
574-
symlink_path = os.path.join(build_path, "lib", "swift", "pm")
575-
if not os.path.islink(symlink_path):
576-
path = os.path.join(build_path, "lib", "swift")
577-
shutil.rmtree(path, True)
578-
mkdir_p(path)
579-
os.symlink(os.path.join(build_path, "debug"), symlink_path)
580-
symlink_path = os.path.join(build_path, "bin")
581-
if not os.path.islink(symlink_path):
582-
path = os.path.join(build_path, "debug")
583-
shutil.rmtree(path, True)
584-
os.symlink(path, symlink_path)
590+
# Construct a fake toolchain so swift-build can build itself
591+
# without requiring it to have hacky-edge-case logic
592+
def make_fake_toolchain():
593+
bindir = os.path.join(sandbox_path, "bin")
594+
symlink_force(args.swiftc_path, bindir)
595+
symlink_force(args.sbt_path, bindir)
596+
597+
make_fake_toolchain()
585598

586599
# Build the package manager with itself.
587-
env_cmd = ["env",
588-
"SWIFT_EXEC=" + args.swiftc_path,
589-
"SWIFT_BUILD_TOOL=" + args.sbt_path,
590-
"SWIFT_BUILD_PATH=" + build_path]
600+
601+
env_cmd = ["env", "SWIFT_EXEC=" + os.path.join(sandbox_path, "bin", "swiftc"),
602+
"SWIFT_BUILD_PATH=" + build_path]
591603
if args.sysroot:
592604
env_cmd.append("SYSROOT=" + args.sysroot)
593605

@@ -628,12 +640,8 @@ def main():
628640
# If testing, run each of the test bundles.
629641
if "test" in build_actions:
630642
# Construct the test environment.
631-
env_cmd = ["env",
632-
"SWIFT_EXEC=" + args.swiftc_path,
633-
"SWIFT_BUILD_TOOL=" + args.sbt_path,
634-
"SWIFT_BUILD_PATH=" + build_path,
635-
"SPM_INSTALL_PATH=" + build_path]
636-
643+
env_cmd = ["env", "SWIFT_EXEC=" + args.swiftc_path,
644+
"SWIFT_BUILD_PATH=" + build_path]
637645
cmd = env_cmd + [os.path.join(build_path, "debug", "swift-test")]
638646
result = subprocess.call(cmd, cwd=g_project_root)
639647
if result != 0:

0 commit comments

Comments
 (0)