-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
throw together a quick dependency management system
- Loading branch information
Showing
7 changed files
with
131 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
deps.d | ||
*.compiled.* | ||
*.srcmap | ||
scraps/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
test4.compiled.js: bufferedaudionode.js stepgeneratornode.js test4.js Makefile | ||
{ java -jar ~/Downloads/compiler.jar --js=bufferedaudionode.js --js=stepgeneratornode.js --js=test4.js --language_in=ES6_STRICT --language_out=ES5_STRICT --create_source_map=test4.srcmap --jscomp_warning=checkTypes --jscomp_warning=checkVars; echo "//# sourceMappingURL=test4.srcmap"; } >| test4.compiled.js | ||
.PHONY: all | ||
|
||
nes.compiled.js: clock.js mem.js apu/lengthcounter.js apu/envelope.js apu/pulse.js apu/apu.js cpu.js bankswitcher.js nsf.js stepgeneratornode.js bufferedaudionode.js nsfplayer.js Makefile | ||
{ java -jar ~/Downloads/compiler.jar --js=clock.js --js=mem.js --js=apu/lengthcounter.js --js=apu/envelope.js --js=apu/pulse.js --js=apu/apu.js --js=cpu.js --js=bankswitcher.js --js=nsf.js --js=bufferedaudionode.js --js=stepgeneratornode.js --js=nsfplayer.js --language_in=ES6_STRICT --language_out=ES5_STRICT --create_source_map=nes.srcmap --jscomp_warning=checkTypes --jscomp_warning=checkVars; echo "//# sourceMappingURL=nes.srcmap"; } >| nes.compiled.js | ||
all: nes.compiled.js # test4.compiled.js | ||
|
||
JSCOMP=java -jar ~/Downloads/compiler.jar | ||
|
||
deps.d: deps.pl | ||
./deps.pl | ||
|
||
-include deps.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/perl | ||
|
||
# Dependency and makefile management. | ||
# Usage: ./deps.pl | ||
# Result: Generates a makefile based on in-file markup. | ||
|
||
# Input files: | ||
# foo.js: | ||
# //@ foo.compiled.js --checkTypes=warning | ||
# import Whatever from './bar'; | ||
# bar.js: | ||
# import Something from './baz'; | ||
# | ||
# Performs a toposort, collecting all deps, and generates deps.d: | ||
# | ||
# foo.compiled.js: foo.js bar.js deps.d | ||
# $(JSCOMP) ... --js=foo.js --js=bar.js --js_output_file=foo.compiled.js --checkTypes=warning | ||
# deps.d: foo.js bar.js | ||
# | ||
# This should be included in the top-level Makefile as: | ||
# | ||
# .PHONY: all | ||
# all: foo.compiled.js | ||
# | ||
# deps.d: | ||
# ./deps.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use File::Basename qw/dirname/; | ||
|
||
# Find all files recursively from current dir | ||
open FIND, "find . -name '*.js' | sed 's+^./++' |"; | ||
my @files = <FIND>; | ||
close FIND; | ||
map {chomp $_} @files; | ||
|
||
# Scan all the files | ||
my %generated = (); | ||
my %deps = (); | ||
foreach my $file (@files) { | ||
$deps{$file} = ''; | ||
open JS, $file; | ||
while (<JS>) { | ||
if (m|//@\s*(\S+)\s+(.*)|) { | ||
$generated{$1} = "$file $2"; | ||
} elsif (m|import .* from '(\.\.?/[^']+)'|) { | ||
my $dep = $1; | ||
my $dir = dirname $file; | ||
while ($dep =~ s|^\./|| or $dep =~ s|^\.\./||) { | ||
$dir = dirname $dir if $& eq '../'; | ||
} | ||
$dep = "$dir/$dep.js"; | ||
$dep =~ s|^(?:\./)+||; | ||
$deps{$file} .= " $dep"; | ||
} | ||
} | ||
close JS; | ||
} | ||
|
||
my $makefile = ''; | ||
|
||
# Now build up the makefile. | ||
foreach my $out (sort(keys(%generated))) { | ||
delete $deps{$out}; | ||
# Find all the deps | ||
my ($file, $flags) = split / /, $generated{$out}, 2; | ||
my %d = ($file => 1); | ||
my @q = ($file); | ||
while (@q) { | ||
my $cur = shift @q; | ||
foreach (split / /, $deps{$cur}) { | ||
next unless $_; | ||
next if defined $d{$_}; | ||
$d{$_} = 1; | ||
push @q, $_; | ||
} | ||
} | ||
# Generate the makefile line | ||
my $srcmap = $out; | ||
$srcmap =~ s/\.js$//; | ||
$srcmap .= ".srcmap"; | ||
my @deps = sort(keys(%d)); | ||
my $header = "$out: @deps deps.d"; | ||
my $cmd = "{ \$(JSCOMP) $flags"; | ||
foreach (@deps) { $cmd .= " --js=$_"; } | ||
$cmd .= " --create_source_map=$srcmap; echo '//# sourceMappingURL=$srcmap'; } >| $out"; | ||
$makefile .= "$header\n\t$cmd\n\n"; | ||
} | ||
|
||
my @srcs = sort(keys(%deps)); | ||
$makefile .= "deps.d: @srcs\n"; | ||
|
||
# Now read the existing file if it's there and only update if changed. | ||
if (open DEPS, "deps.d") { | ||
$/ = undef; | ||
my $prev = <DEPS>; | ||
close DEPS; | ||
exit 0 if $prev eq $makefile; | ||
} | ||
|
||
open DEPS, ">deps.d"; | ||
print DEPS $makefile; | ||
close DEPS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters