Skip to content

Commit c68cf3b

Browse files
authored
Merge pull request #101 from ahoppen/local-dependencies
Allow depending on local dependencies for CI
2 parents 23c6604 + 5be177f commit c68cf3b

File tree

4 files changed

+99
-32
lines changed

4 files changed

+99
-32
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ For local development you'll first need to download and install a recent [swift.
3131

3232
To generate an Xcode project that's set up correctly, run `build-script-helper.py`, passing the path to the downloaded toolchain via the `--toolchain` option, the tool's package name in the `--package-dir` option, and the `generate-xcodeproj` action:
3333
```
34-
$ ./build-script-helper.py --package-dir SourceKitStressTester --toolchain $TOOLCHAIN_DIR generate-xcodeproj
34+
$ ./build-script-helper.py --package-dir SourceKitStressTester --toolchain $TOOLCHAIN_DIR generate-xcodeproj --no-local-deps
3535
```
36+
If you have the [SwiftSyntax](https://github.com/apple/swift-syntax) and [SwiftPM](https://github.com/apple/swift-package-manager) repositories already checked out next to the stress tester's repository, you can omit the `--no-local-deps` option to use the existing checkouts instead of fetching the dependencies using SwiftPM.
37+
3638
This will generate `SourceKitStressTester/SourceKitStressTester.xcodeproj`. Open it and select the toolchain you installed from the Xcode > Toolchains menu, before building the `SourceKitStressTester-Package` scheme.
3739

3840
#### Via command line
3941

40-
To build, run `build-script-helper.py`, passing the path to the downloaded toolchain via the `--toolchain` option and the tool's package name in the `--package-dir` option:
42+
To build, run `build-script-helper.py`, passing the path to the downloaded toolchain via the `--toolchain` option and the tool's package name in the `--package-dir` option.
4143
```
4244
$ ./build-script-helper.py --package-dir SourceKitStressTester --toolchain $TOOLCHAIN_DIR
4345
```
46+
If you have the [SwiftSyntax](https://github.com/apple/swift-syntax) and [SwiftPM](https://github.com/apple/swift-package-manager) repositories already checked out next to the stress tester's repository, you can omit the `--no-local-deps` option to use the existing checkouts instead of fetching the dependencies using SwiftPM.
4447

4548
To run the tests, repeat the above command, but additionally pass the `test` action:
4649
```
47-
$ ./Utilities/build-script-helper.py --package-dir SourceKitStressTester --toolchain $TOOLCHAIN_DIR
50+
$ ./Utilities/build-script-helper.py test --package-dir SourceKitStressTester --toolchain $TOOLCHAIN_DIR
4851
```
4952

5053
## Running
Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.1
22

33
import PackageDescription
4+
#if os(Linux)
5+
import Glibc
6+
#else
7+
import Darwin.C
8+
#endif
49

510
let package = Package(
611
name: "SourceKitStressTester",
@@ -9,34 +14,57 @@ let package = Package(
914
.executable(name: "sk-swiftc-wrapper", targets: ["sk-swiftc-wrapper"]),
1015
],
1116
dependencies: [
12-
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
13-
// FIXME: We should depend on master once master contains all the degybed files
14-
.package(url: "https://github.com/apple/swift-syntax.git", .branch("master")),
15-
17+
// See dependencies added below.
1618
],
1719
targets: [
1820
.target(
1921
name: "Common",
20-
dependencies: ["TSCUtility"]),
22+
dependencies: ["TSCUtility"]
23+
),
2124
.target(
2225
name: "StressTester",
23-
dependencies: ["Common", "TSCUtility", "SwiftSyntax"]),
26+
dependencies: ["Common", "TSCUtility", "SwiftSyntax"]
27+
),
2428
.target(
2529
name: "SwiftCWrapper",
26-
dependencies: ["Common", "TSCUtility"]),
30+
dependencies: ["Common", "TSCUtility"]
31+
),
2732

2833
.target(
2934
name: "sk-stress-test",
30-
dependencies: ["StressTester"]),
35+
dependencies: ["StressTester"]
36+
),
3137
.target(
3238
name: "sk-swiftc-wrapper",
33-
dependencies: ["SwiftCWrapper"]),
39+
dependencies: ["SwiftCWrapper"]
40+
),
3441

