Skip to content

Commit a656b4a

Browse files
committed
---
yaml --- r: 347461 b: refs/heads/master c: e628898 h: refs/heads/master i: 347459: 0c9684b
1 parent 33d2163 commit a656b4a

File tree

8 files changed

+193
-45
lines changed

8 files changed

+193
-45
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 71cdf4a8112372ac670e0c2c10ebe1bf3128a1a8
2+
refs/heads/master: e62889898da3262faa32f33bd553f3aec8b1eeab
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import argparse
6+
import os
7+
import subprocess
8+
9+
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument('--verbose', '-v', action='store_true')
13+
parser.add_argument('--package-path', type=str, required=True)
14+
parser.add_argument('--build-path', type=str, required=True)
15+
parser.add_argument('--toolchain', type=str, required=True)
16+
17+
# Build the debug/release versions.
18+
args = parser.parse_args()
19+
swiftbuild_path = os.path.join(args.toolchain, 'usr', 'bin', 'swift-build')
20+
swiftbuild_args = [
21+
swiftbuild_path,
22+
'--package-path', args.package_path,
23+
'--build-path', args.build_path,
24+
'--configuration', 'debug',
25+
]
26+
if args.verbose:
27+
swiftbuild_args.append('--verbose')
28+
subprocess.call(swiftbuild_args)
29+
30+
swiftbuild_args = [
31+
swiftbuild_path,
32+
'--package-path', args.package_path,
33+
'--build-path', args.build_path,
34+
'--configuration', 'release',
35+
'-Xswiftc', '-Xllvm',
36+
'-Xswiftc', '-align-module-to-page-size',
37+
]
38+
if args.verbose:
39+
swiftbuild_args.append('--verbose')
40+
subprocess.call(swiftbuild_args)
41+
42+
43+
if __name__ == "__main__":
44+
main()

trunk/lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,32 @@ static Optional<llvm::vfs::Status> getStatusOfDependency(
247247
return status.get();
248248
}
249249

250+
/// If the file dependency in \p FullDepPath is inside the \p Base directory,
251+
/// this returns its path relative to \p Base. Otherwise it returns None.
252+
static Optional<StringRef> getRelativeDepPath(StringRef DepPath,
253+
StringRef Base) {
254+
// If Base is the root directory, or DepPath does not start with Base, bail.
255+
if (Base.size() <= 1 || !DepPath.startswith(Base)) {
256+
return None;
257+
}
258+
259+
assert(DepPath.size() > Base.size() &&
260+
"should never depend on a directory");
261+
262+
// Is the DepName something like ${Base}/foo.h"?
263+
if (path::is_separator(DepPath[Base.size()]))
264+
return DepPath.substr(Base.size() + 1);
265+
266+
// Is the DepName something like "${Base}foo.h", where Base
267+
// itself contains a trailing slash?
268+
if (path::is_separator(Base.back()))
269+
return DepPath.substr(Base.size());
270+
271+
// We have something next to Base, like "Base.h", that's somehow
272+
// become a dependency.
273+
return None;
274+
}
275+
250276
#pragma mark - Module Building
251277

