-
Notifications
You must be signed in to change notification settings - Fork 17
/
checkbuild.py
152 lines (123 loc) · 5.25 KB
/
checkbuild.py
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
#!/usr/bin/env python
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Verifies that the build is sane.
Cleans old build artifacts, configures the required environment, determines
build goals, and invokes the build scripts.
"""
import argparse
import datetime
import inspect
import os
import platform
import subprocess
import sys
class ArgParser(argparse.ArgumentParser):
def __init__(self):
super(ArgParser, self).__init__(
description=inspect.getdoc(sys.modules[__name__]))
self.add_argument(
'--package', action='store_true', dest='package', default=True,
help='Package the NDK when done building.')
self.add_argument(
'--no-package', action='store_false', dest='package',
help='Do not package the NDK when done building.')
self.add_argument(
'--release', default=datetime.date.today().strftime('%Y%m%d'),
help='Release name. Package will be named android-ndk-RELEASE.')
system_group = self.add_mutually_exclusive_group()
system_group.add_argument(
'--system', choices=('darwin', 'linux', 'windows', 'windows64'),
help='Build for the given OS.')
old_choices = (
'darwin', 'darwin-x86',
'linux', 'linux-x86',
'windows',
)
system_group.add_argument(
'--systems', choices=old_choices, dest='system',
help='Build for the given OS. Deprecated. Use --system instead.')
def invoke_build(script, args=None):
if args is None:
args = []
subprocess.check_call([os.path.join('build/tools', script)] + args)
def build_ndk(out_dir, system, build_args):
build_args = list(build_args)
build_args.append('--package-dir={}'.format(out_dir))
build_args.append('--verbose')
if system == 'windows' or platform.system() == 'Darwin':
# There's no sense in building the target libraries from Darwin (they
# shouldn't be any different from those built on Linux), and we can't
# build them using the Windows toolchains (because we aren't on
# Windows), so only build the host components.
ndk_dir_arg = '--ndk-dir={}'.format(os.getcwd())
invoke_build('build-host-prebuilts.sh',
build_args + [ndk_dir_arg])
else:
invoke_build('rebuild-all-prebuilt.sh', build_args)
def package_ndk(release_name, system, out_dir, build_args):
package_args = [
'--out-dir={}'.format(out_dir),
'--prebuilt-dir={}'.format(out_dir),
'--release={}'.format(release_name),
'--systems={}'.format(system),
]
invoke_build('package-release.sh', package_args + build_args)
def main():
args, build_args = ArgParser().parse_known_args()
os.chdir(os.path.dirname(os.path.realpath(__file__)))
# Set ANDROID_BUILD_TOP.
if 'ANDROID_BUILD_TOP' not in os.environ:
os.environ['ANDROID_BUILD_TOP'] = os.path.realpath('..')
build_top = os.getenv('ANDROID_BUILD_TOP')
system = args.system
if system != 'windows':
build_args.append('--try-64')
if system is not None:
# TODO(danalbert): Update build server to pass just 'linux'.
original_system = system
if system == 'darwin':
system = 'darwin-x86'
elif system == 'linux':
system = 'linux-x86'
elif system == 'windows64':
system = 'windows'
if system not in ('darwin-x86', 'linux-x86', 'windows'):
sys.exit('Unknown system requested: {}'.format(original_system))
build_args.append('--systems={}'.format(system))
else:
# No flag provided. Use the current OS.
if platform.system() == 'Darwin':
system = 'darwin-x86'
elif platform.system() == 'Linux':
system = 'linux-x86'
else:
sys.exit('Unknown build host: {}'.format(platform.system()))
build_args.append(os.path.join(build_top, 'toolchain'))
DEFAULT_OUT_DIR = os.path.join(build_top, 'out/ndk')
out_dir = os.path.realpath(os.getenv('DIST_DIR', DEFAULT_OUT_DIR))
invoke_build('dev-cleanup.sh')
build_ndk(out_dir, system, build_args)
# TODO(danalbert): Make --package work for Windows and Darwin.
# This doesn't work as-is because we don't build the target components on
# those platforms. Darwin can be fixed by flipping the switch (but then
# builds take longer without needing to), but Windows would actually be a
# two step process (first Linux, then Windows) because --try-64 is required
# for Linux but must not be supplied for Windows.
if args.package and system == 'linux-x86':
package_ndk(args.release, system, out_dir, build_args)
if __name__ == '__main__':
main()