Fixed bug 3262 - Premake scripts are not compatible with "Genie" (premake fork)
authorSam Lantinga
Sat, 01 Oct 2016 12:56:28 -0700
changeset 1042234fb2e531f7c
parent 10421 55fd4e519a58
child 10423 c5b42350ccbb
Fixed bug 3262 - Premake scripts are not compatible with "Genie" (premake fork)

jfverdon

Genie (https://github.com/bkaradzic/genie) is a well known premake fork which uses internally Lua 5.3 (as opposed to version 5.1 used in premake4).
As there is some Lua's API breaks in Lua 5.2, SDL premake scripts do not works with premake.

The two incompatibilities I noticed were:
* unhandle modes "rt" and "wt" for io.open. Has io.open opens files in text mode by default, the "t" flag is not needed (this flag is not supported in Genie).
* os.execute signature change, the return value is a tuple from Lua 5.2, before it was just the called program exit code.
premake/premake4.lua
premake/util/sdl_check_compile.lua
premake/util/sdl_gen_config.lua
     1.1 --- a/premake/premake4.lua	Sat Oct 01 12:54:48 2016 -0700
     1.2 +++ b/premake/premake4.lua	Sat Oct 01 12:56:28 2016 -0700
     1.3 @@ -121,7 +121,7 @@
     1.4  	end
     1.5  
     1.6  	local genFile = baseLoc .. "/SDL-gen.lua"
     1.7 -	local file = fileopen(genFile, "wt")
     1.8 +	local file = fileopen(genFile, "w")
     1.9  	print("Generating " .. genFile .. "...")
    1.10  	-- begin generating the config header file
    1.11  	startGeneration(premakeConfigHeader, premakeTemplateHeader)
     2.1 --- a/premake/util/sdl_check_compile.lua	Sat Oct 01 12:54:48 2016 -0700
     2.2 +++ b/premake/util/sdl_check_compile.lua	Sat Oct 01 12:56:28 2016 -0700
     2.3 @@ -101,6 +101,18 @@
     2.4  	os.remove("./premakecheck.stdout")
     2.5  end
     2.6  
     2.7 +local function os_execute(cmd)
     2.8 +	if _ENV then
     2.9 +		-- Lua 5.2 or greater
    2.10 +		local cmdSuccess, textStatus, returnCode = os.execute(cmd)
    2.11 +		return returnCode
    2.12 +	else
    2.13 +		-- Lua 5.1 or lesser
    2.14 +		local returnCode = os.execute(cmd)
    2.15 +		return returnCode
    2.16 +	end
    2.17 +end
    2.18 +
    2.19  -- Check if a source builds, links, and or/runs, where running depends on
    2.20  -- linking and linking depends on building. The return from this function is
    2.21  -- a triple, where the first is a boolean value indicating if it successfully
    2.22 @@ -108,10 +120,10 @@
    2.23  -- linked, and the third represents nil if it was not run or run correctly, or
    2.24  -- the output from the program executed (may be empty for no output).
    2.25  local function check_build_source(source, link, run)
    2.26 -	local file = fileopen("./premakecheck.c", "wt")
    2.27 +	local file = fileopen("./premakecheck.c", "w")
    2.28  	file:write(source)
    2.29  	file:close()
    2.30 -	local result = os.execute(build_compile_line())
    2.31 +	local result = os_execute(build_compile_line())
    2.32  	if not link then
    2.33  		cleanup_build()
    2.34  		if result == 0 then
    2.35 @@ -125,13 +137,13 @@
    2.36  		cleanup_build()
    2.37  		return false, false, nil -- no compile, no link, no run
    2.38  	end
    2.39 -	result = os.execute(build_link_line())
    2.40 +	result = os_execute(build_link_line())
    2.41  	if not run or result ~= 0 then -- have to link to run
    2.42  		cleanup_build()
    2.43  		return true, result == 0, nil -- compile, maybe link, no run
    2.44  	end
    2.45 -	result = os.execute(build_run_line())
    2.46 -	local output = readfile("./premakecheck.stdout", "rt")
    2.47 +	result = os_execute(build_run_line())
    2.48 +	local output = readfile("./premakecheck.stdout", "r")
    2.49  	cleanup_build()
    2.50  	return true, true, output -- compile, link, ran
    2.51  end
     3.1 --- a/premake/util/sdl_gen_config.lua	Sat Oct 01 12:54:48 2016 -0700
     3.2 +++ b/premake/util/sdl_gen_config.lua	Sat Oct 01 12:56:28 2016 -0700
     3.3 @@ -33,8 +33,8 @@
     3.4  -- This function begins config header generation given the name of the generated
     3.5  -- file and the name of the template file to use.
     3.6  function startGeneration(file, template)
     3.7 -	configFile = fileopen(file, "wt")
     3.8 -	templateFileContents = readfile(template, "rt")
     3.9 +	configFile = fileopen(file, "w")
    3.10 +	templateFileContents = readfile(template, "r")
    3.11  	insertLocation = templateFileContents:find(searchKey)
    3.12  	if insertLocation then
    3.13  		configFile:write(templateFileContents:sub(1, insertLocation - 1))