]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
Add support for recursive target definitions
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 17 Jul 2014 21:27:20 +0000 (23:27 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 17 Jul 2014 21:27:20 +0000 (23:27 +0200)
I.e. one target definition can contain another --target option.

novaboot
tests/novaboot.wv

index a4bf1cf13167d16bea8831ec3179b5f8710bc299..09612aa1fb3279f8ef040b7ba9c97c5d653c335c 100755 (executable)
--- a/novaboot
+++ b/novaboot
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 use warnings (exists $ENV{NOVABOOT_TEST} ? (FATAL => 'all') : ());
-use Getopt::Long qw(GetOptionsFromString);
+use Getopt::Long qw(GetOptionsFromString GetOptionsFromArray);
 use Pod::Usage;
 use File::Basename;
 use File::Spec;
@@ -123,7 +123,6 @@ sub handle_send
     @expect_seen = ();
 }
 
-Getopt::Long::Configure(qw/no_ignore_case no_pass_through/);
 my %opt_spec;
 %opt_spec = (
     "amt=s"         => \$amt,
@@ -183,10 +182,19 @@ my %opt_spec;
 # First process target options
 {
     my $t = defined($explicit_target) ? $explicit_target : $CFG::default_target;
-    if ($t) {
+    my @target_expanded;
+    Getopt::Long::Configure(qw/no_ignore_case pass_through/);
+    while ($t) {
        exists $CFG::targets{$t} or die("Unknown target '$t' (valid targets are: ".join(", ", sort keys(%CFG::targets)).")");
-       GetOptionsFromString($CFG::targets{$t}, %opt_spec);
+
+       undef $explicit_target;
+       my ($ret, $remaining_args) = GetOptionsFromString ($CFG::targets{$t}, ("target|t=s" => \$explicit_target));
+       if (!$ret) { die "Error parsing target $t option"; }
+       push(@target_expanded, @$remaining_args);
+       $t = $explicit_target;
     }
+    Getopt::Long::Configure(qw/no_ignore_case no_pass_through/);
+    GetOptionsFromArray(\@target_expanded, %opt_spec) or die ("Error in target definition");
 }
 
 # Then process other command line options - some of them may override
index 7cee40b020ca0f4da6714f23c65de685de9ca71e..9f682646df1f84ac4c5a5d5ba290c0501e60bb9c 100755 (executable)
@@ -70,4 +70,24 @@ WVSTART ISO image generation
 create_dummy
 WVPASS ./script --iso --target ''
 
+WVSTART Recursive target definition
+create_dummy
+cat > .novaboot <<EOF
+%targets = (
+    't1' => '--reset-cmd="echo MyResetCmd"',
+    't2' => '--target t1',
+);
+EOF
+WVPASS sh -c "./script --target=t2|tee output"
+WVPASS grep -q ^MyResetCmd output
+
+WVSTART Wrong target definition
+create_dummy
+cat > .novaboot <<EOF
+%targets = ('t1' => '--nonsense');
+EOF
+WVPASS sh -c "./script --target=t1 2>&1 |tee output"
+WVPASS grep -q "Error in target definition" output
+
+
 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))