Skip to content

Finalized the new-bootstrap script #2447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ find_package(dispatch QUIET)
find_package(Foundation QUIET)

add_subdirectory(Sources)

if(SWIFTPM_BUILD_DIR)
add_subdirectory(Utilities/BuildExtras/Install)
endif()
14 changes: 12 additions & 2 deletions Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public struct ProcessResult: CustomStringConvertible {
/// The arguments with which the process was launched.
public let arguments: [String]

/// The environment with which the process was launched.
public let environment: [String: String]

/// The exit status of the process.
public let exitStatus: ExitStatus

Expand All @@ -55,6 +58,7 @@ public struct ProcessResult: CustomStringConvertible {
/// See `waitpid(2)` for information on the exit status code.
public init(
arguments: [String],
environment: [String: String],
exitStatusCode: Int32,
output: Result<[UInt8], AnyError>,
stderrOutput: Result<[UInt8], AnyError>
Expand All @@ -70,18 +74,20 @@ public struct ProcessResult: CustomStringConvertible {
exitStatus = .terminated(code: WEXITSTATUS(exitStatusCode))
}
#endif
self.init(arguments: arguments, exitStatus: exitStatus, output: output,
self.init(arguments: arguments, environment: environment, exitStatus: exitStatus, output: output,
stderrOutput: stderrOutput)
}

/// Create an instance using an exit status and output result.
public init(
arguments: [String],
environment: [String: String],
exitStatus: ExitStatus,
output: Result<[UInt8], AnyError>,
stderrOutput: Result<[UInt8], AnyError>
) {
self.arguments = arguments
self.environment = environment
self.output = output
self.stderrOutput = stderrOutput
self.exitStatus = exitStatus
Expand Down Expand Up @@ -474,6 +480,7 @@ public final class Process: ObjectIdentifierProtocol {
// Construct the result.
let executionResult = ProcessResult(
arguments: arguments,
environment: environment,
exitStatusCode: exitStatusCode,
output: stdout.result,
stderrOutput: stderr.result
Expand Down Expand Up @@ -657,7 +664,10 @@ extension ProcessResult.Error: CustomStringConvertible {
case .signalled(let signal):
stream <<< "signalled(\(signal)): "
}


stream <<< result.environment.map({ "\($0)=\($1)" }).joined(separator: " ")
stream <<< " "

// Strip sandbox information from arguments to keep things pretty.
var args = result.arguments
// This seems a little fragile.
Expand Down
6 changes: 6 additions & 0 deletions Sources/Workspace/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,18 @@ public final class UserToolchain: Toolchain {
if let pdLibDirEnvStr = ProcessEnv.vars["SWIFTPM_PD_LIBS"] {
// We pick the first path which exists in a colon seperated list.
let paths = pdLibDirEnvStr.split(separator: ":").map(String.init)
var foundPDLibDir = false
for pathString in paths {
if let path = try? AbsolutePath(validating: pathString), localFileSystem.exists(path) {
pdLibDir = path
foundPDLibDir = true
break
}
}

if !foundPDLibDir {
fatalError("Couldn't find any SWIFTPM_PD_LIBS directory: \(pdLibDirEnvStr)")
}
}

manifestResources = UserManifestResources(
Expand Down
2 changes: 1 addition & 1 deletion Tests/WorkspaceTests/WorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ final class WorkspaceTests: XCTestCase {
"""
}

XCTAssertMatch((ws.interpreterFlags(for: foo)), [.contains("swift/pm/4")])
XCTAssertMatch((ws.interpreterFlags(for: foo)), [.contains("pm/4")])
XCTAssertMatch((ws.interpreterFlags(for: foo)), [.equal("-swift-version"), .equal("4")])
}

Expand Down
7 changes: 6 additions & 1 deletion Utilities/BuildExtras/Install/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
cmake_minimum_required(VERSION 3.15.1)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

project(SwiftPM-Installer LANGUAGES Swift)

foreach(BINARY swift-build swift-test swift-package swift-run)
install(FILES
${SWIFTPM_BUILD_DIR}/${BINARY}
Expand All @@ -16,7 +22,6 @@ list(APPEND LIBSPM_MODULES TSCUtility)

list(APPEND LIBSPM_MODULES Build)
list(APPEND LIBSPM_MODULES Commands)
list(APPEND LIBSPM_MODULES PackageDescription4)
list(APPEND LIBSPM_MODULES PackageGraph)
list(APPEND LIBSPM_MODULES PackageLoading)
list(APPEND LIBSPM_MODULES PackageModel)
Expand Down
64 changes: 37 additions & 27 deletions Utilities/Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

FROM ubuntu:16.04
FROM ubuntu:18.04

# Install related packages.
RUN apt-get -q update && \
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
apt-get -q update && \
apt-get -q install -y \
build-essential \
make \
libc6-dev \
clang-3.6 \
curl \
libedit-dev \
python2.7 \
python2.7-dev \
libicu-dev \
rsync \
libxml2 \
git \
libcurl4-openssl-dev \
vim \
libblocksruntime-dev \
cmake \
ninja-build \
sqlite3 \
libsqlite3-dev \
libncurses5-dev \
&& update-alternatives --quiet --install /usr/bin/clang clang /usr/bin/clang-3.6 100 \
&& update-alternatives --quiet --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 \
&& rm -r /var/lib/apt/lists/*
ARG SNAPSHOT
make \
libc6-dev \
clang-3.9 \
curl \
libedit-dev \
libpython2.7 \
libicu-dev \
libssl-dev \
libxml2 \
tzdata \
git \
libcurl4-openssl-dev \
ninja-build \
sqlite3 \
libsqlite3-dev \
libncurses5-dev \
pkg-config \
apt-transport-https \
ca-certificates \
gnupg \
wget \
software-properties-common && \
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add - && \
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' && \
apt-get -q update && \
apt-get -q install -y cmake && \
update-alternatives --quiet --install /usr/bin/clang clang /usr/bin/clang-3.9 100 && \
update-alternatives --quiet --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.9 100 && \
rm -r /var/lib/apt/lists/*

ARG SNAPSHOT
COPY $SNAPSHOT /
RUN tar -xvzf $SNAPSHOT --directory / --strip-components=1 && \
rm -rf swift-DEVELOPMENT-SNAPSHOT*

# Set Swift Path
ENV PATH /usr/bin:$PATH

# Print Installed Swift Version
RUN swift --version
22 changes: 11 additions & 11 deletions Utilities/Docker/docker-utils
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ script_dir = os.path.dirname(os.path.realpath(__file__))

def call(args):
"""Prints and executes a command."""
print " ".join(args)
print(" ".join(args))
return subprocess.call(args)

def docker_run(command_args):
Expand All @@ -40,24 +40,24 @@ def docker_run(command_args):
"-v", "%s:/llbuild" % llbuild_dir,
"-w", "/swiftpm",
"--rm",
"swiftpm-docker-1604"
"swiftpm-docker-1804"
] + command_args)

def build(_):
"""Builds a docker image with the latest snapshot."""

# Get latest snapshot info.
latest_build_url = "https://swift.org/builds/development/ubuntu1604/latest-build.yml"
latest_build_url = "https://swift.org/builds/development/ubuntu1804/latest-build.yml"
latest_build_data = yaml.load(urllib2.urlopen(latest_build_url).read())
snapshot_filename = latest_build_data["download"]
# FIXME: We shouldn"t need to do this, it should be available in the API.
snapshot_name = snapshot_filename.replace("-ubuntu16.04.tar.gz", "")
snapshot_name = snapshot_filename.replace("-ubuntu18.04.tar.gz", "")
base_url = latest_build_url.rsplit("/", 1)[0]
latest_snapshot_url = base_url + "/" + snapshot_name + "/" + snapshot_filename

# Download latest snapshot (if necessary).
if snapshot_filename in os.listdir(script_dir):
print "Not downloading: " + latest_snapshot_url
print("Not downloading: %s" % latest_snapshot_url)
else:
# FIXME: We should remove old tarballs if we have newer ones.
result = call([
Expand All @@ -68,14 +68,14 @@ def build(_):
])

if result != 0:
print "Unable to install package: " + latest_snapshot_url
print("Unable to install package: %s" % latest_snapshot_url)
exit(1)

# Create docker image.
call([
"docker",
"build",
"-t", "swiftpm-docker-1604",
"-t", "swiftpm-docker-1804",
"--build-arg", "SNAPSHOT=%s" % snapshot_filename,
script_dir
])
Expand All @@ -90,13 +90,13 @@ def bootstrap(args):

def build_run(args):
"""Runs a built swift executable in the container."""
docker_run([".build/x86_64-unknown-linux-gnu/debug/" + args.command] + args.arguments)
docker_run([".build/x86_64-unknown-linux-gnu/debug/swift-" + args.command] + args.arguments)

def main():
"""Main script entry-point."""

parser = argparse.ArgumentParser(
usage="%(prog)s [build|run|bootstrap|spm]",
usage="%(prog)s [build|run|bootstrap|swift]",
description="This script simplifies all the docker operations to build "
"and run a container for SwiftPM development and testing "
"on Linux.")
Expand Down Expand Up @@ -125,8 +125,8 @@ def main():

# spm
parser_swift_build = subparsers.add_parser(
"spm",
help="runs the spm helper script in a container.")
"swift",
help="runs a SwiftPM executable in a container.")
parser_swift_build.add_argument("arguments", nargs="*")
parser_swift_build.set_defaults(func=build_run)

Expand Down
Loading