Changeset 16 in ProjectBuilder for devel/pb/bin
- Timestamp:
- Jul 30, 2007, 6:07:31 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb.pl
r15 r16 15 15 use Data::Dumper; 16 16 use English; 17 use AppConfig qw(:argcount :expand); 18 use File::Basename; 17 19 use Time::localtime qw(localtime); 18 20 use POSIX qw(strftime); … … 30 32 my $option = ""; 31 33 my @pkgs; 34 my $pbtag; # Global TAG variable 35 my $pbver; # Global VERSION variable 36 my $pbrev; # GLOBAL REVISION variable 37 my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst()); 38 my $pbdate = strftime("%Y-%m-%d", @date); 32 39 33 40 getopts('p:t',\%opts); … … 71 78 foreach my $p (@pkgs) { 72 79 73 my $v;74 75 80 if (-f "$ENV{'PBROOT'}/$p/VERSION") { 76 81 open(V,"$ENV{'PBROOT'}/$p/VERSION") || die "Unable to open $ENV{'PBROOT'}/$p/VERSION"; 77 $ v= <V>;78 chomp($ v);82 $pbver = <V>; 83 chomp($pbver); 79 84 close(V); 80 85 } else { 81 $v = $ENV{'PBVER'}; 82 } 83 84 my $tag; 86 $pbver = $ENV{'PBVER'}; 87 } 85 88 86 89 if (-f "$ENV{'PBROOT'}/$p/TAG") { 87 90 open(T,"$ENV{'PBROOT'}/$p/TAG") || die "Unable to open $ENV{'PBROOT'}/$p/TAG"; 88 $ tag = <T>;89 chomp($ tag);91 $pbtag = <T>; 92 chomp($pbtag); 90 93 close(T); 91 94 } else { 92 $tag = $ENV{'PBTAG'}; 93 } 94 print "Management of $p $v-$tag (rev $ENV{'PBREVISION'})\n"; 95 $pbtag = $ENV{'PBTAG'}; 96 } 97 $pbrev = $ENV{'PBREVISION'}; 98 print "Management of $p $pbver-$pbtag (rev $pbrev)\n"; 95 99 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'}); 96 # Clean up dest if necessary 97 my $dest = "$ENV{'PBDESTDIR'}/$p-$ v";100 # Clean up dest if necessary. The export will recreate it 101 my $dest = "$ENV{'PBDESTDIR'}/$p-$pbver"; 98 102 pbrm_rf($dest) if (-d $dest); 99 103 … … 116 120 # Creates a REVISION file 117 121 open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION"; 118 print R "$ ENV{'PBREVISION'}\n";122 print R "$pbrev\n"; 119 123 close(R); 120 124 … … 129 133 print " OK\n"; 130 134 } 131 my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());132 my $pbdate = strftime("%Y-%m-%d", @date);133 134 135 open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n"; 135 136 while (<D>) { … … 140 141 my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver); 141 142 #print Dumper($ddir, $dver, $dfam, $dtype, $dsuf); 142 #print "Filtering DDD => $pbdate, TTT => $ tag, RRR => $tag$dsuf, VVV => $v\n";143 144 # Filter build files from the most precise up to the less143 #print "Filtering DDD => $pbdate, TTT => $pbtag, RRR => $pbtag$dsuf, VVV => $pbver\n"; 144 145 # Filter build files from the less precise up to the most with overloading 145 146 # Filter all files found, keeping the name, and generating in dest 146 my @bfiles; 147 148 # Find all build files first relatively to PBROOT 149 my %bfiles; 147 150 #print "dir: $ENV{'PBCONF'}/$p\n"; 148 if (-d "$ENV{'PBCONF'}/$p/$ddir-$dver") { 149 opendir(BDIR,"$ENV{'PBCONF'}/$p/$ddir-$dver" || die "Unable to open dir $ENV{'PBCONF'}/$p/$ddir-$dver: $!"); 150 @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$ddir-$dver/$_" } readdir(BDIR); 151 if (-d "$ENV{'PBCONF'}/$p/$dtype") { 152 opendir(BDIR,"$ENV{'PBCONF'}/$p/$dtype" || die "Unable to open dir $ENV{'PBCONF'}/$p/$dtype: $!"); 153 foreach my $f (readdir(BDIR)) { 154 next if ($f =~ /^\./); 155 $bfiles{$f} = "$ENV{'PBCONF'}/$p/$dtype/$f"; 156 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; 157 } 158 closedir(BDIR); 159 } elsif (-d "$ENV{'PBCONF'}/$p/$dfam") { 160 opendir(BDIR,"$ENV{'PBCONF'}/$p/$dfam" || die "Unable to open dir $ENV{'PBCONF'}/$p/$dfam: $!"); 161 foreach my $f (readdir(BDIR)) { 162 next if ($f =~ /^\./); 163 $bfiles{$f} = "$ENV{'PBCONF'}/$p/$dfam/$f"; 164 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; 165 } 151 166 closedir(BDIR); 152 167 } elsif (-d "$ENV{'PBCONF'}/$p/$ddir") { 153 168 opendir(BDIR,"$ENV{'PBCONF'}/$p/$ddir" || die "Unable to open dir $ENV{'PBCONF'}/$p/$ddir: $!"); 154 @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$ddir/$_" } readdir(BDIR); 155 closedir(BDIR); 156 } elsif (-d "$ENV{'PBCONF'}/$p/$dfam") { 157 opendir(BDIR,"$ENV{'PBCONF'}/$p/$dfam" || die "Unable to open dir $ENV{'PBCONF'}/$p/$dfam: $!"); 158 @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$dfam/$_" } readdir(BDIR); 159 closedir(BDIR); 160 } elsif (-d "$ENV{'PBCONF'}/$p/$dtype") { 161 opendir(BDIR,"$ENV{'PBCONF'}/$p/$dtype" || die "Unable to open dir $ENV{'PBCONF'}/$p/$dtype: $!"); 162 @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$dtype/$_" } readdir(BDIR); 169 foreach my $f (readdir(BDIR)) { 170 next if ($f =~ /^\./); 171 $bfiles{$f} = "$ENV{'PBCONF'}/$p/$ddir/$f"; 172 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; 173 } 174 closedir(BDIR); 175 } elsif (-d "$ENV{'PBCONF'}/$p/$ddir-$dver") { 176 opendir(BDIR,"$ENV{'PBCONF'}/$p/$ddir-$dver" || die "Unable to open dir $ENV{'PBCONF'}/$p/$ddir-$dver: $!"); 177 foreach my $f (readdir(BDIR)) { 178 next if ($f =~ /^\./); 179 $bfiles{$f} = "$ENV{'PBCONF'}/$p/$ddir-$dver/$f"; 180 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~; 181 } 163 182 closedir(BDIR); 164 183 } else { … … 166 185 next; 167 186 } 187 print "bfiles: ".Dumper(\%bfiles)."\n"; 168 188 169 189 # Get all filters to apply 170 190 # They're cumulative from less specific to most specific 171 191 # suffix is .pbf 192 my @ffiles; 193 my ($ffile0, $ffile1, $ffile2, $ffile3); 172 194 if (-d "$ENV{'PBCONF'}/$p/pbfilter") { 173 opendir(BDIR,"$ENV{'PBCONF'}/$p/pbfilter" || die "Unable to open dir $ENV{'PBCONF'}/$p/pbfilter: $!"); 174 foreach my $f (readdir(BDIR)) { 175 if (-f "$ENV{'PBCONF'}/$p/pbfilter/$dtype.pbf") { 176 177 @bfiles = grep { ! /^\./ && -f "$ENV{'PBCONF'}/$p/$dtype/$_" } readdir(BDIR); 178 closedir(BDIR); 195 $ffile0 = "$ENV{'PBCONF'}/$p/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$p/pbfilter/$dtype.pbf"); 196 $ffile1 = "$ENV{'PBCONF'}/$p/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$p/pbfilter/$dfam.pbf"); 197 $ffile2 = "$ENV{'PBCONF'}/$p/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$p/pbfilter/$ddir.pbf"); 198 $ffile3 = "$ENV{'PBCONF'}/$p/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$p/pbfilter/$ddir-$dver.pbf"); 199 push @ffiles,$ffile0 if (defined $ffile0); 200 push @ffiles,$ffile1 if (defined $ffile1); 201 push @ffiles,$ffile2 if (defined $ffile2); 202 push @ffiles,$ffile3 if (defined $ffile3); 179 203 } 180 204 my $config = AppConfig->new({ 205 # Auto Create variables mentioned in Conf file 206 CREATE => 1, 207 DEBUG => 0, 208 GLOBAL => { 209 # Each conf item is a hash 210 ARGCOUNT => AppConfig::ARGCOUNT_HASH 211 } 212 }); 213 print "ffiles: ".Dumper(\@ffiles)."\n"; 214 if (@ffiles) { 215 $config->file(@ffiles); 216 my $ptr = $config->get("filter"); 217 print "f:".Dumper($ptr)."\n"; 218 219 # Apply now all the filters on all the files concerned 220 # All files are relative to PBROOT 221 # destination dir depends on the type of file 222 if (defined $ptr) { 223 foreach my $f (values %bfiles) { 224 filter_file($f,$ptr,"$dest/pbconf/$ddir-$dver/".basename($f)); 225 } 226 foreach my $f (@filteredfiles) { 227 filter_file($f,$ptr,"$dest/$f"); 228 } 229 } 230 } 181 231 } 182 232 close(D); 183 184 233 } 185 234 } else { … … 188 237 print " cms2build\n"; 189 238 } 239 240 sub filter_file { 241 242 my $f=shift; 243 my $ptr=shift; 244 my %filter=%$ptr; 245 my $destfile=shift; 246 247 print "From $f to $destfile\n"; 248 pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile)); 249 open(DEST,"> $destfile") || die "Unable to create $destfile"; 250 open(FILE,"$ENV{'PBROOT'}/$f") || die "Unable to open $f: $!"; 251 while (<FILE>) { 252 my $line = $_; 253 foreach my $s (keys %filter) { 254 # Process single variables 255 #print "debug: $filter{$s}\n"; 256 my $tmp = $filter{$s}; 257 next if (not defined $tmp); 258 # Expand variables if any single one found 259 if ($tmp =~ /\$/) { 260 eval { $tmp =~ s/(\$\w+)/$1/eeg }; 261 } 262 $line =~ s|$s|$tmp|; 263 } 264 print DEST $line; 265 } 266 close(FILE); 267 close(DEST); 268 }
Note:
See TracChangeset
for help on using the changeset viewer.