2016-04-12 31 views
0

我有一個定義的動作生成覆蓋文件,它需要一些選項。bjam:對多個規則使用相同的動作

actions coverage { 
    echo coverage $(OPTIONS) >> $(<) 
} 

我需要一個規則來設置$(OPTIONS)變量:

rule coverage (targets * : sources * : properties *) { 
    OPTIONS on $(targets) = ... # Get from environment variables 
} 

一旦我這樣做,我可以使用規則生成覆蓋率文件:

make cov.xml : : @coverage ; 

我想要什麼是第二條規則(即以不同方式計算$(OPTIONS)變量),它使用相同的操作。這有可能沒有重複的行動本身?換句話說,是否有可能將兩個規則關聯到相同的行爲?

我要的是這樣的:

actions coverage-from-features { 
    # AVOID HAVING TO REPEAT THIS 
    echo coverage $(OPTIONS) >> $(<) 
} 
rule coverage-from-features (targets * : sources * : properties *) { 
    OPTIONS on $(targets) = ... # Get from feature values 
} 
make cov2.xml : : @coverage-from-features ; 

顯然沒有重複的動作命令本身(乾和所有)。

回答

0

您需要的關鍵方面是:您不需要使用鏡像調用規則的操作。規則可以調用任何和多個動作來完成這項工作。在你的情況下,你可以做這樣的事情:

actions coverage-action { 
    echo coverage $(OPTIONS) >> $(<) 
} 

rule coverage (targets * : sources * : properties *) { 
    OPTIONS on $(targets) = ... ; # Get from environment variables 
    coverage-action $(target) : $(sources) ; 
} 

rule coverage-from-features (targets * : sources * : properties *) { 
    OPTIONS on $(targets) = ... ; # Get from feature values 
    coverage-action $(target) : $(sources) ; 
} 

make cov.xml : : @coverage ; 
make cov2.xml : : @coverage-from-features ; 
+0

似乎不適用於我的「Boost.Build V2(里程碑12)Boost.Jam 03.1.19」。將你的代碼複製到一個空文件夾中的Jamroot文件中,'bjam; bjam cov.xml; bjam cov2.xml'。生成構建目錄但不輸出文件,顯然該操作未執行(使用-d + 2進行確認) –

相關問題