在DUB配置文件中,如何更改依赖项的配置(buildOptions)?

时间:2017-07-31 23:01:39

标签: d dub

假设我有一个名为“myapp”的项目,它取决于“sdlang-d”。我想使用命令行中的dub build --build=release-debug将我的项目构建为release-debug。由于SDLang issue #54,我不能将它作为release-debug构建sdlang-d,所以我想使用我的dub配置文件强制sdlang-d构建为“debug”或“debugMode”,无论何时我为“myapp”选择的构建选项,然后将sdlang-d的调试版本链接到myapp的发布版本(这样我的sdlang-d之外的代码就可以从优化中受益)。

出于测试目的,我创建了一个名为"dub_dependency_config"的github项目来模拟这种情况。在下面的文字中,我将提供具体的输出,我已经从我尝试的事情中观察到了,因此我将引用“ dub_dependency_config ”而不是“myapp”。

我从一个简单的dub.sdl配置文件开始......

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"

...并尝试使用dub build --build=release-debug进行编译,当然问题#54也是如此:

C:\dprojects\dub_dependency_config>dub build --build=release-debug
Performing "release-debug" build using dmd for x86_64.
libinputvisitor 1.2.2: target for configuration "library" is up to date.
taggedalgebraic 0.10.7: target for configuration "library" is up to date.
sdlang-d 0.10.1: building configuration "library"...
..\..\Users\cjoan\AppData\Roaming\dub\packages\sdlang-d-0.10.1\sdlang-d\src\sdlang\lexer.d(1273,41): Deprecation: function std.datetime.TimeZone.getTimeZone is deprecated - Use PosixTimeZone.getTimeZone or WindowsTimeZone.getTimeZone instead
..\..\Users\cjoan\AppData\Roaming\dub\packages\sdlang-d-0.10.1\sdlang-d\src\sdlang\ast.d(680,21): Error: null dereference in function _D6sdlang3ast3Tag16getTagAttributesMFAyaAyaZS6sdlang3ast3Tag146__T11MemberRangeTC6sdlang3ast9AttributeVAyaa13_616c6c41747472696275746573VAyaa17_617474726962757465496e646963696573VAyaa11_5f61747472696275746573Z11MemberRange
dmd failed with exit code 1.

要解决这个问题,我希望能够写出这样的内容:

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1" {
    buildOptions "debugMode"
}

我没想到这实际上会起作用;文档中没有说它应该。无论如何我试了一下,配音似乎忽略了buildOptions标签中的dependency标签。配置文件变得与以前的配置文件相同,我得到了相同的问题#54编译器错误。

我已经阅读了subConfiguration,这似乎是this thread中提到的解决此问题的推荐方法。 subConfiguration给了我很多失败的配置体验。我们来看几点:

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
}
configuration "sdlang-hax" {
    buildOptions "debugMode"
}
subConfiguration "sdlang-d" "sdlang-hax"

这个产生:

C:\dprojects\dub_dependency_config>dub build --build=release-debug

## Warning for package dub_dependency_config, configuration sdlang-hax ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

debugMode: Call DUB with --build=debug

Could not resolve configuration for package dub_dependency_config

所以它无法弄清楚我的意思,作为一个安慰奖,我得到了一个我无法摆脱的唠叨信息;)

勇往直前!

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
    subConfiguration "sdlang-d" "sdlang-hax"
}
configuration "sdlang-hax" {
    buildOptions "debugMode"
}

输出:

C:\dprojects\dub_dependency_config>dub build --build=release-debug

## Warning for package dub_dependency_config, configuration sdlang-hax ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

debugMode: Call DUB with --build=debug

Performing "release-debug" build using dmd for x86_64.
dub_dependency_config ~master: target for configuration "sdlang-hax" is up to date.

C:\dprojects\dub_dependency_config>bin\app.exe
'bin\app.exe' is not recognized as an internal or external command,
operable program or batch file.

这很有意思,我们可以建立......某些东西(我不知道是什么,但这不是我的程序)。

更多组合!我们来吧!

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
    subConfiguration "sdlang-d" "sdlang-hax"
    configuration "sdlang-hax" {
        buildOptions "debugMode"
    }
}

输出:

C:\dprojects\dub_dependency_config>dub build --build=release-debug
Could not resolve configuration for package dub_dependency_config

唠叨走了!但我认为这只意味着我更加努力。

为了学习,我尝试了一些我知道不会起作用的东西,因为我希望从subConfiguration标签中获得任何吱吱声的信息:

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
}
subConfiguration "sdlang-d" "application"

不,我的错误尝试有错误的结果:

C:\dprojects\dub_dependency_config>dub build --build=release-debug
Could not resolve configuration for package dub_dependency_config

如何让它发挥作用?

(顺便说一下:我非常感谢.sdl格式。我在.json版本中遇到了同样的问题,只是缺乏评论能力使得这个问题难以解决,更不用说文档。)

1 个答案:

答案 0 :(得分:0)

我认为您需要引用依赖项本身中可用的配置。 Dub doco并不清楚,之前我犯过类似的错误。对于sdlang-d,似乎包dub.sdl

中有四种配置
  • cli
  • 文库
  • 单元测试-内置
  • 单元测试

这些是os.system块中可供选择的选项。我不认为你可以像你正在做的那样在dub.sdl包中声明它们。在您的第一个输出块中,它显示sdlang-d正在构建subConfiguration配置。