【问题标题】:In a DUB config file, how do I change the configuration (buildOptions) of a dependency?在 DUB 配置文件中,如何更改依赖项的配置(buildOptions)?
【发布时间】:2017-07-31 23:01:38
【问题描述】:

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

出于测试目的,我在 github 上创建了一个名为 "dub_dependency_config" 的项目来模拟这种情况。在下面的文字中,我将提供我从尝试过的事情中观察到的具体输出,因此我将参考“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"
}

我没想到这会真正起作用;文档中没有任何内容说它应该。无论如何我都试过了,dub 似乎忽略了dependency 标签中的buildOptions 标签。配置文件与之前的配置文件相同,我得到相同的问题 #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 版本中遇到了同样的问题,只是缺少评论能力就很难解决,更不用说文档了。)

【问题讨论】:

    标签: d dub


    【解决方案1】:

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

    • cli
    • 图书馆
    • 内置单元测试
    • 单元测试

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 2018-10-13
      • 2020-01-27
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      相关资源
      最近更新 更多