diff --git a/dub.json b/dub.json index f318888..f2a477f 100644 --- a/dub.json +++ b/dub.json @@ -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" ] } diff --git a/dubhash.d b/dubhash.d new file mode 100644 index 0000000..7f11ca5 --- /dev/null +++ b/dubhash.d @@ -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); +}