fileapi: add backtraces for compile/link options

This commit is contained in:
Justin Goshi 2019-09-03 10:25:44 -07:00 committed by Brad King
parent 291c83f063
commit 30006e199b
3 changed files with 142 additions and 11 deletions

View File

@ -802,9 +802,13 @@ void Target::ProcessLanguage(std::string const& lang)
{
// FIXME: Add flags from end section of ExpandRuleVariable,
// which may need to be factored out.
std::string flags;
lg->GetTargetCompileFlags(this->GT, this->Config, lang, flags);
cd.Flags.emplace_back(std::move(flags), JBTIndex());
std::vector<BT<std::string>> flags =
lg->GetTargetCompileFlags(this->GT, this->Config, lang);
cd.Flags.reserve(flags.size());
for (const BT<std::string>& f : flags) {
cd.Flags.emplace_back(this->ToJBT(f));
}
}
std::set<BT<std::string>> defines =
lg->GetTargetDefines(this->GT, this->Config, lang);
@ -1264,7 +1268,7 @@ Json::Value Target::DumpLinkCommandFragments()
Json::Value linkFragments = Json::arrayValue;
std::string linkLanguageFlags;
std::string linkFlags;
std::vector<BT<std::string>> linkFlags;
std::string frameworkPath;
std::string linkPath;
std::string linkLibs;
@ -1275,7 +1279,6 @@ Json::Value Target::DumpLinkCommandFragments()
linkLanguageFlags, linkFlags, frameworkPath, linkPath,
this->GT);
linkLanguageFlags = cmTrimWhitespace(linkLanguageFlags);
linkFlags = cmTrimWhitespace(linkFlags);
frameworkPath = cmTrimWhitespace(frameworkPath);
linkPath = cmTrimWhitespace(linkPath);
linkLibs = cmTrimWhitespace(linkLibs);
@ -1286,8 +1289,11 @@ Json::Value Target::DumpLinkCommandFragments()
}
if (!linkFlags.empty()) {
linkFragments.append(
this->DumpCommandFragment(std::move(linkFlags), "flags"));
for (BT<std::string> frag : linkFlags) {
frag.Value = cmTrimWhitespace(frag.Value);
linkFragments.append(
this->DumpCommandFragment(this->ToJBT(frag), "flags"));
}
}
if (!frameworkPath.empty()) {

View File

@ -232,17 +232,37 @@ def check_target(c):
assert is_string(obj["link"]["language"], expected["link"]["language"])
# FIXME: Properly test commandFragments
if "commandFragments" in obj["link"]:
link_keys.append("commandFragments")
assert is_list(obj["link"]["commandFragments"])
for f in obj["link"]["commandFragments"]:
assert is_dict(f)
assert sorted(f.keys()) == ["fragment", "role"]
assert sorted(f.keys()) == ["fragment", "role"] or sorted(f.keys()) == ["backtrace", "fragment", "role"]
assert is_string(f["fragment"])
assert is_string(f["role"])
assert f["role"] in ("flags", "libraries", "libraryPath", "frameworkPath")
if expected["link"]["commandFragments"] is not None:
def check_link_command_fragments(actual, expected):
assert is_dict(actual)
expected_keys = ["fragment", "role"]
if expected["backtrace"] is not None:
expected_keys.append("backtrace")
assert actual["fragment"] == expected["fragment"]
assert actual["role"] == expected["role"]
check_backtrace(obj, actual["backtrace"], expected["backtrace"])
assert sorted(actual.keys()) == sorted(expected_keys)
check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]),
obj["link"]["commandFragments"], expected["link"]["commandFragments"],
check=check_link_command_fragments,
check_exception=lambda a, e: "Link fragment: %s" % a["fragment"],
missing_exception=lambda e: "Link fragment: %s" % e["fragment"],
extra_exception=lambda a: "Link fragment: %s" % a["fragment"],
allow_extra=True)
if expected["link"]["lto"] is not None:
link_keys.append("lto")
assert is_bool(obj["link"]["lto"], expected["link"]["lto"])
@ -327,15 +347,33 @@ def check_target(c):
missing_exception=lambda e: "Source path: %s" % e,
extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
# FIXME: Properly test compileCommandFragments
if "compileCommandFragments" in actual:
expected_keys.append("compileCommandFragments")
assert is_list(actual["compileCommandFragments"])
for f in actual["compileCommandFragments"]:
assert is_dict(f)
assert sorted(f.keys()) == ["fragment"]
assert is_string(f["fragment"])
if expected["compileCommandFragments"] is not None:
def check_compile_command_fragments(actual, expected):
assert is_dict(actual)
expected_keys = ["fragment"]
if expected["backtrace"] is not None:
expected_keys.append("backtrace")
assert actual["fragment"] == expected["fragment"]
check_backtrace(obj, actual["backtrace"], expected["backtrace"])
assert sorted(actual.keys()) == sorted(expected_keys)
check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]),
actual["compileCommandFragments"], expected["compileCommandFragments"],
check=check_compile_command_fragments,
check_exception=lambda a, e: "Compile fragment: %s" % a["fragment"],
missing_exception=lambda e: "Compile fragment: %s" % e["fragment"],
extra_exception=lambda a: "Compile fragment: %s" % a["fragment"],
allow_extra=True)
if expected["includes"] is not None:
expected_keys.append("includes")
@ -931,6 +969,7 @@ def gen_check_targets(c, g, inSource):
"backtrace": None,
},
],
"compileCommandFragments": None,
},
],
"backtrace": [
@ -998,6 +1037,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -1064,6 +1104,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -1171,6 +1212,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -1217,6 +1259,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -1317,6 +1360,7 @@ def gen_check_targets(c, g, inSource):
"backtrace": None,
},
],
"compileCommandFragments": None,
},
],
"backtrace": [
@ -1367,6 +1411,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": True,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -1433,6 +1478,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -1479,6 +1525,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": True,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -1574,6 +1621,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -1681,6 +1729,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -1727,6 +1776,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -1979,6 +2029,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2062,6 +2113,25 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": [
{
"fragment" : "TargetCompileOptions",
"backtrace": [
{
"file": "^cxx/CMakeLists\\.txt$",
"line": 17,
"command": "target_compile_options",
"hasParent": True,
},
{
"file" : "^cxx/CMakeLists\\.txt$",
"line": None,
"command": None,
"hasParent": False,
},
],
}
],
},
],
"backtrace": [
@ -2129,6 +2199,26 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": [
{
"fragment" : "TargetLinkOptions",
"role" : "flags",
"backtrace": [
{
"file": "^cxx/CMakeLists\\.txt$",
"line": 18,
"command": "target_link_options",
"hasParent": True,
},
{
"file" : "^cxx/CMakeLists\\.txt$",
"line": None,
"command": None,
"hasParent": False,
},
],
},
],
},
"archive": None,
"dependencies": [
@ -2205,6 +2295,7 @@ def gen_check_targets(c, g, inSource):
"backtrace": None,
},
],
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2243,6 +2334,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -2297,6 +2389,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2331,6 +2424,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -2402,6 +2496,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2485,6 +2580,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2519,6 +2615,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -2743,6 +2840,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2777,6 +2875,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -2848,6 +2947,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -2882,6 +2982,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -3114,6 +3215,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3221,6 +3323,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3276,6 +3379,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -3337,6 +3441,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3444,6 +3549,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3499,6 +3605,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -3725,6 +3832,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3759,6 +3867,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -3813,6 +3922,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3847,6 +3957,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -3901,6 +4012,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -3935,6 +4047,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -3989,6 +4102,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -4023,6 +4137,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -4077,6 +4192,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -4111,6 +4227,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -4401,6 +4518,7 @@ def gen_check_targets(c, g, inSource):
],
"includes": None,
"defines": None,
"compileCommandFragments": None,
},
],
"backtrace": [
@ -4435,6 +4553,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "C",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [
@ -4748,6 +4867,7 @@ def gen_check_targets(c, g, inSource):
],
},
],
"compileCommandFragments": None,
},
{
"language": "CXX",
@ -4810,6 +4930,7 @@ def gen_check_targets(c, g, inSource):
],
},
],
"compileCommandFragments": None,
},
],
"backtrace": [
@ -4844,6 +4965,7 @@ def gen_check_targets(c, g, inSource):
"link": {
"language": "CXX",
"lto": None,
"commandFragments": None,
},
"archive": None,
"dependencies": [

View File

@ -13,3 +13,6 @@ target_link_libraries(cxx_shared_exe PRIVATE cxx_shared_lib)
add_library(cxx_static_lib STATIC ../empty.cxx)
add_executable(cxx_static_exe ../empty.cxx)
target_link_libraries(cxx_static_exe PRIVATE cxx_static_lib)
target_compile_options(cxx_exe PUBLIC TargetCompileOptions)
target_link_options(cxx_exe PUBLIC TargetLinkOptions)