Alien-Bazel

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

    my $binary_release = 0;

    my $os_arch = join ":", ( $^O, meta->prop->{platform}{cpu}{arch}{name} );
    if( exists $os_arch_to_binary_release{$os_arch} && ! FROM_SOURCE ) {
        $binary_release = 1;
        my ($suffix) = @{ $os_arch_to_binary_release{$os_arch} }{qw(suffix)};
        %asset_info = (
            asset_name   => qr/^bazel-([0-9\.]+)-\Q${suffix}\E$/,
            asset_format => 'f',
        );
    }

    plugin 'Download::GitHub' => (
        github_user  => 'bazelbuild',
        github_repo  => 'bazel',
        asset        => 1,
        %asset_info,
    );

    if( ! $binary_release ) { # from source
        # provides `bash` in crippled operating systems
        plugin 'Build::MSYS';

        # NEED UPGRADE: verify the signature made by Bazel's release key 3D5919B448457EE0
        # https://bazel.build/bazel-release.pub.gpg

        meta->prop->{env}->{JAVA_HOME} = Alien::Bazel::Util->_find_jdk_java_home;
        # https://bazel.build/install/compile-source#bootstrap-bazel
        # $ env EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh
        meta->prop->{env}->{EXTRA_BAZEL_ARGS} = '--tool_java_runtime_version=local_jdk';

        if( DEBUG_BAZEL_BOOTSTRAP ) {
            meta->prop->{env}->{VERBOSE} = 'yes';
            meta->prop->{env}->{BAZEL_DEBUG_JAVA_COMPILATION} = 1;
        }
        build [
            sub {
                my ($build) = @_;
                $build->log("JAVA_HOME        = $ENV{JAVA_HOME}");
                $build->log("EXTRA_BAZEL_ARGS = $ENV{EXTRA_BAZEL_ARGS}");
            },
            'bash ./compile.sh',
            '%{make_path} %{.install.stage}/bin',
            '%{cp} output/bazel %{.install.stage}/bin'
        ];
    } else {
        patch sub {
            my ($build) = @_;
            my ($bazel_file) = Path::Tiny->new('.')->children(qr/^bazel-/);
            # remove all but 'bazel' prefix and possibly a '.exe' suffix (on
            # MSWin32) so $exe is either 'bazel' or 'bazel.exe'
            (my $exe = $bazel_file->basename) =~ s/^ (bazel) .*? ( (?:\.exe)? ) $/$1$2/x;
            $bazel_file->move( $bazel_file->parent->child($exe) );
            $build->install_prop->{bazel_exe} = $exe;
        };
        build [
            '%{make_path} %{.install.stage}/bin',
            "%{cp} %{.install.bazel_exe} %{.install.stage}/bin",

            ( $^O ne 'MSWin32'
            ? "chmod +x %{.install.stage}/bin/%{.install.bazel_exe}"
            : ()
            )
        ];
    }

    after 'gather' => sub {
        my $time_total = time() - $time_start;
        print {*STDERR} '<<< DEBUG >>> have $time_total = ', $time_total, ' seconds', "\n";
    };
};



( run in 0.396 second using v1.01-cache-2.11-cpan-70e19b8f4f1 )