diff --git a/premake5.lua b/premake5.lua index 2789a979..5c70e963 100644 --- a/premake5.lua +++ b/premake5.lua @@ -33,8 +33,20 @@ newaction { local revNumber = assert(proc:read('*a')):gsub("%s+", "") proc:close() + -- get whether this is a clean revision (no uncommitted changes) + local proc = assert(io.popen("git status --porcelain", "r")) + local revClean = 1 + local revCleanSuffix = "" + if assert(proc:read('*a')) ~= "" then + revClean = 0 + revCleanSuffix = " (unclean)" + end + proc:close() + -- get old version number from version.hpp if any local oldRevNumber = "(none)" + local oldRevClean = 1 + local oldRevCleanSuffix = "" local oldVersionHeader = io.open(wks.location .. "/src/version.hpp", "r") if oldVersionHeader ~=nil then local oldVersionHeaderContent = assert(oldVersionHeader:read('*a')) @@ -43,11 +55,23 @@ newaction { -- old version.hpp format? oldRevNumber = "(none)" end + oldRevClean = string.match(oldVersionHeaderContent, "#define REVISION_CLEAN (%d+)") + if oldRevClean == nil then + -- old version.hpp format? + oldRevClean = 1 + elseif oldRevClean ~= "1" then + oldRevClean = 0 + else + oldRevClean = 1 + end + end + if oldRevClean == 0 then + oldRevCleanSuffix = " (unclean)" end -- generate version.hpp with a revision number if not equal - if oldRevNumber ~= revNumber then - print ("Update " .. oldRevNumber .. " -> " .. revNumber) + if oldRevNumber ~= revNumber or oldRevClean ~= revClean then + print ("Update " .. oldRevNumber .. oldRevCleanSuffix .. " -> " .. revNumber .. revCleanSuffix) local versionHeader = assert(io.open(wks.location .. "/src/version.hpp", "w")) versionHeader:write("/*\n") versionHeader:write(" * Automatically generated by premake5.\n") @@ -55,6 +79,7 @@ newaction { versionHeader:write(" */\n") versionHeader:write("\n") versionHeader:write("#define REVISION " .. revNumber .. "\n") + versionHeader:write("#define REVISION_CLEAN " .. revClean .. "\n") versionHeader:close() end end