premake: Introduce REVISION_CLEAN. More info in this commit msg.
REVISION_CLEAN can be 0 or 1. When it is 0 that means that there were uncommitted changes to the code at the time of version info generation, otherwise this will be 1 which means that there have been no uncommitted changes.
This commit is contained in:
parent
6b65a4d521
commit
536cb2f171
29
premake5.lua
29
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
|
||||
|
Loading…
Reference in New Issue
Block a user