Alien-CPython3

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

              $from->copy($to);
            }
          }
          else
          {
            die 'get did not return a file';
          }
        };
      }
    };
  };


  extract sub {
    my ($build) = @_;

    my @msis = Path::Tiny::path($build->install_prop->{download})->absolute->children( qr/\.msi$/ );
    my $cwd = Path::Tiny->cwd->canonpath;

    for my $msi (@msis) {
      Alien::Build::CommandSequence->new([
        qw(msiexec /a),
        $msi->canonpath,
        "TARGETDIR=$cwd",
        '/qn'
      ])->execute($build);
      my $cwd_msi = Path::Tiny->cwd->child( $msi->basename );
      if( -f $cwd_msi ) {
        $build->log( "Removing @{[ $msi->basename ]}");
        $cwd_msi->remove;
      }
    }
  };

  before build => sub {
    my($build) = @_;

    Alien::Build::CommandSequence->new([
      qw(python -m ensurepip --default-pip),
    ])->execute($build);
  };

  plugin 'Build::Copy';

  after build => sub {
    my($build) = @_;

    my $prefix = $build->install_prop->{prefix};

    $build->runtime_prop->{'style'} = 'binary';
    $build->runtime_prop->{command} = 'python';

    $build->runtime_prop->{share_bin_dir_rel} = '.';
  };
}

sub _otool_libs {
  my ($file) = @_;

  my @libs = do {
    my ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = IPC::Cmd::run(
      command => [ qw(otool -L), $file  ],
      verbose => 0,
    ) or die;


    my @lines = split /\n/, join "", @$stdout_buff;

    # Output is a single line:
    #   - ": is not an object file"
    #   - ": object is not a Mach-O file type."
    die "Not an object file: @lines" if @lines < 2;
    # Output:
    #   - "Archive : [...]"
    die "No libs: $lines[0]" if $lines[0] =~ /^Archive\s+:\s+/;

    # first line is $file
    shift @lines;
    grep { defined } map {
      $_ =~ m%[[:blank:]]+(.*/(Python|[^/]*\.dylib))[[:blank:]]+\(compatibility version%;
      my $path = $1;
      $path;
    } @lines;
  };

  \@libs;
}

use constant PYTHON_FRAMEWORK_PREFIX => '/Library/Frameworks/Python.framework';

sub macos_relocatable_python {
  my ($build, $base) = @_;

  $base = path($base);

  die "Not a directory: $base" unless -d $base;

  my ($version_base) = $base->child( qw(Python.framework Versions) )->children( qr/^3\./ );

  my @paths_to_check;

  File::Find::find(
    sub { push @paths_to_check, path($File::Find::name) if -f && -B },
    $version_base );

  my %paths_changed;

  # Turn paths from PYTHON_FRAMEWORK_PREFIX to @rpath/Python.framework.
  my $frameworks_path = path(PYTHON_FRAMEWORK_PREFIX)->parent;
  my $rpathify = sub {
    my ($path) = @_;
    return unless index($path, PYTHON_FRAMEWORK_PREFIX . '/') == 0;
    return File::Spec->catfile(
      '@rpath',
      File::Spec->abs2rel($path, $frameworks_path)
    );
  };
  for my $change_path (@paths_to_check) {
    next if exists $paths_changed{$change_path};
    my $libs;
    $build->log("Skipping $change_path\n"), next unless eval { $libs = _otool_libs( $change_path ); 1 };



( run in 0.466 second using v1.01-cache-2.11-cpan-9bca49b1385 )