Skip to content

Commit 632059c

Browse files
committed
build/standalone(_packaged)/*.ps: Build only the required dependencies
1 parent fab91d7 commit 632059c

File tree

3 files changed

+75
-29
lines changed

3 files changed

+75
-29
lines changed

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@ STANDALONE_DIR = $(DSTDIR)/standalone
8585
STANDALONE_MKDIRS:=$(STANDALONE_DIR)
8686
STANDALONE_MKDIRSTAMP:=$(STANDALONE_DIR)/.dirstamp
8787
TARGETS_STANDALONE:=$(addprefix $(STANDALONE_DIR)/,$(addsuffix .ps,$(TARGETS)))
88-
cleanlist += $(TARGETS_STANDALONE) $(STANDALONE_MKDIRSTAMP)
8988

9089
STANDALONE_PACKAGE_DIR = $(DSTDIR)/standalone_package
9190
STANDALONE_PACKAGE_MKDIRS:=$(STANDALONE_PACKAGE_DIR)
9291
STANDALONE_PACKAGE_MKDIRSTAMP:=$(STANDALONE_PACKAGE_DIR)/.dirstamp
9392
TARGETS_STANDALONE_PACKAGE:=$(addprefix $(STANDALONE_PACKAGE_DIR)/,$(addsuffix .ps,$(TARGETS)))
94-
cleanlist += $(TARGETS_STANDALONE_PACKAGE) $(STANDALONE_PACKAGE_MKDIRSTAMP)
9593

9694
RELEASEDIR := $(DSTDIR)/release
9795
RELEASEMKDIRS:=$(RELEASEDIR)
@@ -249,17 +247,17 @@ $(STANDALONE_MKDIRSTAMP):
249247
mkdir -p $(STANDALONE_MKDIRS)
250248
touch $@
251249

252-
$(STANDALONE_DIR)/%.ps: $(MONOLITHIC_FILE) $(SRCDIR)/%.ps.src $(SRCDIR)/ps.head $(CHANGES_FILE) $(STANDALONE_MKDIRSTAMP)
253-
$(DSTDIR)/make_standalone.pl $< $@
250+
$(STANDALONE_DIR)/%.ps: $(SRCDIR)/%.ps.src $(SRCDIR)/ps.head $(CHANGES_FILE) $(STANDALONE_MKDIRSTAMP)
251+
$(DSTDIR)/make_standalone.pl $(RESDIR)/Resource $@
254252

255253
#------------------------------------------------------------
256254

257255
$(STANDALONE_PACKAGE_MKDIRSTAMP):
258256
mkdir -p $(STANDALONE_PACKAGE_MKDIRS)
259257
touch $@
260258

261-
$(STANDALONE_PACKAGE_DIR)/%.ps: $(MONOLITHIC_PACKAGE_FILE) $(SRCDIR)/%.ps.src $(SRCDIR)/ps.head $(CHANGES_FILE) $(STANDALONE_PACKAGE_MKDIRSTAMP)
262-
$(DSTDIR)/make_standalone.pl $< $@
259+
$(STANDALONE_PACKAGE_DIR)/%.ps: $(SRCDIR)/%.ps.src $(SRCDIR)/ps.head $(CHANGES_FILE) $(STANDALONE_PACKAGE_MKDIRSTAMP)
260+
$(DSTDIR)/make_standalone.pl $(PACKAGEDIR)/Resource $@
263261

264262
#------------------------------------------------------------
265263

build/make_deps.pl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,21 @@
4141
print "$reqfiles\n";
4242
}
4343

44+
# Standalone dependency rules (only for encoders, not preamble)
45+
if ($resource ne 'uk.co.terryburton.bwipp') {
46+
for my $standalonedir ('build/standalone', 'build/standalone_package') {
47+
my $resdir = $standalonedir eq 'build/standalone'
48+
? 'build/resource/Resource' : 'build/packaged_resource/Resource';
49+
my $reqfiles = "$standalonedir/$resource.ps :";
50+
foreach my $req (split /\s+/, $reqs) {
51+
$req = 'uk.co.terryburton.bwipp' if $req eq 'preamble';
52+
(my $reqfile) = $upr =~ /^$req=(.*)$/m;
53+
$reqfiles .= " $resdir/$reqfile";
54+
}
55+
# Include the encoder itself as a dependency
56+
$reqfiles .= " $resdir/$provfile";
57+
print "$reqfiles\n";
58+
}
59+
}
60+
4461
exit 0;

build/make_standalone.pl

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
if ($#ARGV < 1) {
88
die <<EOF
9-
Usage: $0 <infile> <outfile> [<encoder>...]
9+
Usage: $0 <resourcedir> <outfile> [<encoder>...]
1010
1111
If encoders are not specified explicitly, the single encoder name is deduced
1212
from the name of the output file.
1313
EOF
1414
}
1515

16-
my $infile = shift;
16+
my $resourcedir = shift;
1717
my $outfile = shift;
1818

1919
($outfile) = $outfile =~ /(.*)/; # Untaint
@@ -37,40 +37,71 @@
3737
close $fh;
3838
$head =~ s/XXXX-XX-XX/$version/;
3939

40-
open($fh, '<', $infile) || die "File not found: $infile";
41-
my $template = join('', <$fh>);
42-
close($fh);
40+
open($fh, '<', 'src/uk.co.terryburton.bwipp.upr') || die 'Unable to open UPR file';
41+
my $upr = join('', <$fh>);
42+
close $fh;
4343

4444
open($fh, '>', $outfile) || die "Failed to write $outfile";
4545
print $fh $head;
4646

4747
my %seen;
4848
for my $encoder (@encoders) {
49-
($_, $_, my $meta, $_) = $template =~ /
49+
my $srcfile = "src/$encoder.ps.src";
50+
my $src_fh;
51+
open($src_fh, '<', $srcfile) || die "Unable to open source file: $srcfile";
52+
my $src = join('', <$src_fh>);
53+
close($src_fh);
54+
55+
($_, $_, my $meta, $_) = $src =~ /
5056
^%\ --BEGIN\ (ENCODER|RENDERER|RESOURCE)\ ($encoder)--$
5157
(.*?)
5258
(^[^%].*?)
5359
^%\ --END\ \1\ \2--$
54-
/msgx or die 'Encoder unknown';
60+
/msgx or die "Encoder unknown: $encoder";
61+
5562
(my $reqs) = $meta =~ /^% --REQUIRES (.*)--$/mg;
5663
$reqs = '' unless defined $reqs;
57-
my %reqs = ($encoder => 1);
58-
$reqs{$_} = 1 foreach split ' ', $reqs;
5964

60-
while ($template =~ /
61-
^%\ --BEGIN\ (ENCODER|RENDERER|RESOURCE)\ ([\w-]+?)--$
62-
(.*?)
63-
(^%%.*?)
64-
(^[^%].*?)
65-
^%\ --END\ \1\ \2--$
66-
/msgx) {
67-
my $resource = $2;
68-
my $meta = $3;
69-
my $dsc = $4;
70-
my $body = $5;
71-
next unless $reqs{$resource};
72-
next if $seen{$resource}++;
73-
print $fh "$dsc$body\n";
65+
# Build set of resources to include: dependencies + encoder itself
66+
my %reqs_set;
67+
$reqs_set{$_} = 1 foreach split(' ', $reqs);
68+
$reqs_set{$encoder} = 1;
69+
70+
# Output resources in UPR order (matching monolithic behavior)
71+
my @resources;
72+
while ($upr =~ /^(.*)=(.*)$/mg) {
73+
my $name = $1;
74+
$name = 'preamble' if $name eq 'uk.co.terryburton.bwipp';
75+
push @resources, $name if $reqs_set{$name};
76+
}
77+
78+
for my $resource (@resources) {
79+
next if $seen{$resource}++;
80+
81+
# Map resource name to file path via UPR
82+
my $lookup = $resource eq 'preamble' ? 'uk.co.terryburton.bwipp' : $resource;
83+
(my $relpath) = $upr =~ /^$lookup=(.*)$/m;
84+
die "Resource not found in UPR: $resource" unless $relpath;
85+
86+
my $respath = "$resourcedir/$relpath";
87+
($respath) = $respath =~ /(.*)/; # Untaint
88+
89+
my $res_fh;
90+
open($res_fh, '<', $respath) || die "Unable to open resource file: $respath";
91+
my $res = join('', <$res_fh>);
92+
close($res_fh);
93+
94+
# Extract body from resource file (same pattern as make_monolithic.pl)
95+
$res =~ /
96+
(^%%BeginResource:\ [\w\.]+\ [\w\.-]+?\ .*?$)
97+
.*?
98+
(^%%BeginData:.*?$
99+
.*?
100+
^%%EndResource$)
101+
/msgx or die "Failed to parse resource: $respath";
102+
my $body = "$1\n$2\n";
103+
104+
print $fh "$body\n";
74105
}
75106
}
76107

0 commit comments

Comments
 (0)