git_version.lua (501B)
1 local function exec( cmd ) 2 local pipe = assert( io.popen( cmd ) ) 3 local res = pipe:read( "*line" ) 4 pipe:close() 5 return res or "" 6 end 7 8 local version = exec( "git rev-parse --short HEAD" ) 9 local gitversion = "#define APP_VERSION \"" .. version .. "\"\n" 10 11 local r = io.open( "src/gitversion.h", "r" ) 12 local current = r and r:read( "*all" ) 13 if r then 14 r:close() 15 end 16 17 if current ~= gitversion then 18 local w = assert( io.open( "src/gitversion.h", "w" ) ) 19 w:write( gitversion ) 20 assert( w:close() ) 21 end