问题
I have a Package.swift file with the following structure
var package = Package(
name: "MyProject",
targets: [
Target(name: "MyProject")
],
dependencies: [],
exclude: ["Exclude"]
)
#if DEBUG
package.dependencies.append(Package.Dependency.Package(url: "Dependency-One.git", majorVersion: 0, minor: 0))
#else
package.dependencies.append(Package.Dependency.Package(url: "Dependency-Two.git", majorVersion: 0, minor: 0))
#endif
When I build this with any of the following:
swift build
swift build -c release
swift build -c debug
swift build -c RELEASE
swift build -c DEBUG
It still always downloads Dependency-Two.git. This remains true if I prepend all of the above with
rm -rf .build/ && rm -rf Packages/
So I don't think it's because it's reusing some cache. Is it possible to do what I'm intending here?
回答1:
This is by design. The manifest is not intended to be used to declare conditional behaviors in this manner, but unfortunately for what you are trying to do, the mechanism by which this would be supported (e.g., including additional APIs from PackageDescription
to declare what you want in each configuration) is not designed yet.
I suggest you file an enhancement request for this feature on https://bugs.swift.org.
来源:https://stackoverflow.com/questions/40064198/swift-package-manager-conditional-compile-not-respecting-flags