]>
git.ipfire.org Git - people/ummeegge/ipfire-2.x.git/blob - src/patches/suse-2.6.27.39/guards
6 # +xxx include if xxx is defined
7 # -xxx exclude if xxx is defined
8 # +!xxx include if xxx is not defined
9 # -!xxx exclude if xxx is not defined
23 # s/\.(diff?|patch)$//;
28 # for my $p in (($path, "$path.diff", "$path.dif", "$path.patch")) {
37 $dir =~ s
#([^/])$#$&/#; # append a slash if necessary
45 # Generate a list of files in a directory
48 my ($dir, $path) = @_;
49 my $dh = new FileHandle
;
53 opendir $dh, length("$dir$path") ?
"$dir$path" : '.'
54 or die "$dir$path: $!\n";
55 while ($file = readdir($dh)) {
56 next if $file =~ /^(\.|\.\.|\.#.*|CVS|.*~)$/;
57 if (-d
"$dir$path$file") {
58 @files = (@files, files_in
($dir, "$path$file/"));
60 #print "[$path$file]\n";
61 push @files, "$path$file";
68 # Parse a configuration file
69 # Callback called with ($patch, @guards) arguments
72 my ($fh, $callback) = @_;
85 foreach my $token (split /[\s\t\n]+/, $line) {
87 if ($token =~ /^[-+]/) {
90 #print "[" . join(",", @guards) . "] $token\n";
91 &$callback($token, @guards);
98 # Command line options
100 my ($dir, $config, $default, $check, $list, $invert_match, $with_guards) =
101 ( '', '-', 1, 0, 0, 0, 0);
107 print "$0 - select from a list of files guarded by conditions\n";
108 print "SYNOPSIS: $0 [--prefix=dir] [--path=dir1:dir2:...]\n" .
109 " [--default=0|1] [--check|--list] [--invert-match]\n" .
110 " [--with-guards] [--config=file] symbol ...\n\n" .
111 " (Default values: --path='" . join(':', @path) . "', " .
112 "--default=$default)\n";
116 # Parse command line options
118 Getopt
::Long
::Configure
("bundling");
121 'd|prefix=s' => \
$dir,
122 'c|config=s' => \
$config,
123 'C|check' => \
$check,
125 'w|with-guards' => \
$with_guards,
126 'p|path=s' => \
@path,
127 'D|default=i' => \
$default,
128 'v|invert-match' => \
$invert_match,
129 'h|help' => sub { help
(); exit 0; })) {
142 @path = split(/:/, join(':', @path));
144 my $fh = ($config eq '-') ? \
*STDIN
: new FileHandle
($config)
145 or die "$config: $!\n";
147 $dir = slashme
($dir);
150 # Check for duplicate files, or for files that are not referenced by
157 @files = (@files, files_in
($dir, slashme
($_)));
159 my %files = map { $_ => 0 } @files;
162 my ($patch, @guards) = @_;
163 if (exists $files{$patch}) {
166 print "Not found: $dir$patch\n";
173 while (($file, $ref) = each %files) {
177 print "Unused: $file\n" if $ref == 0;
181 print "Warning: multiple uses: $file\n" if $ref > 1;
182 # This is not an error if the entries are mutually exclusive...
185 exit $problems ?
1 : 0;
189 my ($patch, @guards) = @_;
190 print join(' ', @guards), ' '
191 if (@guards && $with_guards);
192 print "$dir$patch\n";
195 # Generate a list of patches to apply.
197 my %symbols = map { $_ => 1 } @ARGV;
200 my ($patch, @guards) = @_;
204 # If the first guard is -xxx, the patch is included by default;
205 # if it is +xxx, the patch is excluded by default.
206 $selected = ($guards[0] =~ /^-/);
210 or die "Bad guard '$_'\n";
212 # Check if the guard matches
213 if (($2 eq '!' && !exists $symbols{$3}) ||
214 ($2 eq '' && ( $3 eq '' || exists $symbols{$3}))) {
216 $selected = ($1 eq '+');
220 # If there are no guards, use the specified default result.
221 $selected = $default;
225 if $selected ^ $invert_match;
237 guards - select from a list of files guarded by conditions
241 F<guards> [--prefix=F<dir>] [--path=F<dir1:dir2:...>] [--default=<0|1>]
242 [--check|--list] [--invert-match] [--with-guards] [--config=<file>]
248 The script reads a configuration file that may contain so-called guards, file
249 names, and comments, and writes those file names that satisfy all guards to
250 standard output. The script takes a list of symbols as its arguments. Each line
251 in the configuration file is processed separately. Lines may start with a
252 number of guards. The following guards are defined:
256 +I<xxx> Include the file(s) on this line if the symbol I<xxx> is defined.
258 -I<xxx> Exclude the file(s) on this line if the symbol I<xxx> is defined.
260 +!I<xxx> Include the file(s) on this line if the symbol I<xxx> is not defined.
262 -!I<xxx> Exclude the file(s) on this line if the symbol I<xxx> is not defined.
264 - Exclude this file. Used to avoid spurious I<--check> messages.
268 The guards are processed left to right. The last guard that matches determines
269 if the file is included. If no guard is specified, the I<--default>
270 setting determines if the file is included.
272 If no configuration file is specified, the script reads from standard input.
274 The I<--check> option is used to compare the specification file against the
275 file system. If files are referenced in the specification that do not exist, or
276 if files are not enlisted in the specification file warnings are printed. The
277 I<--path> option can be used to specify which directory or directories to scan.
278 Multiple directories are eparated by a colon (C<:>) character. The
279 I<--prefix> option specifies the location of the files.
281 Use I<--list> to list all files independend of any rules. Use I<--invert-match>
282 to list only the excluded patches. Use I<--with-guards> to also include all
283 inclusion and exclusion rules.
287 Andreas Gruenbacher <agruen@suse.de>, SUSE Labs