Skip to content

Commit

Permalink
Attempt to handle arguments with parameters using an eplicit list
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Feb 3, 2023
1 parent 6bdbaeb commit 1418c7c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 349 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
portage-bashrc-mv-21.0
----------------------
- Attempt to handle arguments with parameters using an eplicit list, see
https://github.com/vaeth/portage-bashrc-mv/issues/10

portage-bashrc-mv-20.7
----------------------
- Filter -flto-odr-type-merging with USE_NONGNU=1
Expand Down
44 changes: 41 additions & 3 deletions bashrc.d/10-flag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ FLAG_FILTER_GNU=(
'-frewrite-includes'
'-fsanitize=cfi*'
'-fsanitize=safe-stack'
'-mllvm'
'-mllvm*'
'-Xclang*'
'-mretpoline*'
'-polly*'
'-Wl,-z,retpolineplt'
Expand All @@ -213,6 +214,12 @@ FLAG_FILTER_CLANG_LTO_DEP=(
'-fwhole-program-vtables'
)

FLAG_ARGS_WITH_PARAMS=(
'-mllvm'
'-Xclang'
'--param'
)

FlagEval() {
case $- in
*f*) eval "$*";;
Expand All @@ -222,13 +229,40 @@ FlagEval() {
esac
}

FlagCombineParameters() {
local combine comb par combvar
combvar=$1
shift
combine=
par=
for comb
do if [ -n "$par" ]
then combine=$combine${combine:+\ }"'$par $comb'"
[ -n "$comb" ] || combine=$combine\\\'\\\'
par=
continue
fi
case " ${FLAG_ARGS_WITH_PARAMS[*]} " in
*" $comb "*)
par=$comb
continue;;
esac
combine=$combine${combine:+\ }$comb
done
[ -z "$par" ] || combine=$combine${combine:+\ }$par
eval $combvar=\$combine
}

FlagNodupAdd() {
local addres addf addvar dups
dups=$1
shift
addvar=$1
shift
eval addres=\$$addvar
FlagCombineParameters addf "$@"
eval "set -- a $addf"
shift
for addf
do case " $addres $dups " in
*[[:space:]]"$addf"[[:space:]]*)
Expand All @@ -249,7 +283,11 @@ FlagSub() {
shift
subres=
eval sublist=\$$subvar
for subf in $sublist
FlagCombineParameters sublist $sublist
FlagCombineParameters subf "$@"
eval "set -- a $subf"
shift
eval "for subf in $sublist"'
do for subpat
do [ -n "${subpat:++}" ] || continue
case $subf in
Expand All @@ -259,7 +297,7 @@ FlagSub() {
esac
done
[ -z "${subf:++}" ] || subres=$subres${subres:+\ }$subf
done
done'
eval $subvar=\$subres
}

Expand Down
6 changes: 6 additions & 0 deletions bashrc.d/README
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ SAFE
Note that this is the only command which modifies the variables
CONFIG_SITE NOLAFILEREMOVE CMAKE_MAKEFILE_GENERATOR

Some arguments take parameters: If supported by the compiler, try to use
the -arg=parameter version; otherwise, sometimes quoting may help, though
that might be tricky.
For instance, +'Xclang\ foo' will filter '-Xclang foo' but not
'-Xclang bar'

After all COMMANDs have been executed, some additional actions are taken.
You can prevent this by setting the corresponding variables to false
(either by a COMMAND or in the environment):
Expand Down
Loading

0 comments on commit 1418c7c

Please sign in to comment.