Folding build_tools back into the main repo for simplicity.
This commit is contained in:
10
tools/build/scripts/build_paths.lua
Normal file
10
tools/build/scripts/build_paths.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
build_root = "build"
|
||||
build_bin = build_root .. "/bin/%{cfg.platform}/%{cfg.buildcfg}"
|
||||
build_gen = build_root .. "/gen/%{cfg.platform}/%{cfg.buildcfg}"
|
||||
build_obj = build_root .. "/obj/%{cfg.platform}/%{cfg.buildcfg}"
|
||||
|
||||
build_tools = "tools/build"
|
||||
build_scripts = build_tools .. "/scripts"
|
||||
build_tools_src = build_tools .. "/src"
|
||||
|
||||
platform_suffix = "win"
|
||||
28
tools/build/scripts/force_compile_as_c.lua
Normal file
28
tools/build/scripts/force_compile_as_c.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
if premake.override then
|
||||
local forced_c_files = {}
|
||||
|
||||
-- Forces all of the given .c and .cc files to be compiled as if they were C.
|
||||
function force_compile_as_c(files)
|
||||
for _, val in ipairs(files) do
|
||||
for _, fname in ipairs(os.matchfiles(val)) do
|
||||
table.insert(forced_c_files, path.getabsolute(fname))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- for gmake
|
||||
premake.override(path, "iscfile", function(base, fname)
|
||||
if table.contains(forced_c_files, fname) then
|
||||
return true
|
||||
else
|
||||
return base(fname)
|
||||
end
|
||||
end)
|
||||
-- for msvc
|
||||
premake.override(premake.vstudio.vc2010, "additionalCompileOptions", function(base, cfg, condition)
|
||||
if cfg.abspath and table.contains(forced_c_files, cfg.abspath) then
|
||||
_p(3,'<CompileAs %s>CompileAsC</CompileAs>', condition)
|
||||
end
|
||||
return base(cfg, condition)
|
||||
end)
|
||||
end
|
||||
28
tools/build/scripts/force_compile_as_cc.lua
Normal file
28
tools/build/scripts/force_compile_as_cc.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
if premake.override then
|
||||
local forced_cc_files = {}
|
||||
|
||||
-- Forces all of the given .c files to be compiled as if they were C++.
|
||||
function force_compile_as_cc(files)
|
||||
for _, val in ipairs(files) do
|
||||
for _, fname in ipairs(os.matchfiles(val)) do
|
||||
table.insert(forced_cc_files, path.getabsolute(fname))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- for gmake
|
||||
premake.override(path, "iscfile", function(base, fname)
|
||||
if table.contains(forced_cc_files, fname) then
|
||||
return false
|
||||
else
|
||||
return base(fname)
|
||||
end
|
||||
end)
|
||||
-- for msvc
|
||||
premake.override(premake.vstudio.vc2010, "additionalCompileOptions", function(base, cfg, condition)
|
||||
if cfg.abspath and table.contains(forced_cc_files, cfg.abspath) then
|
||||
_p(3,'<CompileAs %s>CompileAsCpp</CompileAs>', condition)
|
||||
end
|
||||
return base(cfg, condition)
|
||||
end)
|
||||
end
|
||||
41
tools/build/scripts/platform_files.lua
Normal file
41
tools/build/scripts/platform_files.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
include("build_paths.lua")
|
||||
include("util.lua")
|
||||
|
||||
local function match_platform_files(base_path, base_match)
|
||||
files({
|
||||
base_path.."/"..base_match..".h",
|
||||
base_path.."/"..base_match..".c",
|
||||
base_path.."/"..base_match..".cc",
|
||||
})
|
||||
removefiles({base_path.."/".."**_main.cc"})
|
||||
removefiles({base_path.."/".."**_test.cc"})
|
||||
removefiles({base_path.."/".."**_posix.h", base_path.."/".."**_posix.cc"})
|
||||
removefiles({base_path.."/".."**_linux.h", base_path.."/".."**_linux.cc"})
|
||||
removefiles({base_path.."/".."**_mac.h", base_path.."/".."**_mac.cc"})
|
||||
removefiles({base_path.."/".."**_win.h", base_path.."/".."**_win.cc"})
|
||||
filter("platforms:Windows")
|
||||
files({
|
||||
base_path.."/"..base_match.."_win.h",
|
||||
base_path.."/"..base_match.."_win.cc",
|
||||
})
|
||||
filter("platforms:Linux")
|
||||
files({
|
||||
base_path.."/"..base_match.."_posix.h",
|
||||
base_path.."/"..base_match.."_posix.cc",
|
||||
base_path.."/"..base_match.."_linux.h",
|
||||
base_path.."/"..base_match.."_linux.cc",
|
||||
})
|
||||
filter({})
|
||||
end
|
||||
|
||||
-- Adds all .h and .cc files in the current path that match the current platform
|
||||
-- suffix (_win, etc).
|
||||
function local_platform_files(base_path)
|
||||
match_platform_files(base_path or ".", "*")
|
||||
end
|
||||
|
||||
-- Adds all .h and .cc files in the current path and all subpaths that match
|
||||
-- the current platform suffix (_win, etc).
|
||||
function recursive_platform_files(base_path)
|
||||
match_platform_files(base_path or ".", "**")
|
||||
end
|
||||
75
tools/build/scripts/test_suite.lua
Normal file
75
tools/build/scripts/test_suite.lua
Normal file
@@ -0,0 +1,75 @@
|
||||
include("build_paths.lua")
|
||||
include("util.lua")
|
||||
|
||||
newoption({
|
||||
trigger = "test-suite-mode",
|
||||
description = "Whether to merge all tests in a test_suite into a single project",
|
||||
value = "MODE",
|
||||
allowed = {
|
||||
{ "individual", "One binary per test." },
|
||||
{ "combined", "One binary per test suite (default)." },
|
||||
},
|
||||
})
|
||||
|
||||
local function combined_test_suite(test_suite_name, project_root, base_path, config)
|
||||
group("tests")
|
||||
project(test_suite_name)
|
||||
kind("ConsoleApp")
|
||||
language("C++")
|
||||
includedirs(merge_arrays(config["includedirs"], {
|
||||
project_root.."/"..build_tools,
|
||||
project_root.."/"..build_tools_src,
|
||||
project_root.."/"..build_tools.."/third_party/catch/include",
|
||||
}))
|
||||
libdirs(merge_arrays(config["libdirs"], {
|
||||
project_root.."/"..build_bin,
|
||||
}))
|
||||
links(merge_arrays(config["links"], {
|
||||
"gflags",
|
||||
}))
|
||||
files({
|
||||
project_root.."/"..build_tools_src.."/test_suite_main.cc",
|
||||
base_path.."/**_test.cc",
|
||||
})
|
||||
end
|
||||
|
||||
local function split_test_suite(test_suite_name, project_root, base_path, config)
|
||||
local test_paths = os.matchfiles(base_path.."/**_test.cc")
|
||||
for _, file_path in pairs(test_paths) do
|
||||
local test_name = file_path:match("(.*).cc")
|
||||
group("tests/"..test_suite_name)
|
||||
project(test_suite_name.."-"..test_name)
|
||||
kind("ConsoleApp")
|
||||
language("C++")
|
||||
includedirs(merge_arrays(config["includedirs"], {
|
||||
project_root.."/"..build_tools,
|
||||
project_root.."/"..build_tools_src,
|
||||
project_root.."/"..build_tools.."/third_party/catch/include",
|
||||
}))
|
||||
libdirs(merge_arrays(config["libdirs"], {
|
||||
project_root.."/"..build_bin,
|
||||
}))
|
||||
links(merge_arrays(config["links"], {
|
||||
"gflags",
|
||||
}))
|
||||
files({
|
||||
project_root.."/"..build_tools_src.."/test_suite_main.cc",
|
||||
file_path,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Defines a test suite binary.
|
||||
-- Can either be a single binary with all tests or one binary per test based on
|
||||
-- the --test-suite-mode= option.
|
||||
function test_suite(
|
||||
test_suite_name, -- Project or group name for the entire suite.
|
||||
project_root, -- Project root path (with build_tools/ under it).
|
||||
base_path, -- Base source path to search for _test.cc files.
|
||||
config) -- Include/lib directories and links for binaries.
|
||||
if _OPTIONS["test-suite-mode"] == "individual" then
|
||||
split_test_suite(test_suite_name, project_root, base_path, config)
|
||||
else
|
||||
combined_test_suite(test_suite_name, project_root, base_path, config)
|
||||
end
|
||||
end
|
||||
50
tools/build/scripts/util.lua
Normal file
50
tools/build/scripts/util.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
-- Prints a table and all of its contents.
|
||||
function print_r(t)
|
||||
local print_r_cache={}
|
||||
local function sub_print_r(t, indent)
|
||||
if (print_r_cache[tostring(t)]) then
|
||||
print(indent.."*"..tostring(t))
|
||||
else
|
||||
print_r_cache[tostring(t)]=true
|
||||
if (type(t)=="table") then
|
||||
for pos,val in pairs(t) do
|
||||
if (type(val)=="table") then
|
||||
print(indent.."["..pos.."] => "..tostring(t).." {")
|
||||
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
|
||||
print(indent..string.rep(" ",string.len(pos)+6).."}")
|
||||
elseif (type(val)=="string") then
|
||||
print(indent.."["..pos..'] => "'..val..'"')
|
||||
else
|
||||
print(indent.."["..pos.."] => "..tostring(val))
|
||||
end
|
||||
end
|
||||
else
|
||||
print(indent..tostring(t))
|
||||
end
|
||||
end
|
||||
end
|
||||
if (type(t)=="table") then
|
||||
print(tostring(t).." {")
|
||||
sub_print_r(t," ")
|
||||
print("}")
|
||||
else
|
||||
sub_print_r(t," ")
|
||||
end
|
||||
print()
|
||||
end
|
||||
|
||||
-- Merges two tables and returns the resulting table.
|
||||
function merge_tables(t1, t2)
|
||||
local result = {}
|
||||
for k,v in pairs(t1 or {}) do result[k] = v end
|
||||
for k,v in pairs(t2 or {}) do result[k] = v end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Merges to arrays and returns the resulting array.
|
||||
function merge_arrays(t1, t2)
|
||||
local result = {}
|
||||
for k,v in pairs(t1 or {}) do result[#result + 1] = v end
|
||||
for k,v in pairs(t2 or {}) do result[#result + 1] = v end
|
||||
return result
|
||||
end
|
||||
Reference in New Issue
Block a user