-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeRelease.pl
executable file
·503 lines (401 loc) · 14.8 KB
/
MakeRelease.pl
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#! /usr/bin/perl
# This script automates the generation of release packages/installers.
#
# The appropriate header files are updated with the release version,
# optional features with associated service keys.
use File::Basename;
use File::Copy;
use Cwd ('abs_path', 'cwd');
use File::Path qw(remove_tree);
use Getopt::Long;
use POSIX qw(tmpnam);
BEGIN
{
# Global Constants
$VERSION_HEADER = "version.h";
$OPTIONAL_FEATURES_HEADER = "OptionalFeatures.h";
# Create a temporary directory to work in
do
{
$scratchDir = tmpnam();
} while (-e "$scratchDir");
die "Cannot make temporary directory '$scratchDir'\n$!\n"
unless mkdir $scratchDir;
}
END
{
chdir $SOURCE_DIR if (defined $SOURCE_DIR);
my @savedFiles = glob("$scratchDir/*h");
push @savedFiles, glob("$scratchDir/*plist");
# Reinstate any saved files.
foreach $file (@savedFiles)
{
copy("$file", ".");
}
# Remove temporary directory.
print STDERR "Error: Cannot remove temp directory $scratchDir $!\n"
unless ((-d $scratchDir) && (remove_tree($scratchDir) > 0));
}
# Update the header file defining the version with that required.
sub updateVersion
{
my ($version) = @_;
die "ERROR: Cannot open version header file '$VERSION_HEADER'\n$!\n"
unless open INPUT_FILE, "<$VERSION_HEADER";
die "ERROR: Cannot open tmp version header file " .
"'$scratchDir/$VERSION_HEADER.tmp'\n$!\n"
unless open OUTPUT_FILE, ">$scratchDir/$VERSION_HEADER.tmp";
while (<INPUT_FILE>)
{
# Replace the default version with the required version.
if (/CURRENT_VERSION/)
{
s/".*"/"$version"/;
}
print OUTPUT_FILE;
}
close INPUT_FILE;
close OUTPUT_FILE;
# Save the original file for restoration on exit.
copy("$VERSION_HEADER", "$scratchDir/$VERSION_HEADER") or
die "ERROR: Cannot backup \"$VERSION_HEADER\"\n$!\n";
# Overwrite the original file with our modified version.
copy("$scratchDir/$VERSION_HEADER.tmp", "$VERSION_HEADER") or
die "ERROR: Cannot overwrite \"$VERSION_HEADER\"\n$!\n";
}
# Update the header file defining optional features and associated keys to
# enable access to the required services.
sub updateOoptionalFeatures
{
my ($enableMp3, $enableAac, $enableRadio, $tuneInPartnedId, $enableTidal,
$tidalToken, $enableQobuz, $qobuzAppId, $qobuzSecret) = @_;
die "ERROR: Cannot open optional feature heeder file " .
"'$OPTIONAL_FEATURES_HEADER'\n$!\n"
unless open INPUT_FILE, "<$OPTIONAL_FEATURES_HEADER";
die "ERROR: Cannot open tmp optional feature header file " .
"'$scratchDir/$OPTIONAL_FEATURES_HEADER.tmp'\n$!\n"
unless open OUTPUT_FILE, ">$scratchDir/$OPTIONAL_FEATURES_HEADER.tmp";
while (<INPUT_FILE>)
{
if (defined $enableMp3 && /\/\/#define ENABLE_MP3/)
{
s/\/\///;
print OUTPUT_FILE;
next;
}
if (defined $enableAac && /\/\/#define ENABLE_AAC/)
{
s/\/\///;
print OUTPUT_FILE;
next;
}
if (defined $enableRadio && /\/\/#define ENABLE_RADIO/)
{
s/\/\///;
print OUTPUT_FILE;
next;
}
if (defined $enableTidal && /\/\/#define ENABLE_TIDAL/)
{
s/\/\///;
print OUTPUT_FILE;
next;
}
if (defined $enableQobuz && /\/\/#define ENABLE_QOBUZ/)
{
s/\/\///;
print OUTPUT_FILE;
next;
}
if (defined $tidalToken && /^#define.*TIDAL_TOKEN_STRING/)
{
s/TIDAL_TOKEN_STRING/"$tidalToken"/;
print OUTPUT_FILE;
next;
}
if (defined $qobuzAppId && /^#define.*QOBUZ_APPID_STRING/)
{
s/QOBUZ_APPID_STRING/"$qobuzAppId"/;
print OUTPUT_FILE;
next;
}
if (defined $qobuzSecret && /^#define.*QOBUZ_SECRET_STRING/)
{
s/QOBUZ_SECRET_STRING/"$qobuzSecret"/;
print OUTPUT_FILE;
next;
}
if (defined $tuneInPartnedId && /^#define.*TUNEIN_PARTNER_ID_STRING/)
{
s/TUNEIN_PARTNER_ID_STRING/"$tuneInPartnedId"/;
print OUTPUT_FILE;
next;
}
print OUTPUT_FILE;
}
close INPUT_FILE;
close OUTPUT_FILE;
# Save the original file for restoration on exit.
copy("$OPTIONAL_FEATURES_HEADER", "$scratchDir/$OPTIONAL_FEATURES_HEADER")
or die "ERROR: Cannot backup \"$OPTIONAL_FEATURES_HEADER\"\n$!\n";
# Overwrite the original file with our modified version.
copy("$scratchDir/$OPTIONAL_FEATURES_HEADER.tmp", "$OPTIONAL_FEATURES_HEADER")
or die "ERROR: Cannot overwrite \"$OPTIONAL_FEATURES_HEADER\"\n$!\n";
}
# Build the release package and installer for Linux based platforms.
sub buildLinuxRelease
{
my ($platform, $version, $debug, $nativeCodecs) = @_;
# Cleanup any previous build.
system("make clean");
die "ERROR: Cleanup Failed\n" unless ($? == 0);
unlink glob("$platform/*sh");
unlink glob("$platform/*deb");
my $options;
$options .= " DEBUG=0" if (defined $debug);
$options .= " USE_LIBAVCODEC=0" if (defined $nativeCodecs);
$options .= " DISABLE_GTK=0" if (defined $headless);
# Execute the build
system("make $options $platform");
die "ERROR: Build Failed\n" unless ($? == 0);
# Generate the release package.
system("./GeneratePkg.pl -p=$platform -a=openhome-player -v=\"$version\" --i");
die "ERROR: Package Generation Failed\n" unless ($? == 0);
}
# Build the release package and installer for the Win32 platform.
#
# It is required that the script be run from a VS2013 command prompt and
# the path *MUST* contain the INNO Setup utility location
# (C:\Program Files (x86)\Inno Setup 5)
sub buildWin32Release
{
my ($version, $debug, $nativeCodecs) = @_;
my $config;
# Check 'msbuild' is available and executable.
eval {my @dummy = `msbuild 2>nul` or die "$!\n"};
if ($@)
{
die "ERROR: Cannot execute 'msbuild'\n" .
"Please ensure this script is run from a VS2013 command prompt\n";
}
# Check INNO Setup 5 is available and executable.
eval {my @dummy = `iscc 2>nul` or die "$!\n"};
if ($@)
{
die "ERROR: Cannot execute 'iscc'\n" .
"Please ensure Inno Setup 5 is in the PATH \n";
}
# Decide which configuration is required.
if (defined $debug)
{
$config = "Debug";
}
else
{
$config = "Release";
}
if (defined $nativeCodecs)
{
$config .= "IMF";
}
# Cleanup any previous build.
system("msbuild OpenHomePlayer.sln /target:Clean /p:Platform=Win32 " .
"/p:Configuration=$config");
die "ERROR: Cleanup Failed\n" unless ($? == 0);
unlink glob("../Win32Installer/*.exe");
# Execute the build
system("msbuild OpenHomePlayer.sln /p:Platform=Win32 " .
"/p:Configuration=$config");
die "ERROR: Build Failed\n" unless ($? == 0);
# Generate the release package.
# Move to the folder containing the ISetup installer generation script.
# Note the source directory before moving away. We must change back to
# the source diorectory on exit to restore the modified header file.
$SOURCE_DIR = cwd();
chdir "../Win32Installer" or
die "Error: Cannot move to Win32Installer folder\n$!\n";
my $parentFolder = dirname(cwd());
system("iscc \/dMySrcDir=\"$parentFolder\" " .
"\/dMyAppVersion=\"$version\" \/dReleaseType=\"$config\" " .
"OpenHomePlayerInstaller.iss");
die "ERROR: Package Generation Failed\n" unless ($? == 0);
# Annotate the installer with the version.
$version =~ s/\./-/g;
rename("setup.exe", "OpenHomePlayerSetup-$version.exe") or
die "ERROR: Cannot rename 'setup.exe' -> " .
"'OpenHomePlayerSetup-$version.exe'\n$!\n";
}
sub buildOsxRelease
{
my ($version, $debug, $nativeCodecs) = @_;
my $plistBuddy = "/usr/libexec/PlistBuddy";
my $plistFile = "Info.plist";
my $target = "OpenHomePlayer";
# Check the PlistBuddy utility is present and correct.
eval {my @dummy = `$plistBuddy 2>&1` or die "$!\n"};
if ($@)
{
die "ERROR: Cannot execute '$plistBuddy'\n" .
"Please ensure it is avaiable and executable\n";
}
# Save the original Info.plist file for restoration on exit.
copy("$plistFile", "$scratchDir") or
die "ERROR: Cannot backup '$plistFile'. $!\n";
# Update the Info.plist file with the current release information.
system("$plistBuddy -c 'Set :CFBundleShortVersionString \"$version\"' " .
"$plistFile");
die "ERROR: Cannot update version in '$plistFile'.\n$1\n"
unless ($? == 0);
# Note the source directory before moving away. We must change back to
# the source directory on exit to restore the modified header file.
$SOURCE_DIR = cwd();
# Move to folder containing the xcode project.
chdir "..";
# Select the native codec target if required.
if (defined $nativeCodecs)
{
$target = "OpenHomePlayerAFSCodec";
}
# Build and install the application to our temporary folder.
if (defined $debug)
{
system("xcodebuild -project OpenHomePlayer.xcodeproj -target $target " .
"-configuration Debug clean install " .
"DSTROOT=$scratchDir/OpenHomePlayer.dst");
}
else
{
system("xcodebuild -project OpenHomePlayer.xcodeproj -target $target " .
"-configuration Release clean install " .
"DSTROOT=$scratchDir/OpenHomePlayer.dst");
}
die "ERROR: Installation Build Failed\n" unless ($? == 0);
# Copy the latest resources into the pkg
my $pkgResDir = "$scratchDir/OpenHomePlayer.dst/Applications/" .
"$target.app/Contents/Resources/";
# Clear out any existing, possibly out of date, resources.
remove_tree("$pkgResDir/SoftPlayer") or
die "ERROR: Cannot remove pkg resource directory. $!\n";
# Copy over the latest resources from the dependencies
system("cp -R ../dependencies/Mac-x64/ohMediaPlayer/res $pkgResDir");
die "ERROR: Failed to copy current resources into pkg. $!\n"
unless ($? == 0);
# Name the resource folder correctly.
move("$pkgResDir/res", "$pkgResDir/SoftPlayer") or
die "ERROR: Failed to rename resource fodler $!\n";
# Duplicate the English language UI strings in the fallback location.
copy("$pkgResDir/SoftPlayer/lang/en-gb/ConfigOptions.txt",
"$pkgResDir/SoftPlayer/lang") or
die "ERROR: Failed to install default string resources. $!\n";
# Generate the OpenHomePlayer component package.
#
# The package is configured to install to '/Applications/OpenHomePlayer'
system("pkgbuild --root $scratchDir/OpenHomePlayer.dst/ " .
"--install-location \"/\" $scratchDir/OpenHomePlayer.pkg");
die "ERROR: Component Package Generation Failed\n" unless ($? == 0);
# Generate the installer package.
system("productbuild --distribution OpenHomePlayer/Distribution.xml " .
"--package-path $scratchDir --resources OpenHomePlayer " .
"OpenHomePlayer-$version.pkg");
die "ERROR: Installer Package Generation Failed\n" unless ($? == 0);
}
###############################################################################
# MAIN
###############################################################################
my $USAGE = <<EndOfText;
Usage: MakeRelease.pl --platform=<ubuntu|raspbian|Win32|osx> --version=<version>
[--debug] [--headless]
[[--enable-mp3] [--enable-aac] [--use-native-codecs]]
[--enable-radio --tunein-partner-id=<tunein partner id]
[--enable-tidal --tidal-token=<tidal token>]
[--enable-qobuz --qobuz-secret=<qobuz secret>
--qobuz-app-id=<qobuz app id>]
EndOfText
GetOptions("platform=s" => \$platform,
"version=s" => \$version,
"debug" => \$debug,
"use-native-codecs" => \$nativeCodecs,
"headless" => \$headless,
"enable-mp3" => \$enableMp3,
"enable-aac" => \$enableAac,
"enable-radio" => \$enableRadio,
"tunein-partner-id=s" => \$tuneInPartnedId,
"enable-tidal" => \$enableTidal,
"tidal-token=s" => \$tidalToken,
"enable-qobuz" => \$enableQobuz,
"qobuz-secret=s" => \$qobuzSecret,
"qobuz-app-id=s" => \$qobuzAppId);
# Verify command line parameters
if (! defined $platform || ! defined $version)
{
die "$USAGE\n";
}
if ($platform !~ /ubuntu|raspbian|Win32|osx/)
{
die "Invalid Platform: $platform\n";
}
if (defined $nativeCodecs && (! defined $enableMp3 && ! defined $enableAac))
{
die "Native codecs require eith Mp3 or Aac to be enabeled\n";
}
if ((defined $enableRadio && ! defined $tuneInPartnedId) ||
(! defined $enableRadio && defined $tuneInPartnedId))
{
die "$USAGE\n";
}
if ((defined $enableTidal && ! defined $tidalToken) ||
(! defined $enableTidal && defined $tidalToken))
{
die "$USAGE\n";
}
if ((defined $enableQobuz && !(defined $qobuzSecret && defined $qobuzAppId)) ||
(! defined $enableQobuz && (defined $qobuzSecret || defined $qobuzAppId)))
{
die "$USAGE\n";
}
if (defined $headless && ($platform ne "raspbian"))
{
die "Headless target is currently unavailable for this platform\n";
}
# Move to the directory containing the platform source.
my $sourceDir = abs_path(dirname($0));
if ($platform =~ /raspbian|ubuntu/)
{
$sourceDir .= "/linux";
}
elsif ($platform =~ /osx/)
{
$sourceDir .= "/$platform/OpenHomePlayer";
}
else
{
$sourceDir .= "/$platform";
}
chdir $sourceDir or
die "ERROR: Cannot move to source directory: $sourceDir. $!\n";
# Update 'version.h' with the release version.
#
# On Osx this isn't required as the version is read from the application
# Info.plist
if ($platform !~ /osx/)
{
&updateVersion("$version");
}
# Update 'OptionalFeatures.h with enabled features and service keys
&updateOoptionalFeatures($enableMp3, $enableAac, $enableRadio, $tuneInPartnedId,
$enableTidal, $tidalToken, $enableQobuz, $qobuzAppId,
$qobuzSecret);
# Generate the release
if ($platform =~ /raspbian|ubuntu/)
{
&buildLinuxRelease($platform, $version, $debug, $nativeCodecs, $headless);
}
elsif ($platform =~ /Win32/)
{
&buildWin32Release($version, $debug, $nativeCodecs);
}
elsif ($platform =~ /osx/)
{
&buildOsxRelease($version, $debug, $nativeCodecs);
}
1;