Skip to content

Use global code coverage flag in swift package generate-xcodeproj #2919

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 2 commits into from
Sep 11, 2020
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
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ if ProcessInfo.processInfo.environment["SWIFTPM_LLBUILD_FWK"] == nil {
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("master")),
.package(url: "https://github.com/apple/swift-argument-parser.git", .exact("0.3.0")),
// The 'swift-argument-parser' version declared here must match that
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight nitpick here — it doesn't have to exactly match, but just be compatible. Since the dependency is "up to next minor", it means that all other dependencies have to resolve to a 0.3.x dependency. In general SwiftPM will pick the highest version that satisfies all the constrains, so it's fine for one package to specify "at least 0.3.0" and another to say "at least 0.3.2" and another to say "at least 0.3", as long as the package has a single tag that satisfies all requirements. So I think the working here would be that the version requirements have to be compatible, but they don't need to strictly match. It's only a problem if one of them starts to require "0.4.x", for example.

// used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
// dependency version changes here with those projects.
.package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMinor(from: "0.3.1")),
.package(url: "https://github.com/apple/swift-driver.git", .branch("master")),
]
} else {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Commands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public struct SwiftToolOptions: ParsableArguments {
}

/// Whether to enable code coverage.
@Flag(name: .customLong("enable-code-coverage"), help: "Test with code coverage enabled")
@Flag(name: .customLong("code-coverage"),
inversion: .prefixedEnableDisable,
help: "Enable code coverage")
var shouldEnableCodeCoverage: Bool = false

// TODO: Does disable-automatic-resolution alias force-resolved-versions?
Expand Down
29 changes: 12 additions & 17 deletions Sources/Commands/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,6 @@ extension SwiftPackageTool {
@Option(help: "Path to xcconfig file", completion: .file())
var xcconfigOverrides: AbsolutePath?

@Flag(name: .customLong("code-coverage"),
inversion: .prefixedEnableDisable,
help: "Enable code coverage in the generated project")
var isCodeCoverageEnabled: Bool = false

@Option(name: .customLong("output"),
help: "Path where the Xcode project should be generated")
var outputPath: AbsolutePath?
Expand All @@ -559,16 +554,6 @@ extension SwiftPackageTool {

@Flag(help: "Do not add file references for extra files to the generated Xcode project")
var skipExtraFiles: Bool = false

func xcodeprojOptions(with buildFlags: BuildFlags) -> XcodeprojOptions {
XcodeprojOptions(
flags: buildFlags,
xcconfigOverrides: xcconfigOverrides,
isCodeCoverageEnabled: isCodeCoverageEnabled,
useLegacySchemeGenerator: useLegacySchemeGenerator,
enableAutogeneration: enableAutogeneration,
addExtraFiles: !skipExtraFiles)
}
}

@OptionGroup()
Expand All @@ -577,6 +562,16 @@ extension SwiftPackageTool {
@OptionGroup()
var options: Options

func xcodeprojOptions() -> XcodeprojOptions {
XcodeprojOptions(
flags: swiftOptions.buildFlags,
xcconfigOverrides: options.xcconfigOverrides,
isCodeCoverageEnabled: swiftOptions.shouldEnableCodeCoverage,
useLegacySchemeGenerator: options.useLegacySchemeGenerator,
enableAutogeneration: options.enableAutogeneration,
addExtraFiles: !options.skipExtraFiles)
}

func run(_ swiftTool: SwiftTool) throws {
let graph = try swiftTool.loadPackageGraph()

Expand All @@ -597,7 +592,7 @@ extension SwiftPackageTool {
}
let xcodeprojPath = Xcodeproj.buildXcodeprojPath(outputDir: dstdir, projectName: projectName)

var genOptions = options.xcodeprojOptions(with: swiftOptions.buildFlags)
var genOptions = xcodeprojOptions()
genOptions.manifestLoader = try swiftTool.getManifestLoader()

try Xcodeproj.generate(
Expand All @@ -616,7 +611,7 @@ extension SwiftPackageTool {
diagnostics: swiftTool.diagnostics,
watchmanScriptsDir: swiftTool.buildPath.appending(component: "watchman"),
packageRoot: swiftTool.packageRoot!
).runXcodeprojWatcher(options.xcodeprojOptions(with: swiftOptions.buildFlags))
).runXcodeprojWatcher(xcodeprojOptions())
}
}
}
Expand Down