/ufo
Created
June 7, 2012 20:14
Revisions
-
gerdr revised this gist
Jun 16, 2012 . 1 changed file with 28 additions and 23 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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,33 @@ #!/usr/bin/env perl6 sub dirwalk($dir = '.', Mu :$d = none(<. ..>), Mu :$f = *, :&dx = -> $ {}, :&fx = -> $ {}) { for dir($dir, :test(*)) -> $name { given "$dir/$name" { when .IO.f { &fx.($_) if $f.ACCEPTS($name) } when .IO.d { dirwalk($_, :$d, :$f, :&dx, :&fx) if $d.ACCEPTS($name) } } } &dx.($dir); } sub mkdir-p($file, Bool :$f = False) { my @parents = $file.split('/'); @parents.pop if $f; my $path = ''; for @parents { $path ~= "$_/"; mkdir($path) unless $path.IO.d; } } sub rmdir-r($path) { dirwalk($path, :dx(&rmdir), :fx(&unlink)) } sub compile($src, $dest) { @@ -32,13 +41,6 @@ sub compile($src, $dest) { $comp.command_line($args, :encoding<utf8>); } sub parse-makefile($file) { gather for $file.IO.lines { next unless /'.pir:'/; @@ -64,7 +66,10 @@ sub name-from-pm($file) { multi MAIN() { my $last-run = 'Makefile'.IO.f ?? 'Makefile'.IO.modified !! -Inf; my @modules = gather <lib lib6>.grep(*.IO.d).map({ dirwalk($_, :f(/\.pm6?$/), :fx(&take)) }); my %targets = @modules.map(&name-from-pm) Z=> @modules.map(&pir-from-pm); my %deps = parse-makefile('Makefile') if 'Makefile'.IO.f; @@ -123,11 +128,11 @@ multi MAIN('rmdir', *@dirs) { } multi MAIN('compile', $src, $dest) { mkdir-p($dest, :f); compile($src, $dest); } multi MAIN('cp', $src, $dest) { mkdir-p($dest, :f); $src.IO.copy($dest); } -
gerdr revised this gist
Jun 9, 2012 . 1 changed file with 87 additions and 106 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 charactersOriginal file line number Diff line number Diff line change @@ -1,100 +1,5 @@ #!/usr/bin/env perl6 sub dirpath($file) { my @path = $file.split('/'); @path.pop; @@ -127,26 +32,102 @@ sub compile($src, $dest) { $comp.command_line($args, :encoding<utf8>); } sub find-modules($dir) { gather given dir($dir).map("$dir/" ~ *) { take .grep(*.IO.f).grep(/\.pm6?$/); take .grep(*.IO.d).map(&find-modules) } } sub parse-makefile($file) { gather for $file.IO.lines { next unless /'.pir:'/; my ($target, @deps) = .comb(/[<![:]>\S]+/); take $target => @deps; } } sub parse-pm-file($file) { gather for $file.IO.lines { take ~$0 if /^\s* ['use'|'need'] \s+ (\w+ ['::' \w+]*)/; } } sub pir-from-pm($file) { 'blib/' ~ $file.subst(/\.pm6?$/, '.pir'); } sub name-from-pm($file) { $file.subst(/^lib6?\/|\.pm6?$/, '', :g).subst('/', '::', :g); } multi MAIN() { my $last-run = 'Makefile'.IO.f ?? 'Makefile'.IO.modified !! -Inf; my @modules = <lib lib6>.grep(*.IO.d).map(&find-modules); my %targets = @modules.map(&name-from-pm) Z=> @modules.map(&pir-from-pm); my %deps = parse-makefile('Makefile') if 'Makefile'.IO.f; for @modules { next if $last-run > .IO.modified; say "ufo: parsing $_"; my $name = name-from-pm($_); my $target = %targets{$name}; my @deps = "blib/$_", parse-pm-file($_).grep(* ne $name).map({ %targets{$_} // Nil }); %deps{$target} = @deps; } my $ufo = "$*EXECUTABLE_NAME $?FILE"; given open('Makefile', :w) { LEAVE .close; .say( "build: {%targets.values} clean: $ufo rmdir blib realclean: clean $ufo rm Makefile Makefile: {@modules} $ufo "); for @modules -> $file { .say( "blib/$file: $file $ufo cp $file blib/$file "); } for %deps.kv -> $target, @deps { .say( "$target: {@deps} $ufo compile {@deps[0]} $target "); } } } multi MAIN('rm', *@files) { unlink($_) for @files.grep(*.IO.e); } multi MAIN('rmdir', *@dirs) { rmdir-r($_) for @dirs.grep(*.IO.e); } multi MAIN('compile', $src, $dest) { mkpath(dirpath($dest)); compile($src, $dest); } multi MAIN('cp', $src, $dest) { mkpath(dirpath($dest)); $src.IO.copy($dest); } -
gerdr revised this gist
Jun 8, 2012 . 1 changed file with 1 addition and 0 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 charactersOriginal file line number Diff line number Diff line change @@ -117,6 +117,7 @@ sub rmdir-r($dir) { } sub compile($src, $dest) { use lib <blib/lib blib/lib6>; my $comp := pir::compreg__Ps('perl6'); my $args := nqp::list; nqp::push($args, $?FILE); -
gerdr revised this gist
Jun 8, 2012 . 1 changed file with 32 additions and 18 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,14 @@ #!/usr/bin/env perl6 my $ufo = "$*EXECUTABLE_NAME $?FILE"; my %modules; my %pirs; my %deps; multi MAIN() { for grep *.IO.d, <lib lib6> -> $dir { my @files = find-modules($dir); for @files -> $file { my $name = module-name($file.subst(/^ $dir '/' /, '')); my $pir = 'blib/' ~ pir-file($file); @@ -88,6 +79,14 @@ $pir: $bfile $deps $fh.close; } sub find-modules($root) { gather { my @files = dir($root).map("$root/" ~ *); take @files.grep(*.IO.f).grep(/ \.pm6? $/); take @files.grep(*.IO.d).map(&find-modules); } } sub module-name($file) { $file.subst(/ \.pm6? $/, '').subst('/', '::', :g) } @@ -110,24 +109,39 @@ sub mkpath(*@path) { } } sub rmdir-r($dir) { my @files = dir($dir).map("$dir/" ~ *); rmdir-r($_) for @files.grep(*.IO.d); unlink($_) for @files.grep(*.IO.f); rmdir($dir); } sub compile($src, $dest) { my $comp := pir::compreg__Ps('perl6'); my $args := nqp::list; nqp::push($args, $?FILE); nqp::push($args, '--target=pir'); nqp::push($args, "--output=$dest"); nqp::push($args, $src); $comp.command_line($args, :encoding<utf8>); } multi MAIN(Str *@files, Bool :$rm) { say 'rm -f ' ~ @files; for @files -> $file { unlink($file) if $file.IO.f } } multi MAIN(Str $dir, Bool :$rmdir) { say "rm -rf $dir"; rmdir-r($dir) if $dir.IO.e; } multi MAIN(Str $src, Str $dest, Bool :$cc) { say "perl6 --target=pir --output=$dest $src"; mkpath(dirpath($dest)); compile($src, $dest); } multi MAIN(Str $src, Str $dest, Bool :$cp) { -
gerdr revised this gist
Jun 8, 2012 . 1 changed file with 47 additions and 11 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ #!/usr/bin/env perl6 # TODO: # investigate if spawning perl6 is necessary for compilation # get rid of remaining shell() usage # write replacement for find my %modules; my %pirs; my %deps; @@ -50,19 +55,34 @@ multi MAIN() { my $fh = open('Makefile', :w); my $pirs = %pirs.keys.sort.join(' '); my $files = %pirs.values.sort.join(' '); $fh.print: qq{# generated by ufo build: $pirs clean: @$ufo --rmdir blib realclean: clean @$ufo --rm Makefile Makefile: $files @$ufo }; for %deps.keys.sort -> $pir { next unless %pirs.exists($pir); my $file = %pirs{$pir}; my $bfile = 'blib/' ~ $file; my $deps = %deps{$pir}.sort.join(' '); $fh.print: qq{ $bfile: $file @$ufo --cp $file $bfile $pir: $bfile $deps @$ufo --cc $bfile $pir }; } $fh.close; @@ -76,9 +96,25 @@ sub pir-file($file) { $file.subst(/ \.pm6? $/, '.pir') } sub dirpath($file) { my @path = $file.split('/'); @path.pop; @path; } sub mkpath(*@path) { my $path = '.'; for @path -> $dir { $path ~= '/' ~ $dir; mkdir($path) unless $path.IO.d; } } multi MAIN(Str *@files, Bool :$rm) { say('rm -f ' ~ @files); for @files -> $file { unlink($file) if $file.IO.f } } multi MAIN(Str $dir, Bool :$rmdir) { @@ -87,15 +123,15 @@ multi MAIN(Str $dir, Bool :$rmdir) { } multi MAIN(Str $src, Str $dest, Bool :$cc) { mkpath(dirpath($dest)); $perl6 ~= <blib/lib blib/lib6>.grep(*.IO.d).map(' -I' ~ *).join; my $cmd = "$perl6 --target=pir --output=$dest $src"; say $cmd; shell($cmd); } multi MAIN(Str $src, Str $dest, Bool :$cp) { say "cp $src $dest"; mkpath(dirpath($dest)); $src.IO.copy($dest); } -
gerdr revised this gist
Jun 8, 2012 . 1 changed file with 3 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -50,11 +50,13 @@ multi MAIN() { my $fh = open('Makefile', :w); $fh.say("build: " ~ %pirs.keys.sort.join(' ') ~ "\n"); $fh.say("clean:\n\t@$ufo --rmdir blib\n"); $fh.say("realclean: clean\n\t@$ufo --rm Makefile\n"); $fh.say("Makefile: " ~ %pirs.values.sort.join(' ') ~"\n\t@$ufo\n"); for %deps.keys.sort -> $pir { next unless %pirs.exists($pir); my $file = %pirs{$pir}; my $bfile = 'blib/' ~ $file; $fh.say("$bfile: $file"); -
gerdr revised this gist
Jun 8, 2012 . 1 changed file with 80 additions and 60 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 charactersOriginal file line number Diff line number Diff line change @@ -1,79 +1,99 @@ #!/usr/bin/env perl6 my %modules; my %pirs; my %deps; my $perl6 = $*EXECUTABLE_NAME; my $ufo = "$perl6 $?FILE"; multi MAIN() { for grep *.IO.d, <lib lib6> -> $dir { my @files = qqx[ find $dir -type f \\( -name \\*.pm -or -name \\*.pm6 \\) ].lines; for @files -> $file { my $name = module-name($file.subst(/^ $dir '/' /, '')); my $pir = 'blib/' ~ pir-file($file); %modules{$name} = $pir; %pirs{$pir} = $file; } } if 'Makefile'.IO.f { for 'Makefile'.IO.lines { next if /^ [ \t || '#' ] /; my ($file, $deps) = .split(/ \s* ':' \s* /, 2); next unless $file ~~ /^ \S+ \.pir $/; %deps{$file} = []; for $deps.words -> $dep { next unless %pirs.exists($dep); %deps{$file}.push($dep); } } } for %modules.kv -> $name, $pir { my $file = %pirs{$pir}; next if %deps.exists($pir) && 'Makefile'.IO.modified > $file.IO.modified; say "ufo: parsing $file"; %deps{$pir} = []; for $file.IO.lines { if /^\s* ['use'|'need'] \s+ (\w+ ['::' \w+]*)/ && $0 -> $dep { next if $dep eq $name || !%modules.exists(~$dep); %deps{$pir}.push(%modules{~$dep}); } } } my $fh = open('Makefile', :w); $fh.say('build: ' ~ %pirs.keys.sort.join(' ') ~ "\n"); $fh.say("clean:\n\t@$ufo --rmdir blib\n"); $fh.say("realclean: clean\n\t@$ufo --rm Makefile\n"); for %deps.keys.sort -> $pir { my $file = %pirs{$pir}; my $bfile = 'blib/' ~ $file; $fh.say("$bfile: $file"); $fh.say("\t@$ufo --cp $file $bfile\n"); $fh.say("$pir: $bfile " ~ %deps{$pir}.join(' ')); $fh.say("\t@$ufo --cc $bfile $pir\n"); } $fh.close; } sub module-name($file) { $file.subst(/ \.pm6? $/, '').subst('/', '::', :g) } sub pir-file($file) { $file.subst(/ \.pm6? $/, '.pir') } multi MAIN(Str *@files, Bool :$rm) { say('rm -f ' ~ @files); shell('rm -f ' ~ @files); } multi MAIN(Str $dir, Bool :$rmdir) { say("rm -rf $dir"); shell("rm -rf $dir"); } multi MAIN(Str $src, Str $dest, Bool :$cc) { shell("mkdir -p `dirname $dest`"); $perl6 ~= <blib/lib blib/lib6>.grep(*.IO.d).map(' -I' ~ *).join; my $cmd = "$perl6 --target=pir --output=$dest $src"; say $cmd; shell($cmd); } multi MAIN(Str $src, Str $dest, Bool :$cp) { shell("mkdir -p `dirname $dest`"); say "cp $src $dest"; $src.IO.copy($dest); } -
gerdr revised this gist
Jun 7, 2012 . 1 changed file with 2 additions and 5 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,7 @@ #!/usr/bin/env perl6 multi MAIN() { my $fh = open('Makefile', :w); $fh.print(q{#generated by ufo PERL6 := ___PERL6__ @@ -53,7 +49,8 @@ include $(DEPS) }.subst(:g, '___PERL6__', $*EXECUTABLE_NAME).subst(:g, '__UFO__', $*PROGRAM_NAME).subst(:g, '__LIBDIR__', 'lib6/'.IO ~~ :d ?? 'lib6' !! 'lib/'.IO ~~ :d ?? 'lib' !! '.')); $fh.close; } sub module-name($path) { -
gerdr created this gist
Jun 7, 2012 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ #!/usr/bin/env perl6 multi MAIN() { # BUG: :w only clears file and prints nothing! my $fh = open('Makefile', :w); $fh.close; $fh = open('Makefile', :a); LEAVE $fh.close; $fh.print(q{#generated by ufo PERL6 := ___PERL6__ UFO := __UFO__ PM_FILES := $(shell find __LIBDIR__ -type f -name '*.pm') PM6_FILES := $(shell find __LIBDIR__ -type f -name '*.pm6') SOURCES := $(PM_FILES) $(PM6_FILES) PIR_FILES_FROM_PM := $(PM_FILES:%.pm=blib/%.pir) PIR_FILES_FROM_PM6 := $(PM6_FILES:%.pm6=blib/%.pir) BUILD_FILES := $(SOURCES:%=blib/%) $(PIR_FILES_FROM_PM) $(PIR_FILES_FROM_PM6) DEPS := $(addprefix .ufo/,$(SOURCES)) override PERL6LIB := blib/__LIBDIR__:$(PERL6LIB) export PERL6LIB .PHONY : build clean realclean build : $(BUILD_FILES) clean : rm -rf blib realclean : clean rm -rf .ufo rm -f Makefile $(DEPS) : .ufo/% : % @mkdir -p $(dir $@) $(UFO) $< $@ $(SOURCES) $(SOURCES:%=blib/%) : blib/% : % @mkdir -p $(dir $@) cp $< $@ $(PIR_FILES_FROM_PM) : %.pir : %.pm @mkdir -p $(dir $@) $(PERL6) --target=pir --output=$@ $< $(PIR_FILES_FROM_PM6) : %.pir : %.pm6 @mkdir -p $(dir $@) $(PERL6) --target=pir --output=$@ $< include $(DEPS) }.subst(:g, '___PERL6__', $*EXECUTABLE_NAME).subst(:g, '__UFO__', $*PROGRAM_NAME).subst(:g, '__LIBDIR__', 'lib6/'.IO ~~ :d ?? 'lib6' !! 'lib/'.IO ~~ :d ?? 'lib' !! '.')) } sub module-name($path) { $path.subst(/^ lib6? '/' || \.pm6? $/, '', :g).subst('/', '::', :g) } sub pir-name($path) { $path.subst(/ \.pm6? $/, '.pir') } multi MAIN($in, $out, *@files) { my $name = module-name($in); my %modules = @files.map({ module-name($^file) => 'blib/' ~ $^file }); my @deps; for $in.IO.lines { if /^\s* ['use'|'need'] \s+ (\w+ ['::' \w+]*)/ && $0 -> $dep { next if $dep eq $name || !%modules.exists(~$dep); @deps.push(pir-name(%modules{~$dep})); } } my $fh = $out eq '-' ?? $*OUT !! open($out, :w); $fh.say(pir-name('blib/' ~ $in) ~ ' : ' ~ @deps.join(' ')); $fh.close; }