Commit c7d5a8a6 authored by Kevin Daudt's avatar Kevin Daudt 💬

apkbuild-lint: add checks for overwriting CFLAGS and GOFLAGS

These should not be overwritten, but expanded instead.
parent ad92ad4d
Pipeline #7622 passed with stage
in 36 seconds
......@@ -369,3 +369,15 @@ by the apkbuild-cpan program but are now deprecated and their contents must be m
into the contents of its respective variable.
Severity: Minor, Certainty: Certain
## overwrite-xflags [AL36]
Don't overwrite `CFLAGS`, `GOFLAGS`, `CPPFLAGS`, `CXXFLAGS` and `FFLAGS`. There
flags are generally defined outside the of the APKBUILD and should not be
overwritten because they contain important flags that should not be discarded.
Instead, expand the variable. For example: `CFLAGS="$CFLAGS .."`
This list might be expanded as more variables are found that should not be
overwritten.
Severity: Serious, Certainty: Certain
......@@ -276,6 +276,15 @@ cpan_variable() {
scan '^cpancheckdepends=' 'merge the contents of cpancheckdepends into checkdepends and remove it' 'AL35' 'MC'
}
overwrite_xflags() {
[ "$SKIP_OVERWRITE_XFLAGS" ] && return 0
[ "$SKIP_AL36" ] && return 0
# shellcheck disable=SC2016
grep -oHn "$1=\".*\"" $apkbuild |
grep -vF "\$$1" |
sed "s/^\([^:]*:[^:]*:\)\(.*\)/SC:[AL36]:\1$1 should not be overwritten, add \$$1 to it/"
}
_run_apkbuild_leo() {
# Run all tests from Leo
pkgname_quoted &
......@@ -315,6 +324,11 @@ for apkbuild; do
variable_capitalized &
braced_variable &
cpan_variable &
overwrite_xflags "CFLAGS" &
overwrite_xflags "GOFLAGS" &
overwrite_xflags "CPPFLAGS" &
overwrite_xflags "CXXFLAGS" &
overwrite_xflags "FFLAGS" &
for phase in prepare build check package; do
superfluous_cd_builddir "$phase" &
......
......@@ -17,6 +17,15 @@ is_travis() {
test -n "$TRAVIS"
}
retab() {
case $(realpath "$(which unexpand)") in
*busybox*) flag="-f";;
*) flag="--first-only";;
esac
unexpand $flag -t4
}
@test 'default builddir can be removed' {
cat <<-"EOF" >$apkbuild
pkgname=a
......@@ -866,4 +875,133 @@ is_travis() {
[[ $status -eq 0 ]]
}
@test 'CFLAGS can be expanded' {
cat <<-"EOF" | retab >$apkbuild
foo() {
CFLAGS="$CFLAGS -O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'CFLAGS should not be overwritten' {
cat <<-"EOF" | retab >$apkbuild
foo() {
CFLAGS="-O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
assert_match "${lines[0]}" '\[AL36\].*:CFLAGS should not be overwritten, add \$CFLAGS to it'
}
@test 'GOFLAGS can be expanded' {
cat <<-"EOF" | retab >$apkbuild
foo() {
GOFLAGS="$GOFLAGS -O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'GOFLAGS should not be overwritten' {
cat <<-"EOF" | retab >$apkbuild
foo() {
GOFLAGS="-O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
echo "output: $output"
assert_match "${lines[0]}" '\[AL36\].*:GOFLAGS should not be overwritten, add \$GOFLAGS to it'
}
@test 'CPPFLAGS can be expanded' {
cat <<-"EOF" | retab >$apkbuild
foo() {
CPPFLAGS="$CPPFLAGS -O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'CPPFLAGS should not be overwritten' {
cat <<-"EOF" | retab >$apkbuild
foo() {
CPPFLAGS="-O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
echo "output: $output"
assert_match "${lines[0]}" '\[AL36\].*:CPPFLAGS should not be overwritten, add \$CPPFLAGS to it'
}
@test 'CXXFLAGS can be expanded' {
cat <<-"EOF" | retab >$apkbuild
foo() {
CXXFLAGS="$CXXFLAGS -O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'CXXFLAGS should not be overwritten' {
cat <<-"EOF" | retab >$apkbuild
foo() {
CXXFLAGS="-O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
echo "output: $output"
assert_match "${lines[0]}" '\[AL36\].*:CXXFLAGS should not be overwritten, add \$CXXFLAGS to it'
}
@test 'FFLAGS can be expanded' {
cat <<-"EOF" | retab >$apkbuild
foo() {
FFLAGS="$FFLAGS -O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 0 ]]
}
@test 'FFLAGS should not be overwritten' {
cat <<-"EOF" | retab >$apkbuild
foo() {
FFLAGS="-O3"
}
EOF
run $cmd $apkbuild
[[ $status -eq 1 ]]
echo "output: $output"
assert_match "${lines[0]}" '\[AL36\].*:FFLAGS should not be overwritten, add \$FFLAGS to it'
}
# vim: noexpandtab
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment