Source

shlomi-fish-homepage / bin / gen-build-deps

Full commit
#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Long (qw( GetOptions ));

use IO::All;
use File::Which ( qw( which ) );
use YAML::XS ( qw( LoadFile ) );

my $out_fn;
my $exes_fn;
my $modules_fn;

GetOptions(
    'o|output=s' => \$out_fn,
    'exes-conf=s' => \$exes_fn,
    'modules-conf=s' => \$modules_fn,
)
    or die "Failed - $!";

{
    my @not_found;

    foreach my $cmd (
        io->file($exes_fn)->chomp->getlines()
    )
    {
        if (not
            (
                ($cmd =~ m{\A/})
                ? (-e $cmd)
                : (defined(scalar(which($cmd))))
            )
        )
        {
            push @not_found, $cmd;
        }
    }

    if (@not_found)
    {
        print "The following commands could not be found:\n\n";
        foreach my $cmd (sort { $a cmp $b } @not_found)
        {
            print "$cmd\n";
        }
        exit(-1);
    }
}

{
    my ($yaml_data) = LoadFile($modules_fn);

    my $required_modules = $yaml_data->{required}->{modules};

    my @not_found;

    foreach my $m (sort { $a cmp $b } keys(%$required_modules))
    {
        my $v = $required_modules->{$m};
        local $SIG{__WARN__} = sub {};
        my $verdict = eval( "use $m " . ($v ||'') . ';' );
        my $Err = $@;

        if ($Err)
        {
            push @not_found, $m;
        }
    }

    if (@not_found)
    {
        print "The following modules could not be found:\n\n";
        foreach my $module (@not_found)
        {
            print "$module\n";
        }
        exit(-1);
    }
}

{
    my @not_found;

    foreach my $path (
        "$ENV{HOME}/.shlomifish-amazon-sak.json",
    )
    {
        if (! -e $path)
        {
            push @not_found, $path;
        }
    }

    if (@not_found)
    {
        print "The following required files could not be found.\n";
        print "Please set them up:\n";
        print "\n";

        foreach my $path (sort { $a cmp $b } @not_found)
        {
            print "$path\n";
        }
        exit(-1);
    }
}

io->file($out_fn)->print("Success!");

exit(0);