Skip to content
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

Reorder swiftc args to allow user override #715

Merged
merged 2 commits into from Oct 9, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Fixtures/Miscellaneous/OverrideSwiftcArgs/Package.swift
@@ -0,0 +1,5 @@
import PackageDescription

let package = Package(
name: "OverrideSwiftcArgs"
)
7 changes: 7 additions & 0 deletions Fixtures/Miscellaneous/OverrideSwiftcArgs/Sources/main.swift
@@ -0,0 +1,7 @@
/// This file exists to test the ability to override deployment targets via args passed to swiftc
/// For this test to work, this file must have an API call which was introduced in a version
/// higher than the default macOS deployment target that is checked in.
@available(macOS 10.20, *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I was wondering if available API could be used

func foo() {}

foo()
8 changes: 4 additions & 4 deletions Sources/Build/describe().swift
Expand Up @@ -38,7 +38,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
for module in graph.modules {
switch module {
case let module as SwiftModule:
let compile = try Command.compile(swiftModule: module, configuration: conf, prefix: prefix, otherArgs: swiftcArgs + toolchain.swiftPlatformArgs, compilerExec: toolchain.swiftCompiler)
let compile = try Command.compile(swiftModule: module, configuration: conf, prefix: prefix, otherArgs: toolchain.swiftPlatformArgs + swiftcArgs, compilerExec: toolchain.swiftCompiler)
commands.append(compile)
targets.append([compile], for: module)

Expand All @@ -48,7 +48,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
if module.isTest { continue }
#endif
// FIXME: Find a way to eliminate `externalModules` from here.
let compile = try Command.compile(clangModule: module, externalModules: graph.externalModules, configuration: conf, prefix: prefix, otherArgs: flags.cCompilerFlags + toolchain.clangPlatformArgs, compilerExec: toolchain.clangCompiler)
let compile = try Command.compile(clangModule: module, externalModules: graph.externalModules, configuration: conf, prefix: prefix, otherArgs: toolchain.clangPlatformArgs + flags.cCompilerFlags, compilerExec: toolchain.clangCompiler)
commands += compile
targets.append(compile, for: module)

Expand All @@ -62,7 +62,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac

for product in graph.products {
var rpathArgs = [String]()

// On Linux, always embed an RPATH adjacent to the linked binary. Note
// that the '$ORIGIN' here is literal, it is a reference which is
// understood by the dynamic linker.
Expand All @@ -73,7 +73,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
if product.containsOnlyClangModules {
command = try Command.linkClangModule(product, configuration: conf, prefix: prefix, otherArgs: Xld, linkerExec: toolchain.clangCompiler)
} else {
command = try Command.linkSwiftModule(product, configuration: conf, prefix: prefix, otherArgs: Xld + swiftcArgs + toolchain.swiftPlatformArgs + rpathArgs, linkerExec: toolchain.swiftCompiler)
command = try Command.linkSwiftModule(product, configuration: conf, prefix: prefix, otherArgs: Xld + toolchain.swiftPlatformArgs + swiftcArgs + rpathArgs, linkerExec: toolchain.swiftCompiler)
}

commands.append(command)
Expand Down
27 changes: 18 additions & 9 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Expand Up @@ -21,7 +21,7 @@ import func POSIX.popen
class MiscellaneousTestCase: XCTestCase {
func testPrintsSelectedDependencyVersion() {

// verifies the stdout contains information about
// verifies the stdout contains information about
// the selected version of the package

fixture(name: "DependencyResolution/External/Simple", tags: ["1.3.5"]) { prefix in
Expand Down Expand Up @@ -91,21 +91,21 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertNoSuchPath(buildDir.appending(component: "some"))
}
}

func testManifestExcludes4() {

// exclude directory is inside Tests folder (Won't build without exclude)

fixture(name: "Miscellaneous/ExcludeDiagnostic4") { prefix in
XCTAssertBuilds(prefix)
XCTAssertFileExists(prefix.appending(components: ".build", "debug", "FooPackage.swiftmodule"))
}
}

func testManifestExcludes5() {

// exclude directory is Tests folder (Won't build without exclude)

fixture(name: "Miscellaneous/ExcludeDiagnostic5") { prefix in
XCTAssertBuilds(prefix)
XCTAssertFileExists(prefix.appending(components: ".build", "debug", "FooPackage.swiftmodule"))
Expand Down Expand Up @@ -318,13 +318,13 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertFileExists(prefix.appending(components: ".build", "debug", "libProductName.\(Product.dynamicLibraryExtension)"))
}
}

func testProductWithNoModules() {
fixture(name: "Miscellaneous/ProductWithNoModules") { prefix in
XCTAssertBuildFails(prefix)
}
}

func testProductWithMissingModules() {
fixture(name: "Miscellaneous/ProductWithMissingModules") { prefix in
XCTAssertBuildFails(prefix)
Expand Down Expand Up @@ -387,6 +387,14 @@ class MiscellaneousTestCase: XCTestCase {
}
}

func testOverridingSwiftcArguments() throws {
#if os(macOS)
fixture(name: "Miscellaneous/OverrideSwiftcArgs") { prefix in
try executeSwiftBuild(prefix, configuration: .Debug, printIfError: true, Xcc: [], Xld: [], Xswiftc: ["-target", "x86_64-apple-macosx10.20"], env: [:])
}
#endif
}

static var allTests = [
("testExecutableAsBuildOrderDependency", testExecutableAsBuildOrderDependency),
("testPrintsSelectedDependencyVersion", testPrintsSelectedDependencyVersion),
Expand Down Expand Up @@ -418,5 +426,6 @@ class MiscellaneousTestCase: XCTestCase {
("testSecondBuildIsNullInModulemapGen", testSecondBuildIsNullInModulemapGen),
("testSwiftTestParallel", testSwiftTestParallel),
("testInitPackageNonc99Directory", testInitPackageNonc99Directory),
("testOverridingSwiftcArguments", testOverridingSwiftcArguments),
]
}