mirror of
https://github.com/xenia-project/build-tools.git
synced 2026-01-31 01:25:25 +01:00
Initial build_tools.
This commit is contained in:
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[submodule "third_party/catch"]
|
||||
path = third_party/catch
|
||||
url = https://github.com/philsquared/Catch.git
|
||||
[submodule "third_party/premake-core"]
|
||||
path = third_party/premake-core
|
||||
url = https://github.com/premake/premake-core.git
|
||||
[submodule "third_party/gflags"]
|
||||
path = third_party/gflags
|
||||
url = https://github.com/benvanik/gflags.git
|
||||
42
LICENSE
42
LICENSE
@@ -1,28 +1,24 @@
|
||||
Copyright (c) 2015,
|
||||
Copyright (c) 2015, Ben Vanik.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the project nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of build-tools nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL BEN VANIK BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
4
premake5.lua
Normal file
4
premake5.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
include("scripts/build_paths.lua")
|
||||
include("scripts/force_compile_as_cc.lua")
|
||||
include("scripts/platform_files.lua")
|
||||
include("scripts/test_suite.lua")
|
||||
10
scripts/build_paths.lua
Normal file
10
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 = "build_tools"
|
||||
build_scripts = build_tools .. "/scripts"
|
||||
build_tools_src = build_tools .. "/src"
|
||||
|
||||
platform_suffix = "win"
|
||||
28
scripts/force_compile_as_cc.lua
Normal file
28
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
|
||||
33
scripts/platform_files.lua
Normal file
33
scripts/platform_files.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
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",
|
||||
})
|
||||
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
scripts/test_suite.lua
Normal file
75
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
scripts/util.lua
Normal file
50
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
|
||||
53
src/test_suite_main.cc
Normal file
53
src/test_suite_main.cc
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include <codecvt>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "third_party/catch/include/catch.hpp"
|
||||
|
||||
namespace xe {
|
||||
bool has_console_attached() { return true; }
|
||||
} // namespace xe
|
||||
|
||||
// Used in console mode apps; automatically picked based on subsystem.
|
||||
int main(int argc, wchar_t* argv[]) {
|
||||
google::SetUsageMessage(std::string("usage: ..."));
|
||||
google::SetVersionString("1.0");
|
||||
|
||||
// Convert all args to narrow, as gflags doesn't support wchar.
|
||||
int argca = argc;
|
||||
char** argva = (char**)alloca(sizeof(char*) * argca);
|
||||
for (int n = 0; n < argca; n++) {
|
||||
size_t len = wcslen(argv[n]);
|
||||
argva[n] = (char*)alloca(len + 1);
|
||||
wcstombs_s(nullptr, argva[n], len + 1, argv[n], _TRUNCATE);
|
||||
}
|
||||
|
||||
// Parse flags; this may delete some of them.
|
||||
google::ParseCommandLineFlags(&argc, &argva, true);
|
||||
|
||||
#if _WIN32
|
||||
// Setup COM on the main thread.
|
||||
// NOTE: this may fail if COM has already been initialized - that's OK.
|
||||
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
#endif // _WIN32
|
||||
|
||||
// Run Catch.
|
||||
int result = Catch::Session().run(argc, argva);
|
||||
|
||||
google::ShutDownCommandLineFlags();
|
||||
return result;
|
||||
}
|
||||
1
third_party/catch
vendored
Submodule
1
third_party/catch
vendored
Submodule
Submodule third_party/catch added at 1dd0d4c61a
1
third_party/gflags
vendored
Submodule
1
third_party/gflags
vendored
Submodule
Submodule third_party/gflags added at 78b15171a7
31
third_party/gflags.lua
vendored
Normal file
31
third_party/gflags.lua
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
group("third_party")
|
||||
project("gflags")
|
||||
uuid("e319da87-75ed-4517-8f65-bd25e9cc02a3")
|
||||
kind("StaticLib")
|
||||
language("C++")
|
||||
links({
|
||||
})
|
||||
defines({
|
||||
"PATH_SEPARATOR=%%27\\\\%%27",
|
||||
"GFLAGS_DLL_DECL=",
|
||||
"GFLAGS_DLL_DEFINE_FLAG=",
|
||||
"GFLAGS_DLL_DECLARE_FLAG=",
|
||||
"_LIB",
|
||||
})
|
||||
includedirs({
|
||||
"gflags/src/windows",
|
||||
"gflags/src",
|
||||
})
|
||||
files({
|
||||
"gflags/src/gflags.cc",
|
||||
"gflags/src/gflags_completions.cc",
|
||||
"gflags/src/gflags_reporting.cc",
|
||||
"gflags/src/mutex.h",
|
||||
"gflags/src/util.h",
|
||||
"gflags/src/windows/config.h",
|
||||
"gflags/src/windows/gflags/gflags.h",
|
||||
"gflags/src/windows/gflags/gflags_completions.h",
|
||||
"gflags/src/windows/gflags/gflags_declare.h",
|
||||
"gflags/src/windows/port.cc",
|
||||
"gflags/src/windows/port.h",
|
||||
})
|
||||
1
third_party/premake-core
vendored
Submodule
1
third_party/premake-core
vendored
Submodule
Submodule third_party/premake-core added at 5566d7dd60
Reference in New Issue
Block a user