Skip to content

Commit b590948

Browse files
committed
Finalized the new-bootstrap script
1 parent 6601ff8 commit b590948

File tree

8 files changed

+498
-1820
lines changed

8 files changed

+498
-1820
lines changed

Documentation/Development.md

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ $ ../swift/utils/build-script -R --llbuild --swiftpm --xctest --foundation --lib
2424
This will build the compiler and friends in the `build/` directory. It takes about 1
2525
hour for the initial build process. However, it is not really required to build
2626
the entire compiler in order to work on the Package Manager. A faster option is
27-
using a [snapshot](https://swift.org/download/#releases) from swift.org.
27+
using a [snapshot](https://swift.org/download/#releases) from swift.org, or even faster,
28+
using Xcode 11.
2829

2930
## Using a Trunk Snapshot
3031

@@ -64,7 +65,7 @@ Note: Make sure the directory for llbuild is called "llbuild" and not
6465

6566
```sh
6667
$ cd swiftpm
67-
$ Utilities/bootstrap
68+
$ Utilities/bootstrap build
6869
```
6970

7071
Note: The bootstrap script requires having [CMake](https://cmake.org/) and [Ninja](https://ninja-build.org/) installed. Please refer to the [Swift project repo](https://github.com/apple/swift/blob/master/README.md#macos) for installation instructions.
@@ -73,9 +74,6 @@ This command builds the Package Manager inside the `.build/` directory.
7374
Run the bootstrap script to rebuild after making a change to the source
7475
code.
7576

76-
You can also use the built binaries: `swift-build`, `swift-package`,
77-
`swift-test`, `swift-run`.
78-
7977
### Example
8078

8179
```sh
@@ -87,42 +85,34 @@ $ /path/to/swiftpm/.build/x86_64-apple-macosx/debug/swift-build
8785
5. Test the Swift Package Manager.
8886

8987
```sh
90-
$ Utilities/bootstrap test --test-parallel
88+
$ Utilities/bootstrap test --parallel
9189
```
9290

9391
Use this command to run the tests. All tests must pass before a patch can be accepted.
9492

9593
## Self Hosting a Swift Package
9694

97-
It is possible to build SwiftPM with itself using a special script that is
98-
emitted during bootstrapping. This is useful when you want to rebuild just the
95+
It is possible to build SwiftPM with itself using the built SwiftPM
96+
binaries. This is useful when you want to rebuild just the
9997
sources or run a single test. Make sure you run the bootstrap script first.
10098

10199
```sh
102100
$ cd swiftpm
103101

104102
# Rebuild just the sources.
105-
$ .build/x86_64-apple-macosx/debug/spm build
103+
$ .build/x86_64-apple-macosx/debug/swift-build
106104

107105
# Run a single test.
108-
$ .build/x86_64-apple-macosx/debug/spm test --filter PackageGraphTests.DependencyResolverTests/testBasics
106+
$ .build/x86_64-apple-macosx/debug/swift-test --filter PackageGraphTests.DependencyResolverTests/testBasics
109107
```
110108

111-
Note: If you make any changes to the `PackageDescription` runtime-related targets,
112-
you **will** need to rebuild using the bootstrap script.
109+
Note: If you make any changes to the `PackageDescription4` target, you **will** need to rebuild using the bootstrap script.
113110

114111
## Developing using Xcode
115112

116-
Run the following commands to generate and open an Xcode project.
113+
Simply open SwiftPM's `Package.swift` manifest with the latest release of Xcode. Make sure you have run `Utilites/bootstrap` beforehand.
117114

118-
```sh
119-
$ Utilities/bootstrap --generate-xcodeproj
120-
generated: ./SwiftPM.xcodeproj
121-
$ open SwiftPM.xcodeproj
122-
```
123-
124-
Note: If you make any changes to the `PackageDescription` or `PackageDescription4`
125-
targets, you will need to regenerate the Xcode project using the above command.
115+
Note: If you make any changes to the `PackageDescription4` target, you will need to run `bootstrap` again.
126116

127117
## Using Continuous Integration
128118

@@ -142,17 +132,6 @@ be used to get quick feedback.
142132

143133
Note: Smoke tests are still required for merging pull-requests.
144134

145-
## Running the Performance Tests
146-
147-
Running performance tests is a little awkward right now. First, generate the
148-
Xcode project using this command:
149-
150-
```sh
151-
$ Utilities/bootstrap --generate-xcodeproj --enable-perf-tests
152-
```
153-
154-
Then, open the generated project and run the `PerformanceTest` scheme.
155-
156135
## Testing on Linux with Docker
157136

158137
For contributors on macOS who need to test on Linux, install Docker and use the

Sources/TSCBasic/Process.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public struct ProcessResult: CustomStringConvertible {
3939
/// The arguments with which the process was launched.
4040
public let arguments: [String]
4141

42+
/// The environment with which the process was launched.
43+
public let environment: [String: String]
44+
4245
/// The exit status of the process.
4346
public let exitStatus: ExitStatus
4447

@@ -55,6 +58,7 @@ public struct ProcessResult: CustomStringConvertible {
5558
/// See `waitpid(2)` for information on the exit status code.
5659
public init(
5760
arguments: [String],
61+
environment: [String: String],
5862
exitStatusCode: Int32,
5963
output: Result<[UInt8], AnyError>,
6064
stderrOutput: Result<[UInt8], AnyError>
@@ -70,18 +74,20 @@ public struct ProcessResult: CustomStringConvertible {
7074
exitStatus = .terminated(code: WEXITSTATUS(exitStatusCode))
7175
}
7276
#endif
73-
self.init(arguments: arguments, exitStatus: exitStatus, output: output,
77+
self.init(arguments: arguments, environment: environment, exitStatus: exitStatus, output: output,
7478
stderrOutput: stderrOutput)
7579
}
7680

7781
/// Create an instance using an exit status and output result.
7882
public init(
7983
arguments: [String],
84+
environment: [String: String],
8085
exitStatus: ExitStatus,
8186
output: Result<[UInt8], AnyError>,
8287
stderrOutput: Result<[UInt8], AnyError>
8388
) {
8489
self.arguments = arguments
90+
self.environment = environment
8591
self.output = output
8692
self.stderrOutput = stderrOutput
8793
self.exitStatus = exitStatus
@@ -474,6 +480,7 @@ public final class Process: ObjectIdentifierProtocol {
474480
// Construct the result.
475481
let executionResult = ProcessResult(
476482
arguments: arguments,
483+
environment: environment,
477484
exitStatusCode: exitStatusCode,
478485
output: stdout.result,
479486
stderrOutput: stderr.result
@@ -657,7 +664,10 @@ extension ProcessResult.Error: CustomStringConvertible {
657664
case .signalled(let signal):
658665
stream <<< "signalled(\(signal)): "
659666
}
660-
667+
668+
stream <<< result.environment.map({ "\($0)=\($1)" }).joined(separator: " ")
669+
stream <<< " "
670+
661671
// Strip sandbox information from arguments to keep things pretty.
662672
var args = result.arguments
663673
// This seems a little fragile.

Sources/Workspace/UserToolchain.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,18 @@ public final class UserToolchain: Toolchain {
234234
if let pdLibDirEnvStr = ProcessEnv.vars["SWIFTPM_PD_LIBS"] {
235235
// We pick the first path which exists in a colon seperated list.
236236
let paths = pdLibDirEnvStr.split(separator: ":").map(String.init)
237+
var foundPDLibDir = false
237238
for pathString in paths {
238239
if let path = try? AbsolutePath(validating: pathString), localFileSystem.exists(path) {
239240
pdLibDir = path
241+
foundPDLibDir = true
240242
break
241243
}
242244
}
245+
246+
if !foundPDLibDir {
247+
fatalError("Couldn't find any SWIFTPM_PD_LIBS directory: \(pdLibDirEnvStr)")
248+
}
243249
}
244250

245251
manifestResources = UserManifestResources(

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ final class WorkspaceTests: XCTestCase {
147147
"""
148148
}
149149

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

Utilities/Docker/Dockerfile

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
11
# This source file is part of the Swift.org open source project
22
#
3-
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
3+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
44
# Licensed under Apache License v2.0 with Runtime Library Exception
55
#
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
FROM ubuntu:16.04
9+
FROM ubuntu:18.04
10+
1011
# Install related packages.
11-
RUN apt-get -q update && \
12+
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
13+
apt-get -q update && \
1214
apt-get -q install -y \
13-
build-essential \
14-
make \
15-
libc6-dev \
16-
clang-3.6 \
17-
curl \
18-
libedit-dev \
19-
python2.7 \
20-
python2.7-dev \
21-
libicu-dev \
22-
rsync \
23-
libxml2 \
24-
git \
25-
libcurl4-openssl-dev \
26-
vim \
27-
libblocksruntime-dev \
28-
cmake \
29-
ninja-build \
30-
sqlite3 \
31-
libsqlite3-dev \
32-
libncurses5-dev \
33-
&& update-alternatives --quiet --install /usr/bin/clang clang /usr/bin/clang-3.6 100 \
34-
&& update-alternatives --quiet --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 \
35-
&& rm -r /var/lib/apt/lists/*
36-
ARG SNAPSHOT
15+
make \
16+
libc6-dev \
17+
clang-3.9 \
18+
curl \
19+
libedit-dev \
20+
libpython2.7 \
21+
libicu-dev \
22+
libssl-dev \
23+
libxml2 \
24+
tzdata \
25+
git \
26+
libcurl4-openssl-dev \
27+
ninja-build \
28+
sqlite3 \
29+
libsqlite3-dev \
30+
libncurses5-dev \
31+
pkg-config \
32+
apt-transport-https \
33+
ca-certificates \
34+
gnupg \
35+
wget \
36+
software-properties-common && \
37+
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add - && \
38+
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' && \
39+
apt-get -q update && \
40+
apt-get -q install -y cmake && \
41+
update-alternatives --quiet --install /usr/bin/clang clang /usr/bin/clang-3.9 100 && \
42+
update-alternatives --quiet --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.9 100 && \
43+
rm -r /var/lib/apt/lists/*
3744

45+
ARG SNAPSHOT
3846
COPY $SNAPSHOT /
3947
RUN tar -xvzf $SNAPSHOT --directory / --strip-components=1 && \
4048
rm -rf swift-DEVELOPMENT-SNAPSHOT*
49+
4150
# Set Swift Path
4251
ENV PATH /usr/bin:$PATH
52+
4353
# Print Installed Swift Version
4454
RUN swift --version

Utilities/Docker/docker-utils

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
2424

2525
def call(args):
2626
"""Prints and executes a command."""
27-
print " ".join(args)
27+
print(" ".join(args))
2828
return subprocess.call(args)
2929

3030
def docker_run(command_args):
@@ -40,24 +40,24 @@ def docker_run(command_args):
4040
"-v", "%s:/llbuild" % llbuild_dir,
4141
"-w", "/swiftpm",
4242
"--rm",
43-
"swiftpm-docker-1604"
43+
"swiftpm-docker-1804"
4444
] + command_args)
4545

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

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

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

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

7474
# Create docker image.
7575
call([
7676
"docker",
7777
"build",
78-
"-t", "swiftpm-docker-1604",
78+
"-t", "swiftpm-docker-1804",
7979
"--build-arg", "SNAPSHOT=%s" % snapshot_filename,
8080
script_dir
8181
])
@@ -90,13 +90,13 @@ def bootstrap(args):
9090

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

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

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

126126
# spm
127127
parser_swift_build = subparsers.add_parser(
128-
"spm",
129-
help="runs the spm helper script in a container.")
128+
"swift",
129+
help="runs a SwiftPM executable in a container.")
130130
parser_swift_build.add_argument("arguments", nargs="*")
131131
parser_swift_build.set_defaults(func=build_run)
132132

0 commit comments

Comments
 (0)