This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
/
BuckEnvironmentCheckPhase.php-example
67 lines (62 loc) · 1.87 KB
/
BuckEnvironmentCheckPhase.php-example
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
<?hh // strict
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook\ShipIt;
// Not strict because variadics aren't currently supported by strict
final class BuckEnvironmentCheckPhase extends EnvironmentCheckPhase {
private static function runCommand(
int $extra_flags,
string ...$command
): string {
/* HH_FIXME[4128] Use ShipItShellCommand */
return ShipItUtil::shellExec(
/* path = */ '.',
/* stdin = */ null,
ShipItUtil::DONT_VERBOSE | ShipItUtil::NO_THROW | $extra_flags,
...$command,
);
}
<<__Override>>
public function runImpl(ShipItBaseConfig $config): void {
$ant_v = self::runCommand(
/* flags = */ 0,
'ant', '-version',
);
$match = array();
if (!preg_match('@version ([0-9\.]+)@', $ant_v, &$match)) {
fprintf(STDERR, "Couldn't identify ant version: %s\n", $ant_v);
exit(1);
}
if ($match[1] < '1.9') {
fprintf(STDERR, "Needed ant 1.9, got %s\n", $match[1]);
exit(1);
}
$java_v = self::runCommand(
ShipItUtil::RETURN_STDERR,
'java', '-version',
);
$match = array();
if (!preg_match('@version "([0-9\.]+)@', $java_v, &$match)) {
fprintf(STDERR, "Couldn't identify java version: %s\n", $java_v);
exit(1);
}
if ($match[1] < '1.7') {
fprintf(STDERR, "Needed Java 1.7, got %s\n", $match[1]);
exit(1);
}
if (getenv('ANDROID_HOME') === false) {
fwrite(STDERR, "ANDROID_HOME env variable not set\n");
exit(1);
}
if (getenv('NDK_HOME') === false) {
fwrite(STDERR, "NDK_HOME env variable not set\n");
exit(1);
}
}
}