From 4752073b984845a407b45855d42f4d4733b49efd Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 11 Jun 2024 13:11:49 +0200 Subject: foreign rules: fix computation of absolute paths When setting CC, etc, in foreign rules, it is often useful to have it set as absolute path. This originally was achieved using realpath(1). This, however, implies that symbolic links are followed as well, which confuses some compilers if they are not called with correct argv[0]. Therefore, 4e86f756bddca8db402502be47c0825e1e2aeb0d tries to replace this by concatenation with $(pwd), which, however, is only correct for tools brought locally by the toolchain. Hence fix the test by not evaluating it in the shell at all and rather using the knowledge about toolchain versus system tools that the rules have anyway. --- CC/foreign/cmake/EXPRESSIONS | 59 ++++++++++++++++++++++++++++++++++++++++---- CC/foreign/make/EXPRESSIONS | 40 +++++++++++++++++++++++++++--- CC/foreign/shell/EXPRESSIONS | 50 +++++++++++++++++++++++++++++++++---- 3 files changed, 135 insertions(+), 14 deletions(-) diff --git a/CC/foreign/cmake/EXPRESSIONS b/CC/foreign/cmake/EXPRESSIONS index ee7c595..bf2385e 100644 --- a/CC/foreign/cmake/EXPRESSIONS +++ b/CC/foreign/cmake/EXPRESSIONS @@ -310,11 +310,60 @@ , "export TMPDIR=\"$(pwd)/scratch\"" , "export TOOLCHAIN=\"$(pwd)/toolchain\"" , "export LOCALBASE=\"$(pwd)/localbase\"" - , "export CC=$([ -x \"${CC}\" ] && echo $(pwd)/${CC} || echo ${CC})" - , "export CXX=$([ -x \"${CXX}\" ] && echo $(pwd)/${CXX} || echo ${CXX})" - , "export AR=$([ -x \"${AR}\" ] && echo $(pwd)/${AR} || echo ${AR})" - , "export MAKE=$([ -x \"${MAKE}\" ] && echo $(pwd)/${MAKE} || echo ${MAKE})" - , "export CMAKE=$([ -x \"${CMAKE}\" ] && echo $(pwd)/${CMAKE} || echo ${CMAKE})" + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CC" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CC=$(pwd)/${CC}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CXX" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CXX=$(pwd)/${CXX}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "AR" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export AR=$(pwd)/${AR}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "MAKE" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export MAKE=$(pwd)/${MAKE}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CMAKE" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CMAKE=$(pwd)/${CMAKE}" + , "else": "" + } + , { "type": "join" + , "$1": + [ "export PATH=\"$(./expand_exec TOOLCHAIN -- echo " + , { "type": "join_cmd" + , "$1": [{"type": "var", "name": "PATH"}] + } + , ")${PATH:+:}${PATH}\"" + ] + } , { "type": "join" , "$1": [ "export PATH=\"$(./expand_exec TOOLCHAIN -- echo " diff --git a/CC/foreign/make/EXPRESSIONS b/CC/foreign/make/EXPRESSIONS index 5f80fd8..bff8205 100644 --- a/CC/foreign/make/EXPRESSIONS +++ b/CC/foreign/make/EXPRESSIONS @@ -288,10 +288,42 @@ , "export DESTDIR=\"$(pwd)/install\"" , "export TOOLCHAIN=\"$(pwd)/toolchain\"" , "export LOCALBASE=\"$(pwd)/localbase\"" - , "export CC=$([ -x \"${CC}\" ] && echo $(pwd)/${CC} || echo ${CC})" - , "export CXX=$([ -x \"${CXX}\" ] && echo $(pwd)/${CXX} || echo ${CXX})" - , "export AR=$([ -x \"${AR}\" ] && echo $(pwd)/${AR} || echo ${AR})" - , "export MAKE=$([ -x \"${MAKE}\" ] && echo $(pwd)/${MAKE} || echo ${MAKE})" + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CC" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CC=$(pwd)/${CC}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CXX" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CXX=$(pwd)/${CXX}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "AR" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export AR=$(pwd)/${AR}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "MAKE" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export MAKE=$(pwd)/${MAKE}" + , "else": "" + } , { "type": "join" , "$1": [ "export PATH=\"$(./expand_exec TOOLCHAIN -- echo " diff --git a/CC/foreign/shell/EXPRESSIONS b/CC/foreign/shell/EXPRESSIONS index 572835c..bf0ecdb 100644 --- a/CC/foreign/shell/EXPRESSIONS +++ b/CC/foreign/shell/EXPRESSIONS @@ -240,11 +240,51 @@ , "export TOOLCHAIN=\"$(pwd)/toolchain\"" , "export LOCALBASE=\"$(pwd)/localbase\"" , "export DESTDIR=\"$(pwd)/install\"" - , "export CC=$([ -x \"${CC}\" ] && echo $(pwd)/${CC} || echo ${CC})" - , "export CXX=$([ -x \"${CXX}\" ] && echo $(pwd)/${CXX} || echo ${CXX})" - , "export AR=$([ -x \"${AR}\" ] && echo $(pwd)/${AR} || echo ${AR})" - , "export MAKE=$([ -x \"${MAKE}\" ] && echo $(pwd)/${MAKE} || echo ${MAKE})" - , "export CMAKE=$([ -x \"${CMAKE}\" ] && echo $(pwd)/${CMAKE} || echo ${CMAKE})" + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CC" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CC=$(pwd)/${CC}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CXX" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CXX=$(pwd)/${CXX}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "AR" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export AR=$(pwd)/${AR}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "MAKE" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export MAKE=$(pwd)/${MAKE}" + , "else": "" + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "CMAKE" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": "export CMAKE=$(pwd)/${CMAKE}" + , "else": "" + } , { "type": "join" , "$1": [ "export PATH=\"$(./expand_exec TOOLCHAIN -- echo " -- cgit v1.2.3 From 08d76f32e960577e0e382c5c17fa368ddc8b210d Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 11 Jun 2024 09:45:30 +0200 Subject: ["CC/foreign/shell", "data"] honor shell toolchain --- CC/foreign/shell/EXPRESSIONS | 33 +++++++++++++++++++++++++++++++-- CC/foreign/shell/RULES | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CC/foreign/shell/EXPRESSIONS b/CC/foreign/shell/EXPRESSIONS index bf0ecdb..a0a9a00 100644 --- a/CC/foreign/shell/EXPRESSIONS +++ b/CC/foreign/shell/EXPRESSIONS @@ -38,17 +38,38 @@ , "foreign-PATH": ["CC/foreign", "default-PATH"] , "foreign-TOOLCHAIN": ["CC/foreign", "default-TOOLCHAIN"] , "foreign-NON_SYSTEM_TOOLS": ["CC/foreign", "default-NON_SYSTEM_TOOLS"] + , "map_provider": ["", "field_map_provider"] + , "sh": ["shell", "sh"] + , "sh-PATH": ["shell", "PATH"] + , "sh prolog": ["shell", "prolog"] } , "expression": { "type": "let*" , "bindings": [ ["TOOLCHAIN_DIR", "toolchain"] + , [ "shell TOOLCHAIN" + , { "type": "let*" + , "bindings": + [ ["fieldname", "shell defaults"] + , ["provider", "TOOLCHAIN"] + , ["default", {"type": "empty_map"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "map_provider"} + } + ] + , [ "sh" + , { "type": "let*" + , "bindings": [["fieldname", "shell defaults"]] + , "body": {"type": "CALL_EXPRESSION", "name": "sh"} + } + ] , [ "TOOLCHAIN" , { "type": "disjoint_map_union" , "msg": "Toolchain trees may not overlap" , "$1": [ {"type": "CALL_EXPRESSION", "name": "foreign-TOOLCHAIN"} , {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"} + , {"type": "var", "name": "shell TOOLCHAIN"} ] } ] @@ -181,6 +202,10 @@ , "$1": [ {"type": "CALL_EXPRESSION", "name": "foreign-PATH"} , {"type": "CALL_EXPRESSION", "name": "default-PATH"} + , { "type": "let*" + , "bindings": [["fieldname", "shell defaults"]] + , "body": {"type": "CALL_EXPRESSION", "name": "sh-PATH"} + } ] } ] @@ -232,7 +257,11 @@ , "$1": { "type": "++" , "$1": - [ [ "set -eu" + [ { "type": "let*" + , "bindings": [["fieldname", "shell defaults"]] + , "body": {"type": "CALL_EXPRESSION", "name": "sh prolog"} + } + , [ "set -eu" , "mkdir -p scratch work install" , "export ACTION_DIR=\"$(pwd)\"" , "export TMPDIR=\"$(pwd)/scratch\"" @@ -323,7 +352,7 @@ , {"type": "var", "name": "expand_exec"} ] } - , "cmd": ["sh", "run_cmds.sh"] + , "cmd": [{"type": "var", "name": "sh"}, "run_cmds.sh"] , "outs": {"type": "var", "name": "installed_files"} , "out_dirs": {"type": "var", "name": "installed_dirs"} , "env": {"type": "var", "name": "ENV"} diff --git a/CC/foreign/shell/RULES b/CC/foreign/shell/RULES index 5c85955..6a5d8ec 100644 --- a/CC/foreign/shell/RULES +++ b/CC/foreign/shell/RULES @@ -29,6 +29,7 @@ , "implicit": { "defaults": [["CC", "defaults"]] , "foreign-defaults": [["CC/foreign", "defaults"]] + , "shell defaults": [["shell", "defaults"]] , "expand_exec": [["./", "..", "expand_exec"]] } , "field_doc": @@ -268,6 +269,7 @@ , "implicit": { "defaults": [["CC", "defaults"]] , "foreign-defaults": [["CC/foreign", "defaults"]] + , "shell defaults": [["shell", "defaults"]] , "config_reader": [["CC", "prebuilt/read_pkgconfig.py"]] , "expand_exec": [["./", "..", "expand_exec"]] } -- cgit v1.2.3 From 85f97ddf0e18548d95d50aa1f7599a1aad833d97 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Wed, 19 Jun 2024 10:57:52 +0200 Subject: rules-cc: Binaries should keep the compile dependency headers for debugging --- CC/EXPRESSIONS | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index f3188c0..c7ee9e0 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -1475,9 +1475,14 @@ , { "type": "if" , "cond": {"type": "var", "name": "DEBUG"} , "then": - { "type": "let*" - , "bindings": [["deps-provider", "debug-hdrs"]] - , "body": {"type": "CALL_EXPRESSION", "name": "debug-deps"} + { "type": "map_union" + , "$1": + [ { "type": "let*" + , "bindings": [["deps-provider", "debug-hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "debug-deps"} + } + , {"type": "var", "name": "compile-deps"} + ] } , "else": {"type": "empty_map"} } -- cgit v1.2.3