Просмотр исходного кода

scripts: Cleanup build_opt() handling

- Rename binary_opt() to build_opt() in dpkg-genchanges, and change
  it to handle -S.
- Remove function prototype.
- Expand the ternary operator in build_opt() into a if/elsif/else
  statement.
- Use build_opt() instead of hardcoding '-S' all over the place.
Guillem Jover лет назад: 12
Родитель
Сommit
f29cb2788d
2 измененных файлов с 39 добавлено и 20 удалено
  1. 20 11
      scripts/dpkg-buildpackage.pl
  2. 19 9
      scripts/dpkg-genchanges.pl

+ 20 - 11
scripts/dpkg-buildpackage.pl

@@ -144,12 +144,18 @@ sub build_normal() { return ($include & BUILD_ALL) == BUILD_ALL; }
 sub build_sourceonly() { return $include == BUILD_SOURCE; }
 sub build_binaryonly() { return !($include & BUILD_SOURCE); }
 sub build_binaryindep() { return ($include == BUILD_ARCH_INDEP); }
-sub build_opt() {
-    return (($include == BUILD_BINARY) ? '-b' :
-            (($include == BUILD_ARCH_DEP) ? '-B' :
-             (($include == BUILD_ARCH_INDEP) ? '-A' :
-              (($include == BUILD_SOURCE) ? '-S' :
-               internerr("build_opt called with include=$include")))));
+sub build_opt {
+    if ($include == BUILD_BINARY) {
+        return '-b';
+    } elsif ($include == BUILD_ARCH_DEP) {
+        return '-B';
+    } elsif ($include == BUILD_ARCH_INDEP) {
+        return '-A';
+    } elsif ($include == BUILD_SOURCE) {
+        return '-S';
+    } else {
+        internerr("build_opt called with include=$include");
+    }
 }
 
 while (@ARGV) {
@@ -211,34 +217,37 @@ while (@ARGV) {
     } elsif (/^-nc$/) {
 	$noclean = 1;
     } elsif (/^-b$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, '-S') if build_sourceonly;
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
+	    if build_sourceonly;
 	$include = BUILD_BINARY;
 	push @changes_opts, '-b';
 	@checkbuilddep_opts = ();
 	$buildtarget = 'build';
 	$binarytarget = 'binary';
     } elsif (/^-B$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, '-S') if build_sourceonly;
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
+	    if build_sourceonly;
 	$include = BUILD_ARCH_DEP;
 	push @changes_opts, '-B';
 	@checkbuilddep_opts = qw(-B);
 	$buildtarget = 'build-arch';
 	$binarytarget = 'binary-arch';
     } elsif (/^-A$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, '-S') if build_sourceonly;
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
+	    if build_sourceonly;
 	$include = BUILD_ARCH_INDEP;
 	push @changes_opts, '-A';
 	@checkbuilddep_opts = qw(-A);
 	$buildtarget = 'build-indep';
 	$binarytarget = 'binary-indep';
     } elsif (/^-S$/) {
-	usageerr(_g('cannot combine %s and %s'), build_opt, '-S')
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
 	    if build_binaryonly;
 	$include = BUILD_SOURCE;
 	push @changes_opts, '-S';
 	@checkbuilddep_opts = qw(-A -B);
     } elsif (/^-F$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, build_opt)
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
 	    if not build_normal;
 	$include = BUILD_ALL;
 	@checkbuilddep_opts = ();

+ 19 - 9
scripts/dpkg-genchanges.pl

@@ -92,11 +92,18 @@ my $include = BUILD_ALL;
 
 sub is_sourceonly() { return $include == BUILD_SOURCE; }
 sub is_binaryonly() { return !($include & BUILD_SOURCE); }
-sub binary_opt() {
-    return (($include == BUILD_BINARY) ? '-b' :
-            (($include == BUILD_ARCH_DEP) ? '-B' :
-             (($include == BUILD_ARCH_INDEP) ? '-A' :
-              internerr("binary_opt called with include=$include"))));
+sub build_opt {
+    if ($include == BUILD_BINARY) {
+       return '-b';
+    } elsif ($include == BUILD_ARCH_DEP) {
+        return '-B';
+    } elsif ($include == BUILD_ARCH_INDEP) {
+        return '-A';
+    } elsif ($include == BUILD_SOURCE) {
+        return '-S';
+    } else {
+        internerr("build_opt called with include=$include");
+    }
 }
 
 sub version {
@@ -143,18 +150,21 @@ sub usage {
 while (@ARGV) {
     $_=shift(@ARGV);
     if (m/^-b$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, '-S') if is_sourceonly;
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
+	    if is_sourceonly;
 	$include = BUILD_BINARY;
     } elsif (m/^-B$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, '-S') if is_sourceonly;
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
+	    if is_sourceonly;
 	$include = BUILD_ARCH_DEP;
 	printf { *STDERR } _g('%s: arch-specific upload - not including arch-independent packages') . "\n", $Dpkg::PROGNAME;
     } elsif (m/^-A$/) {
-	usageerr(_g('cannot combine %s and %s'), $_, '-S') if is_sourceonly;
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
+	    if is_sourceonly;
 	$include = BUILD_ARCH_INDEP;
 	printf { *STDERR } _g('%s: arch-indep upload - not including arch-specific packages') . "\n", $Dpkg::PROGNAME;
     } elsif (m/^-S$/) {
-	usageerr(_g('cannot combine %s and %s'), binary_opt, '-S')
+	usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
 	    if is_binaryonly;
 	$include = BUILD_SOURCE;
     } elsif (m/^-s([iad])$/) {