aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-08-03 03:57:53 -0400
committerB. Watson <urchlay@slackware.uk>2024-08-03 03:57:53 -0400
commit62b60ad45fbed9c6ce1ac6280390430418a2301a (patch)
tree8c711efd9202ec3398201e7963e1d902c32490f3
parent0dba383818c23844d957ce673fb398208c1aba49 (diff)
downloadsbo-maintainer-tools-62b60ad45fbed9c6ce1ac6280390430418a2301a.tar.gz
sbolint: detect scripts that do no error-checking.
-rwxr-xr-xsbolint31
1 files changed, 30 insertions, 1 deletions
diff --git a/sbolint b/sbolint
index aa520c6..1ad3cc2 100755
--- a/sbolint
+++ b/sbolint
@@ -235,6 +235,13 @@ that haven't been updated).
=item -
+The script must exit with failure status if the build fails. Normally this
+is done with B<set -e> somewhere near the top of the script. Also allowed
+is B<#!/bin/bash -e> (or B<-ue, -eu, etc>) on the first line, or manual
+checks with B<|| exit 1>. If none of these things are found, it's an error.
+
+=item -
+
README must exist, have mode 0644, its character encoding must be
either ASCII or UTF-8 without BOM, and it may not contain tab characters.
@@ -1334,9 +1341,13 @@ sub check_script {
my @lines = check_and_read($file);
return unless scalar @lines;
+ my $bash_e_opt;
if($lines[0] !~ /^#!/) {
log_error("$file:1: missing or invalid shebang line (should be '#!/bin/bash')");
- } elsif($lines[0] !~ m,#!/bin/bash(?: (?:-e|-eu|-ue|-e -u|-u -e))?$,) {
+ } elsif($lines[0] =~ m,#!/bin/bash(?:\s+(-e|-eu|-ue|-e -u|-u -e))?\s*$,) {
+ my $arg = $1;
+ $bash_e_opt = 1 if defined($arg) && $arg =~ /e/;
+ } else {
log_warning("$file:1: shebang line should be #!/bin/bash (possibly with -e/-u arg(s)), not '$lines[0]'");
}
@@ -1345,6 +1356,7 @@ sub check_script {
my ($cdpkg, $codestart, $lint_enabled, $print_pkg_name, $pkg_type, $arch_lineno);
my ($old_arch, $old_flags, $have_py2, $have_py3);
my ($libsuf_set, $flags_set, $libsuf_used, $flags_used);
+ my ($set_e, $or_exit_1);
$lint_enabled = 1;
for(@lines) {
@@ -1516,6 +1528,15 @@ sub check_script {
if(/^[^#]*\$\{?SLKCFLAGS/) {
$flags_used = $lineno;
}
+
+ if(/^[^#]*set\s+([^#]+)/) {
+ my $arg = $1;
+ $set_e = $lineno if $arg =~ /e/;
+ }
+
+ if(/^[^#]*\|\|\s+exit\s+1/) {
+ $or_exit_1 = $lineno;
+ }
}
if(not defined($prgnam)) {
@@ -1620,6 +1641,14 @@ sub check_script {
if($libsuf_set && (!$libsuf_used)) {
log_note("$file:$libsuf_set: LIBDIRSUFFIX gets set, but never used.");
}
+
+ ## warn "\$set_e: " . ($set_e || 0);
+ ## warn "\$bash_e_opt: " . ($bash_e_opt || 0);
+ ## warn "\$or_exit_1: " . ($or_exit_1 || 0);
+
+ if(!(defined $set_e || defined $bash_e_opt || defined $or_exit_1)) {
+ log_error("$file: this script has no error checking (need bash -e option, 'set -e', or '|| exit 1').");
+ }
}
sub check_doinst {