Open ianhinder opened 12 years ago
I use the following piece of code to achieve this for another Mathematica package. It first checks for BUILD_ID and GIT_REVISION files (which are included in releases), and then falls back to detecting these manually.
KrancVersion[] := Module[{path, buildid, gitrev}, path = FileNameDrop[FindFile["Kranc`"], -2];
buildid = Quiet@ReadList[FileNameJoin[{path, "BUILD_ID"}], "String"]; If[SameQ[buildid, $Failed], buildid = "git"; , buildid = First[buildid]; ];
gitrev = Quiet@ReadList[FileNameJoin[{path, "GIT_REVISION"}],"String"]; If[SameQ[gitrev, $Failed], gitrev = First@ReadList["!git --git-dir "<>FileNameJoin[{path, ".git"}]<>" rev-parse HEAD", String]; , gitrev = First[gitrev]; ];
Grid[{{"Installed in:", path}, {"Build ID: ", buildid}, {"Git revision: ", gitrev}}, Alignment -> Left] ]
Kranc should output its directory and branch when it runs. This should go to the screen, and probably also to the generated thorn's README or a small source file. This may help prevent surprises if people accidentally run the wrong version.
(Requested by Erik Schnetter in https://trac.einsteintoolkit.org/ticket/698)