Created
May 21, 2011 00:42
-
-
Save tyuki39/984081 to your computer and use it in GitHub Desktop.
Gradleにおけるインクリメンタルビルドの実現例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
例えば次のような構成に対して実行すると、R.csv、A/A.csv、A/B/B.csvができます。 | |
サンプルでは特別な変換処理はしていないので、R.dat、A.dat、B.datは空でも構いません。 | |
A/A.datの内容を変更した場合に、A/A.csvを変更する処理だけが走ることを確認します。 | |
| build.gradle | |
| Rakefile | |
| R.dat | |
| | |
\---A | |
| A.dat | |
| | |
\---B | |
B.dat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 全ての .csv ができている場合は OK とだけ出力 | |
// .dat の状態と .csv の状態が前回実行した時の状態から変わっていない | |
// 場合は、.dat から .csv への変換をスキップ | |
// このとき、.dat と .csv のペアごとにスキップするかどうかを判断 | |
// | |
// 注意: makeやrakeとはスキップするかどうかの判断基準が違うので要注意 | |
defaultTasks 'sample' | |
task sample { | |
srcFiles = fileTree(dir: '.').matching { include '**/*.dat' } | |
srcFiles.eachWithIndex { srcFile, index -> | |
// .dat から .csv への変換用タスク | |
task "dat$index" { | |
destFile = file(srcFile.canonicalPath.replaceFirst(/dat$/, "csv")) | |
inputs.file srcFile | |
outputs.file destFile | |
outputs.upToDateWhen( { it.outputs.files.every { it.exists() } } ) | |
doLast { | |
destFile.write("test") | |
} | |
} | |
// sampleタスク と 変換用ルールの依存関係を確立 | |
dependsOn "dat$index" | |
} | |
doLast { | |
println "OK" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 全ての .csv ができている場合は OK とだけ出力 | |
# .dat に対応する .csv がないか、.dat よりも .csv が新しい場合に | |
# .dat から .csv への変換をスキップ | |
# このとき、.dat と .csv のペアごとにスキップするかどうかを判断 | |
# | |
# build.gradleとの比較用サンプル | |
task :default => :sample | |
INPUTS = FileList["**/*.dat"] | |
OUTPUTS = INPUTS.ext('.csv') | |
desc "sampleタスク と 変換用ルールの依存関係を確立" | |
task :sample => OUTPUTS do | |
print "OK" | |
end | |
desc ".dat から .csv への変換用ルール" | |
rule ".csv" => ".dat" do |target| | |
sh "echo \"test\" > \"#{target.name}\"" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment