diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-05-08 15:00:48 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-05-13 11:08:42 +0200 |
commit | f5c95742d60f88df37e242c4066468f14c14bd05 (patch) | |
tree | e222fcffa9d32e85f37dc4df7be7e4a840cd76cc | |
parent | 000729aafb76d02981be4ddd6467afd81a92bcd2 (diff) | |
download | justbuild-f5c95742d60f88df37e242c4066468f14c14bd05.tar.gz |
rules: Support staging debug artifacts in install-with-deps rule
The existing rule is extended to also stage source files if in
debug mode, in order for a debugger to be able to find all needed
symbols. Conflicting paths are allowed; in case of conflicts, the
file from the closest target in the dependency chain wins.
-rw-r--r-- | rules/CC/EXPRESSIONS | 78 | ||||
-rw-r--r-- | rules/CC/RULES | 18 |
2 files changed, 94 insertions, 2 deletions
diff --git a/rules/CC/EXPRESSIONS b/rules/CC/EXPRESSIONS index b3ce957b..067fc0d0 100644 --- a/rules/CC/EXPRESSIONS +++ b/rules/CC/EXPRESSIONS @@ -188,6 +188,40 @@ } } } +, "debug-srcs": + { "doc": ["Collect debug dependencies (sources) from given target_fields"] + , "vars": ["deps-fieldnames", "deps-transition"] + , "vars_doc": + { "deps-fieldnames": + ["List of target_field names to collect dependencies from."] + , "deps-transition": + ["The optional configuration transition for the targets."] + } + , "imports": {"provider_list": ["./", "..", "field_provider_list"]} + , "expression": + { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "fieldname" + , "range": {"type": "var", "name": "deps-fieldnames"} + , "body": + { "type": "++" + , "$1": + { "type": "let*" + , "bindings": + [ ["provider", "debug-srcs"] + , ["transition", {"type": "var", "name": "deps-transition"}] + , ["default", {"type": "empty_map"}] + ] + , "body": [{"type": "CALL_EXPRESSION", "name": "provider_list"}] + } + } + } + } + } + } , "compile-deps": { "doc": ["Collect compile dependencies (headers) from given target_fields"] , "vars": ["deps-fieldnames", "deps-transition"] @@ -1025,6 +1059,7 @@ , "ADD_CXXFLAGS" , "AR" , "ENV" + , "DEBUG" , "name" , "pure C" , "srcs" @@ -1047,6 +1082,7 @@ , "cflags-files-deps": "cflags-files-deps" , "ldflags-files-deps": "ldflags-files-deps" , "lib artifact": "lib artifact" + , "debug-srcs": "debug-srcs" } , "expression": { "type": "let*" @@ -1085,6 +1121,19 @@ , [ "ldflags-files" , {"type": "CALL_EXPRESSION", "name": "ldflags-files-deps"} ] + , [ "debug-srcs" + , { "type": "if" + , "cond": {"type": "var", "name": "DEBUG"} + , "then": + { "type": "map_union" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "debug-srcs"} + , {"type": "var", "name": "srcs"} + ] + } + , "else": {"type": "empty_map"} + } + ] , ["deps-fieldnames", {"type": "var", "name": "public-fieldnames"}] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , [ "compile-args" @@ -1123,6 +1172,7 @@ , "link-deps" , "link-args" , "package" + , "debug-srcs" ] } , { "type": "var" @@ -1304,6 +1354,7 @@ , "ADD_CFLAGS" , "ADD_CXXFLAGS" , "ENV" + , "DEBUG" , "name" , "pure C" , "srcs" @@ -1321,6 +1372,7 @@ , "cflags-files-deps": "cflags-files-deps" , "ldflags-files-deps": "ldflags-files-deps" , "binary": "bin artifact" + , "debug-srcs": "debug-srcs" } , "expression": { "type": "let*" @@ -1354,11 +1406,24 @@ , {"type": "CALL_EXPRESSION", "name": "ldflags-files-deps"} ] , ["package", {"type": "singleton_map", "key": "to_bin", "value": true}] + , [ "debug-srcs" + , { "type": "if" + , "cond": {"type": "var", "name": "DEBUG"} + , "then": + { "type": "map_union" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "debug-srcs"} + , {"type": "var", "name": "srcs"} + ] + } + , "else": {"type": "empty_map"} + } + ] ] , "body": { "type": "RESULT" , "artifacts": {"type": "CALL_EXPRESSION", "name": "binary"} - , "provides": {"type": "env", "vars": ["package"]} + , "provides": {"type": "env", "vars": ["package", "debug-srcs"]} } } } @@ -1400,6 +1465,13 @@ ] } ] + , [ "debug-srcs" + , { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "debug-srcs" + , "default": {"type": "empty_map"} + } + ] ] , "body": { "type": "if" @@ -1554,6 +1626,10 @@ , "subdir": {"type": "var", "name": "pc-install-dir"} , "$1": {"type": "var", "name": "pkg-config"} } + , { "type": "to_subdir" + , "subdir": "debug-src" + , "$1": {"type": "var", "name": "debug-srcs"} + } ] } } diff --git a/rules/CC/RULES b/rules/CC/RULES index a5202cf3..a2ced03d 100644 --- a/rules/CC/RULES +++ b/rules/CC/RULES @@ -350,6 +350,7 @@ , "ADD_CXXFLAGS" , "AR" , "ENV" + , "DEBUG" ] , "implicit": {"defaults": ["defaults"]} , "field_doc": @@ -443,6 +444,7 @@ , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." ] , "ENV": ["The environment for any action generated."] + , "DEBUG": ["Compute the debug-stage, needed for local debugging."] } , "artifacts_doc": ["The actual library (libname.a) staged in the specified directory"] @@ -460,6 +462,7 @@ [ "List of strings that have to be added to the command line for linking actions" , "in targets depending on this library" ] + , "debug-srcs": ["Map of all dependencies' sources needed for debugging."] } , "anonymous": { "proto-deps": @@ -569,7 +572,15 @@ , "private-ldflags" ] , "config_vars": - ["CC", "CXX", "CFLAGS", "CXXFLAGS", "ADD_CFLAGS", "ADD_CXXFLAGS", "ENV"] + [ "CC" + , "CXX" + , "CFLAGS" + , "CXXFLAGS" + , "ADD_CFLAGS" + , "ADD_CXXFLAGS" + , "ENV" + , "DEBUG" + ] , "implicit": {"defaults": ["defaults"]} , "field_doc": { "name": ["The name of the binary"] @@ -626,9 +637,12 @@ , "taken from the [\"CC\", \"defaults\"] target" ] , "ENV": ["The environment for any action generated."] + , "DEBUG": ["Compute the debug-stage, needed for local debugging."] } , "artifacts_doc": ["The final binary, staged to the given directory"] , "runfiles_doc": ["None"] + , "provides_doc": + {"debug-srcs": ["Map of all dependencies' sources needed for debugging."]} , "anonymous": { "private-proto-deps": { "target": "private-proto" @@ -704,6 +718,8 @@ , "the target, artifacts and dependencies will be installed to" , "subdirectories \"bin\", \"include\", and \"lib\". For library targets," , "a pkg-config file is generated and provided in \"lib/pkgconfig\"." + , "In debug mode, sources needed for local debugging will be installed to" + , "subdirectory \"debug-src\"." ] , "config_vars": ["PREFIX"] , "target_fields": ["targets"] |