Swift package manager conditional compile not respecting flags

隐身守侯 提交于 2019-12-11 02:14:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!