3542
.testTarget(
36-
name: "StressTesterToolTests",
37-
dependencies: ["StressTester"]),
43+
name: "StressTesterToolTests",
44+
dependencies: ["StressTester"],
45+
// SwiftPM does not get the rpath for XCTests in multiroot packages right (rdar://56793593)
46+
// Add the correct rpath here
47+
linkerSettings: [.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@loader_path/../../../"])]
48+
),
3849
.testTarget(
3950
name: "SwiftCWrapperToolTests",
40-
dependencies: ["SwiftCWrapper"])
51+
dependencies: ["SwiftCWrapper"],
52+
// SwiftPM does not get the rpath for XCTests in multiroot packages right (rdar://56793593)
53+
// Add the correct rpath here
54+
linkerSettings: [.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@loader_path/../../../"])]
55+
)
4156
]
4257
)
58+
59+
if getenv("SWIFTCI_USE_LOCAL_DEPS") == nil {
60+
// Building standalone.
61+
package.dependencies += [
62+
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
63+
.package(url: "https://github.com/apple/swift-syntax.git", .branch("master")),
64+
]
65+
} else {
66+
package.dependencies += [
67+
.package(path: "../../swiftpm"),
68+
.package(path: "../../swift-syntax"),
69+
]
70+
}

SwiftEvolve/Package.swift

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1-
// swift-tools-version:4.2
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version:5.1
32

43
import PackageDescription
54

5+
#if os(Linux)
6+
import Glibc
7+
#else
8+
import Darwin.C
9+
#endif
10+
611
let package = Package(
712
name: "SwiftEvolve",
813
products: [
914
.executable(name: "swift-evolve", targets: ["swift-evolve"]),
1015
.library(name: "SwiftEvolve", targets: ["SwiftEvolve"])
1116
],
1217
dependencies: [
13-
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
14-
// FIXME: We should depend on master once master contains all the degybed files
15-
.package(url: "https://github.com/apple/swift-syntax.git", .branch("master")),
18+
// See dependencies added below.
1619
],
1720
targets: [
1821
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
1922
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2023
.target(
2124
name: "swift-evolve",
22-
dependencies: ["SwiftEvolve"]),
25+
dependencies: ["SwiftEvolve"]
26+
),
2327
.target(
2428
name: "SwiftEvolve",
25-
dependencies: ["TSCUtility", "SwiftSyntax"]),
29+
dependencies: ["TSCUtility", "SwiftSyntax"]
30+
),
2631
.testTarget(
27-
name: "SwiftEvolveTests",
28-
dependencies: ["SwiftEvolve"])
32+
name: "SwiftEvolveTests",
33+
dependencies: ["SwiftEvolve"],
34+
// SwiftPM does not get the rpath for XCTests in multiroot packages right (rdar://56793593)
35+
// Add the correct rpath here
36+
linkerSettings: [.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@loader_path/../../../"])]
37+
)
2938
]
3039
)
40+
41+
if getenv("SWIFTCI_USE_LOCAL_DEPS") == nil {
42+
// Building standalone.
43+
package.dependencies += [
44+
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("master")),
45+
.package(url: "https://github.com/apple/swift-syntax.git", .branch("master")),
46+
]
47+
} else {
48+
package.dependencies += [
49+
.package(path: "../../swiftpm"),
50+
.package(path: "../../swift-syntax"),
51+
]
52+
}

build-script-helper.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def parse_args(args):
4040
parser.add_argument('--build-dir', default='.build')
4141
parser.add_argument('--toolchain', required=True, help='the toolchain to use when building this package')
4242
parser.add_argument('--update', action='store_true', help='update all SwiftPM dependencies')
43+
parser.add_argument('--no-local-deps', action='store_true', help='use normal remote dependencies when building')
4344
parser.add_argument('build_actions', help="Extra actions to perform. Can be any number of the following", choices=['all', 'build', 'test', 'install', 'generate-xcodeproj'], nargs="*", default=['build'])
4445

4546
parsed = parser.parse_args(args)
@@ -64,12 +65,18 @@ def run(args):
6465
sourcekit_searchpath=args.sourcekitd_dir
6566
package_name = os.path.basename(args.package_dir)
6667

