<commit_before>use Pies;
use Panda::Common;

class Panda::Builder does Pies::Builder {
    has $!srcdir;

    method build(Pies::Project $p) {
        indir "$!srcdir/{dirname $p.name}", {
            run 'ufo' and die "ufo failed";
            run 'make' and die "Building failed";
        };
    }
}

# vim: ft=perl6<commit_msg>Use pure-perl building instead of ufo && make<commit_after>use Pies;
use Panda::Common;
use File::Find;
use File::Mkdir;

class Panda::Builder does Pies::Builder {
    has $!srcdir;

    method build-order(@list) {
        # TODO
        return @list
    }

    method build(Pies::Project $p) {
        indir "$!srcdir/{dirname $p.name}", {
            if "Configure.pl".IO ~~ :f {
                run 'perl6 Configure.pl' and die "Configure.pl failed";
            }

            if "Makefile".IO ~~~ :f {
                run 'make' and die "'make' failed";
                return; # it's alredy built
            }

            # list of files to compile
            my @files = find(dir => 'lib', name => /\.pm6?$/).list;
            my @dirs = @files.map(*.dir).uniq;
            mkdir "blib/$_", :p for @dirs;

            my @tobuild = self.build-order(@files);
            my $p6lib = "{cwd}/blib/lib:{cwd}/lib:{%*ENV<PERL6LIB>}";
            for @tobuild -> $file {
                $file.IO.copy: "blib/{$file.dir}/{$file.name}";
                run "env PERL6LIB=$p6lib perl6 --target=pir "
                    ~ "--output=blib/{$file.dir}/"
                    ~ "{$file.name.subst(/\.pm6?$/, '.pir')} $file"
                    and die "Failed building $file";
            }
        };
    }
}

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.16535433070866143, 'fraction_numerical': 0.0060569351907934586, 'mean_word_length': 1.7037643207855975, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2807667', 'n_tokens_mistral': 572, 'n_tokens_neox': 553, 'n_words': 129}