252278
/// Builds a parseable module interface into a .swiftmodule at the provided
@@ -365,52 +391,29 @@ class swift::ParseableInterfaceBuilder {
365391
bool collectDepsForSerialization(CompilerInstance &SubInstance,
366392
SmallVectorImpl<FileDependency> &Deps,
367393
bool IsHashBased) {
368-
StringRef SDKPath = SubInstance.getASTContext().SearchPathOpts.SDKPath;
369-
StringRef ResourcePath =
370-
SubInstance.getASTContext().SearchPathOpts.RuntimeResourcePath;
394+
auto &Opts = SubInstance.getASTContext().SearchPathOpts;
395+
SmallString<128> SDKPath(Opts.SDKPath);
396+
path::native(SDKPath);
397+
SmallString<128> ResourcePath(Opts.RuntimeResourcePath);
398+
path::native(ResourcePath);
399+
371400
auto DTDeps = SubInstance.getDependencyTracker()->getDependencies();
372401
SmallVector<StringRef, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
373402
InitialDepNames.push_back(interfacePath);
374403
llvm::StringSet<> AllDepNames;
404+
SmallString<128> Scratch;
405+
406+
for (const auto &InitialDepName : InitialDepNames) {
407+
path::native(InitialDepName, Scratch);
408+
StringRef DepName = Scratch.str();
375409

376-
for (auto const &DepName : InitialDepNames) {
377410
assert(moduleCachePath.empty() || !DepName.startswith(moduleCachePath));
378411
assert(prebuiltCachePath.empty() || !DepName.startswith(prebuiltCachePath));
379412

380-
/// Lazily load the dependency buffer if we need it. If we're not
381-
/// dealing with a hash-based dependencies, and if the dependency is
382-
/// not a .swiftmodule, we can avoid opening the buffer.
383-
std::unique_ptr<llvm::MemoryBuffer> DepBuf = nullptr;
384-
auto getDepBuf = [&]() -> llvm::MemoryBuffer * {
385-
if (DepBuf) return DepBuf.get();
386-
if (auto Buf = getBufferOfDependency(fs, DepName, interfacePath,
387-
diags, diagnosticLoc)) {
388-
DepBuf = std::move(Buf);
389-
return DepBuf.get();
390-
}
391-
return nullptr;
392-
};
393-
394-
// Adjust the paths of dependences in the SDK to be relative to it
395-
bool IsSDKRelative = false;
396-
StringRef DepNameToStore = DepName;
397-
if (SDKPath.size() > 1 && DepName.startswith(SDKPath)) {
398-
assert(DepName.size() > SDKPath.size() &&
399-
"should never depend on a directory");
400-
if (llvm::sys::path::is_separator(DepName[SDKPath.size()])) {
401-
// Is the DepName something like ${SDKPath}/foo.h"?
402-
DepNameToStore = DepName.substr(SDKPath.size() + 1);
403-
IsSDKRelative = true;
404-
} else if (llvm::sys::path::is_separator(SDKPath.back())) {
405-
// Is the DepName something like "${SDKPath}foo.h", where SDKPath
406-
// itself contains a trailing slash?
407-
DepNameToStore = DepName.substr(SDKPath.size());
408-
IsSDKRelative = true;
409-
} else {
410-
// We have something next to an SDK, like "Foo.sdk.h", that's somehow
411-
// become a dependency.
412-
}
413-
}
413+
// Serialize the paths of dependencies in the SDK relative to it.
414+
Optional<StringRef> SDKRelativePath = getRelativeDepPath(DepName, SDKPath);
415+
StringRef DepNameToStore = SDKRelativePath.getValueOr(DepName);
416+
bool IsSDKRelative = SDKRelativePath.hasValue();
414417

415418
if (AllDepNames.insert(DepName).second && dependencyTracker) {
416419
dependencyTracker->addDependency(DepName, /*isSystem*/IsSDKRelative);
@@ -425,6 +428,20 @@ class swift::ParseableInterfaceBuilder {
425428
if (!Status)
426429
return true;
427430

431+
/// Lazily load the dependency buffer if we need it. If we're not
432+
/// dealing with a hash-based dependencies, and if the dependency is
433+
/// not a .swiftmodule, we can avoid opening the buffer.
434+
std::unique_ptr<llvm::MemoryBuffer> DepBuf = nullptr;
435+
auto getDepBuf = [&]() -> llvm::MemoryBuffer * {
436+
if (DepBuf) return DepBuf.get();
437+
if (auto Buf = getBufferOfDependency(fs, DepName, interfacePath,
438+
diags, diagnosticLoc)) {
439+
DepBuf = std::move(Buf);
440+
return DepBuf.get();
441+
}
442+
return nullptr;
443+
};
444+
428445
if (IsHashBased) {
429446
auto buf = getDepBuf();
430447
if (!buf) return true;
@@ -687,8 +704,7 @@ class ParseableInterfaceModuleLoaderImpl {
687704
if (!dep.isSDKRelative())
688705
return dep.getPath();
689706

690-
StringRef SDKPath = ctx.SearchPathOpts.SDKPath;
691-
scratch.assign(SDKPath.begin(), SDKPath.end());
707+
path::native(ctx.SearchPathOpts.SDKPath, scratch);
692708
llvm::sys::path::append(scratch, dep.getPath());
693709
return StringRef(scratch.data(), scratch.size());
694710
}
@@ -1003,7 +1019,8 @@ class ParseableInterfaceModuleLoaderImpl {
10031019
SmallString<128> SDKRelativeBuffer;
10041020
for (auto &dep: allDeps) {
10051021
StringRef fullPath = getFullDependencyPath(dep, SDKRelativeBuffer);
1006-
dependencyTracker->addDependency(fullPath, dep.isSDKRelative());
1022+
dependencyTracker->addDependency(fullPath,
1023+
/*IsSystem=*/dep.isSDKRelative());
10071024
}
10081025
}
10091026

trunk/utils/build-script

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,17 @@ class BuildScriptInvocation(object):
244244
"--android-icu-i18n-include, and --android-icu-data "
245245
"must be specified")
246246

247-
if args.legacy_impl and (args.build_indexstoredb or
248-
args.build_sourcekitlsp):
247+
targets_needing_toolchain = [
248+
'build_indexstoredb',
249+
'build_sourcekitlsp',
250+
'build_toolchainbenchmarks',
251+
]
252+
has_target_needing_toolchain = \
253+
bool(sum(getattr(args, x) for x in targets_needing_toolchain))
254+
if args.legacy_impl and has_target_needing_toolchain:
249255
diagnostics.fatal(
250256
"--legacy-impl is incompatible with building packages needing "
251-
"a toolchain (indexstore-db or sourcekit-lsp)")
257+
"a toolchain (%s)" % ", ".join(targets_needing_toolchain))
252258

253259
@staticmethod
254260
def apply_default_arguments(toolchain, args):
@@ -879,6 +885,8 @@ class BuildScriptInvocation(object):
879885
product_classes.append(products.IndexStoreDB)
880886
if self.args.build_sourcekitlsp:
881887
product_classes.append(products.SourceKitLSP)
888+
if self.args.build_toolchainbenchmarks:
889+
product_classes.append(products.ToolchainBenchmarks)
882890
return product_classes
883891

884892
def execute(self):

trunk/utils/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ def create_argument_parser():
546546
help='build IndexStoreDB')
547547
option(['--sourcekit-lsp'], toggle_true('build_sourcekitlsp'),
548548
help='build SourceKitLSP')
549+
option(['--toolchain-benchmarks'],
550+
toggle_true('build_toolchainbenchmarks'),
551+
help='build Swift Benchmarks using swiftpm against the just built '
552+
'toolchain')
549553

550554
option('--xctest', toggle_true('build_xctest'),
551555
help='build xctest')

trunk/utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'build_swiftevolve': False,
8989
'build_indexstoredb': False,
9090
'build_sourcekitlsp': False,
91+
'build_toolchainbenchmarks': False,
9192
'build_tvos': True,
9293
'build_tvos_device': False,
9394
'build_tvos_simulator': False,
@@ -448,6 +449,7 @@ class IgnoreOption(_BaseOption):
448449
EnableOption('--libicu', dest='build_libicu'),
449450
EnableOption('--indexstore-db', dest='build_indexstoredb'),
450451
EnableOption('--sourcekit-lsp', dest='build_sourcekitlsp'),
452+
EnableOption('--toolchain-benchmarks', dest='build_toolchainbenchmarks'),
451453
EnableOption('--long-test'),
452454
EnableOption('--show-sdks'),
453455
EnableOption('--stress-test'),

trunk/utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
from .benchmarks import ToolchainBenchmarks
1314
from .cmark import CMark
1415
from .foundation import Foundation
1516
from .indexstoredb import IndexStoreDB
@@ -47,4 +48,5 @@
4748
'SwiftEvolve',
4849
'IndexStoreDB',
4950
'SourceKitLSP',
51+
'ToolchainBenchmarks',
5052
]
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# swift_build_support/products/benchmarks.py --------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
import platform
15+
16+
from . import product
17+
from .. import shell
18+
from .. import targets
19+
20+
21+
# Build against the current installed toolchain.
22+
class ToolchainBenchmarks(product.Product):
23+
@classmethod
24+
def product_source_name(cls):
25+
return "benchmarks"
26+
27+
@classmethod
28+
def is_build_script_impl_product(cls):
29+
return False
30+
31+
def do_build(self, host_target):
32+
run_build_script_helper(host_target, self, self.args)
33+
34+
def do_test(self, host_target):
35+
"""Just run a single instance of the command for both .debug and
36+
.release.
37+
"""
38+
cmdline = ['--num-iters=1', 'XorLoop']
39+
debug_bench = os.path.join(self.build_dir, 'debug', 'SwiftBench')
40+
shell.call([debug_bench] + cmdline)
41+
42+
release_bench = os.path.join(self.build_dir, 'release', 'SwiftBench')
43+
shell.call([release_bench] + cmdline)
44+
45+
46+
def run_build_script_helper(host_target, product, args):
47+
toolchain_path = args.install_destdir
48+
if platform.system() == 'Darwin':
49+
# The prefix is an absolute path, so concatenate without os.path.
50+
toolchain_path += \
51+
targets.darwin_toolchain_prefix(args.install_prefix)
52+
53+
# Our source_dir is expected to be './$SOURCE_ROOT/benchmarks'. That is due
54+
# the assumption that each product is in its own build directory. This
55+
# product is not like that and has its package/tools instead in
56+
# ./$SOURCE_ROOT/swift/benchmark.
57+
package_path = os.path.join(product.source_dir, '..', 'swift', 'benchmark')
58+
package_path = os.path.abspath(package_path)
59+
60+
# We use a separate python helper to enable quicker iteration when working
61+
# on this by avoiding going through build-script to test small changes.
62+
helper_path = os.path.join(package_path, 'utils', 'build_script_helper.py')
63+
64+
build_cmd = [
65+
helper_path,
66+
'--verbose',
67+
'--package-path', package_path,
68+
'--build-path', product.build_dir,
69+
'--toolchain', toolchain_path,
70+
]
71+
shell.call(build_cmd)

0 commit comments

Comments
 (0)