68+
env = dict(os.environ)
69+
# Use local dependencies (i.e. checked out next sourcekit-lsp).
70+
if not args.no_local_deps:
71+
env['SWIFTCI_USE_LOCAL_DEPS'] = "1"
72+
6773
if args.update:
6874
print("** Updating dependencies of %s **" % package_name)
6975
try:
7076
update_swiftpm_dependencies(package_dir=args.package_dir,
7177
swift_exec=args.swift_exec,
7278
build_dir=args.build_dir,
79+
env=env,
7380
verbose=args.verbose)
7481
except subprocess.CalledProcessError as e:
7582
printerr('FAIL: Updating dependencies of %s failed' % package_name)
@@ -86,6 +93,7 @@ def run(args):
8693
sourcekit_searchpath=sourcekit_searchpath,
8794
build_dir=args.build_dir,
8895
config=args.config,
96+
env=env,
8997
verbose=args.verbose)
9098
except subprocess.CalledProcessError as e:
9199
printerr('FAIL: Building %s failed' % package_name)
@@ -100,6 +108,7 @@ def run(args):
100108
generate_xcodeproj(args.package_dir,
101109
swift_exec=args.swift_exec,
102110
sourcekit_searchpath=sourcekit_searchpath,
111+
env=env,
103112
verbose=args.verbose)
104113
except subprocess.CalledProcessError as e:
105114
printerr('FAIL: Generating the Xcode project failed')
@@ -119,6 +128,7 @@ def run(args):
119128
sourcekit_searchpath=sourcekit_searchpath,
120129
build_dir=args.build_dir,
121130
config=test_config,
131+
env=env,
122132
verbose=args.verbose)
123133
except subprocess.CalledProcessError as e:
124134
printerr('FAIL: Testing %s failed' % package_name)
@@ -158,18 +168,22 @@ def should_run_action(action_name, selected_actions):
158168
return False
159169

160170

161-
def update_swiftpm_dependencies(package_dir, swift_exec, build_dir, verbose):
171+
def update_swiftpm_dependencies(package_dir, swift_exec, build_dir, env, verbose):
162172
args = [swift_exec, 'package', '--package-path', package_dir, '--build-path', build_dir, 'update']
163-
check_call(args, verbose=verbose)
173+
check_call(args, env=env, verbose=verbose)
164174

165175

166-
def invoke_swift(package_dir, action, swift_exec, sourcekit_searchpath, build_dir, config, verbose):
176+
def invoke_swift(package_dir, action, swift_exec, sourcekit_searchpath, build_dir, config, env, verbose):
167177
swiftc_args = ['-Fsystem', sourcekit_searchpath]
168178
linker_args = ['-rpath', sourcekit_searchpath]
169179

170-
171180
args = [swift_exec, action, '--package-path', package_dir, '-c', config, '--build-path', build_dir] + interleave('-Xswiftc', swiftc_args) + interleave('-Xlinker', linker_args)
172-
check_call(args, verbose=verbose)
181+
182+
# Tell SwiftSyntax that we are building in a CI environment so that it does
183+
# not need to rebuilt if it has already been built before.
184+
env['SWIFT_BUILD_SCRIPT_ENVIRONMENT'] = '1'
185+
186+
check_call(args, env=env, verbose=verbose)
173187

174188

175189
def install_package(package_dir, install_dir, sourcekit_searchpath, build_dir, rpaths_to_delete, verbose):
@@ -203,7 +217,7 @@ def install(src, dest, rpaths_to_delete, rpaths_to_add, verbose):
203217
for rpath in rpaths_to_add:
204218
add_rpath(dest, rpath, verbose=verbose)
205219

206-
def generate_xcodeproj(package_dir, swift_exec, sourcekit_searchpath, verbose):
220+
def generate_xcodeproj(package_dir, swift_exec, sourcekit_searchpath, env, verbose):
207221
package_name = os.path.basename(package_dir)
208222
config_path = os.path.join(package_dir, 'Config.xcconfig')
209223
with open(config_path, 'w') as config_file:
@@ -215,7 +229,7 @@ def generate_xcodeproj(package_dir, swift_exec, sourcekit_searchpath, verbose):
215229
xcodeproj_path = os.path.join(package_dir, '%s.xcodeproj' % package_name)
216230

217231
args = [swift_exec, 'package', '--package-path', package_dir, 'generate-xcodeproj', '--xcconfig-overrides', config_path, '--output', xcodeproj_path]
218-
check_call(args, verbose=verbose)
232+
check_call(args, env=env, verbose=verbose)
219233

220234
def add_rpath(binary, rpath, verbose):
221235
cmd = ['install_name_tool', '-add_rpath', rpath, binary]

0 commit comments

Comments
 (0)