Prevent dub from blindly rebuilding every time

This commit is contained in:
Laurent Tréguier 2018-11-14 18:18:13 +01:00
parent df035368e2
commit 43e010d9e8
No known key found for this signature in database
GPG Key ID: 09530BFFC32D4A69
2 changed files with 24 additions and 1 deletions

View File

@ -24,6 +24,6 @@
"bin"
],
"preGenerateCommands" : [
"rdmd --eval=\"auto dir=environment.get(\\\"DUB_PACKAGE_DIR\\\"); dir.buildPath(\\\"bin\\\").mkdirRecurse; auto gitVer = (\\\"git -C \\\"~dir~\\\" describe --tags\\\").executeShell; (gitVer.status == 0 ? gitVer.output.strip : \\\"v\\\" ~ dir.dirName.baseName.findSplitAfter(environment.get(\\\"DUB_ROOT_PACKAGE\\\")~\\\"-\\\")[1]).ifThrown(\\\"0.0.0\\\").chain(newline).to!string.toFile(dir.buildPath(\\\"bin\\\", \\\"dubhash.txt\\\"));\""
"rdmd dubhash.d"
]
}

23
dubhash.d Normal file
View File

@ -0,0 +1,23 @@
import std.algorithm;
import std.ascii;
import std.conv;
import std.exception;
import std.file;
import std.path;
import std.process;
import std.range;
import std.string;
void main()
{
auto dir = environment.get("DUB_PACKAGE_DIR");
auto hashFile = dir.buildPath("bin", "dubhash.txt");
auto gitVer = executeShell("git -C " ~ dir ~ " describe --tags");
auto ver = (gitVer.status == 0 ? gitVer.output.strip
: "v" ~ dir.dirName.baseName.findSplitAfter(
environment.get("DUB_ROOT_PACKAGE") ~ "-")[1]).ifThrown("0.0.0")
.chain(newline).to!string.strip;
dir.buildPath("bin").mkdirRecurse;
if (!hashFile.exists || ver != hashFile.readText.strip)
hashFile.write(ver);
}