-
Notifications
You must be signed in to change notification settings - Fork 0
/
alienfile
213 lines (183 loc) · 5.17 KB
/
alienfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use alienfile;
use Config;
# NOTE: you can set ALIEN_MESON_SHARE_PREFER to either:
#
# - "auto": try source install then try binary install (default)
# - "source": try source install only
# - "binary": try binary install only
plugin 'Probe::CommandLine' => (
command => $_,
args => [ '--version' ],
match => qr/([0-9\.]+)/,
version => qr/([0-9\.]+)/,
) for qw( meson.py meson );
my %github_info = (
github_user => 'mesonbuild',
github_repo => 'meson',
);
my $python_bin;
sub can_source {
for my $test_python_bin ( qw(python3 python) ) {
if(
File::Which::which($test_python_bin)
&&
Capture::Tiny::capture(sub {
system( $test_python_bin, qw( --version ) )
}) =~ /^Python 3/
) {
$python_bin = $test_python_bin;
return;
}
}
die "No Python3 found" unless defined $python_bin;
}
sub do_source {
# Python source
plugin 'Download::GitHub' => (
%github_info,
asset => 1,
asset_name => qr/^meson-([0-9\.]+)\.tar\.gz$/,
version => qr/([0-9\.]+)/,
);
patch sub {
my @tests = Path::Tiny::path('.')->children( qr/.*test.*/ );
$_->remove_tree for @tests;
Path::Tiny::path('graphics')->remove_tree;
Path::Tiny::path('setup.py')->remove_tree;
};
plugin 'Build::Copy';
after build => sub {
my($build) = @_;
$build->runtime_prop->{'style'} = 'source';
$build->runtime_prop->{'python-source'} = 1;
$build->runtime_prop->{command} = 'meson.py';
$build->runtime_prop->{python_bin} = $python_bin;
};
}
my ($binary_release_name_re, $binary_release_format);
sub can_binary {
if( $^O eq 'MSWin32' && $Config{ptrsize} == 8 ) {
# Windows 64-bit
$binary_release_name_re = qr/meson-.*-64\.msi/;
$binary_release_format = '.msi';
return;
}
if( $^O eq 'darwin' ) {
# macOS
$binary_release_name_re = qr/meson-.*\.pkg/;
$binary_release_format = '.pkg';
return;
}
die "No binary packages available for this configuration";
}
sub do_binary {
plugin 'Download::GitHub' => (
%github_info,
asset => 1,
asset_name => $binary_release_name_re,
asset_format => 'none',
version => qr/([0-9\.]+)/,
);
if( $binary_release_format eq '.msi' ) {
extract sub {
my ($build) = @_;
my $msi = Path::Tiny::path($build->install_prop->{download})->canonpath;
my $cwd = Path::Tiny->cwd->canonpath;
Alien::Build::CommandSequence->new([
qw(msiexec /a),
$msi,
"TARGETDIR=$cwd",
'/qn'
])->execute($build);
};
patch sub {
my $cwd = Path::Tiny->cwd;
$_->remove for $cwd->children( qr/\.msi$/ );
my $PFiles = $cwd->child('PFiles64');
if( -d $PFiles ) {
File::Copy::Recursive::rmove( "$PFiles/*", $cwd );
$PFiles->remove_tree;
}
my $Meson = $cwd->child('Meson');
$Meson->child('ninja.exe')->remove;
File::Copy::Recursive::rmove( "$Meson/*", $cwd );
$Meson->remove_tree;
};
plugin 'Build::Copy';
after build => sub {
my($build) = @_;
$build->runtime_prop->{'style'} = 'binary';
$build->runtime_prop->{command} = 'meson';
};
} elsif( $binary_release_format eq '.pkg' ) {
extract sub {
my ($build) = @_;
Alien::Build::CommandSequence->new([
qw(pkgutil --expand-full),
$build->install_prop->{download},
'meson'
])->execute($build);
};
patch sub {
my $cwd = Path::Tiny->cwd;
my $meson_top = $cwd->child('meson.pkg/Payload/usr/local');
# remove some small extra files?
#$_->remove_tree for $cwd->children( qr/^(Distribution|Resources)$/ );
$meson_top->child('bin', 'ninja')->remove;
File::Copy::Recursive::rmove( "$meson_top/*", $cwd );
$meson_top->remove_tree;
};
plugin 'Build::Copy';
after build => sub {
my($build) = @_;
$build->runtime_prop->{'style'} = 'binary';
$build->runtime_prop->{command} = 'meson';
};
}
}
share {
requires 'Path::Tiny';
requires 'File::Which';
requires 'Capture::Tiny';
requires 'Alien::Build::CommandSequence';
requires 'File::Copy::Recursive';
$ENV{ALIEN_MESON_SHARE_PREFER} ||= 'auto';
my $release_types = {
source => {
'can' => \&can_source,
'do' => \&do_source,
},
binary => {
'can' => \&can_binary,
'do' => \&do_binary,
},
};
if( $ENV{ALIEN_MESON_SHARE_PREFER} eq 'auto' ) {
my $which_type;
my @types = qw(source binary);
for my $type (@types) {
eval { $release_types->{$type}{can}->() };
my $catch = $@;
if( $catch ) {
warn "Unable to install release type $type: $catch";
next;
}
$which_type = $type;
$release_types->{$type}{do}->();
last;
}
if( ! $which_type ) {
die "Unable to install from release types: @types";
}
} elsif( exists $release_types->{ $ENV{ALIEN_MESON_SHARE_PREFER} } ) {
$release_types->{ $ENV{ALIEN_MESON_SHARE_PREFER} }{$_}->() for qw(can do);
} else {
die "Unknown value for ALIEN_MESON_SHARE_PREFER: $ENV{ALIEN_MESON_SHARE_PREFER}";
}
};
sys {
meta->after_hook( probe => sub {
my($build) = @_;
$build->runtime_prop->{'style'} = 'system';
});
};