2017-07-31 37 views
0

假設我有一個名爲「myapp」的項目,它取決於「sdlang-d」。我想從命令行使用dub build --build=release-debug將我的項目構建爲release-debug。由於SDLang issue #54,我不能讓它構建sdlang-d作爲release-debug,所以我想用我的配音配置文件來強制sdlang-d構建爲「debug」或「debugMode」,而不管構建選項何時選擇爲「myapp」,然後將調試版本的sdlang-d鏈接到myapp的發佈版本(這樣我的代碼在sdlang-d之外就可以從優化中受益)。在DUB配置文件中,如何更改依賴項的配置(buildOptions)?

出於測試目的,我創建了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" 
} 

我沒有實驗值將其實際工作;文件中沒有說它應該。無論如何,我試過了,配音似乎忽略了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 

老馬走了!但我認爲這只是意味着我失敗了。

在學習的興趣,我嘗試的東西,我知道,因爲我希望得到任何信息的吱吱聲出來的子結構標籤將無法正常工作:

// 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版本中我遇到了同樣的問題,僅僅缺乏評論能力使得這種棘手的問題難以解決,更不用說文檔了。)

回答

0

我認爲你需要引用依賴本身中可用的配置。 Dub doco並不清楚,我之前也犯過類似的錯誤。對於sdlang-d它似乎有四種配置在封裝dub.sdl

  • CLI
  • 單元測試,內置
  • 單元測試

這些是在選擇的選項subConfiguration區塊。我不認爲你可以像你在做的那樣在你的軟件包dub.sdl中實際聲明它們。在您的第一個輸出塊中,顯示sdlang-d正在構建library配置。