xref: /aosp_15_r20/frameworks/rs/build_rs.py (revision e1eccf28f96817838ad6867f7f39d2351ec11f56)
1*e1eccf28SAndroid Build Coastguard Worker#!/usr/bin/env python
2*e1eccf28SAndroid Build Coastguard Worker#
3*e1eccf28SAndroid Build Coastguard Worker# Copyright (C) 2016 The Android Open Source Project
4*e1eccf28SAndroid Build Coastguard Worker#
5*e1eccf28SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*e1eccf28SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*e1eccf28SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*e1eccf28SAndroid Build Coastguard Worker#
9*e1eccf28SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*e1eccf28SAndroid Build Coastguard Worker#
11*e1eccf28SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*e1eccf28SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*e1eccf28SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*e1eccf28SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*e1eccf28SAndroid Build Coastguard Worker# limitations under the License.
16*e1eccf28SAndroid Build Coastguard Worker#
17*e1eccf28SAndroid Build Coastguard Workerfrom __future__ import print_function
18*e1eccf28SAndroid Build Coastguard Worker
19*e1eccf28SAndroid Build Coastguard Workerimport argparse
20*e1eccf28SAndroid Build Coastguard Workerimport glob
21*e1eccf28SAndroid Build Coastguard Workerimport os
22*e1eccf28SAndroid Build Coastguard Workerimport shutil
23*e1eccf28SAndroid Build Coastguard Workerimport subprocess
24*e1eccf28SAndroid Build Coastguard Workerimport sys
25*e1eccf28SAndroid Build Coastguard Workerimport re
26*e1eccf28SAndroid Build Coastguard Worker
27*e1eccf28SAndroid Build Coastguard Worker
28*e1eccf28SAndroid Build Coastguard WorkerTHIS_DIR = os.path.realpath(os.path.dirname(__file__))
29*e1eccf28SAndroid Build Coastguard WorkerORIG_ENV = dict(os.environ)
30*e1eccf28SAndroid Build Coastguard Worker
31*e1eccf28SAndroid Build Coastguard Worker
32*e1eccf28SAndroid Build Coastguard Workerdef android_path(*args):
33*e1eccf28SAndroid Build Coastguard Worker    out_dir = os.path.realpath(os.path.join(THIS_DIR, '../..', *args))
34*e1eccf28SAndroid Build Coastguard Worker    return out_dir
35*e1eccf28SAndroid Build Coastguard Worker
36*e1eccf28SAndroid Build Coastguard Worker
37*e1eccf28SAndroid Build Coastguard Workerdef build_path(*args):
38*e1eccf28SAndroid Build Coastguard Worker    # Our multistage build directories will be placed under OUT_DIR if it is in
39*e1eccf28SAndroid Build Coastguard Worker    # the environment. By default they will be placed under
40*e1eccf28SAndroid Build Coastguard Worker    # $ANDROID_BUILD_TOP/out.
41*e1eccf28SAndroid Build Coastguard Worker    top_out = ORIG_ENV.get('OUT_DIR', android_path('out'))
42*e1eccf28SAndroid Build Coastguard Worker    if not os.path.isabs(top_out):
43*e1eccf28SAndroid Build Coastguard Worker        top_out = os.path.realpath(top_out)
44*e1eccf28SAndroid Build Coastguard Worker    out_dir = os.path.join(top_out, *args)
45*e1eccf28SAndroid Build Coastguard Worker    return out_dir
46*e1eccf28SAndroid Build Coastguard Worker
47*e1eccf28SAndroid Build Coastguard Worker
48*e1eccf28SAndroid Build Coastguard Workerdef install_file(src, dst):
49*e1eccf28SAndroid Build Coastguard Worker    print('Copying ' + src)
50*e1eccf28SAndroid Build Coastguard Worker    shutil.copy2(src, dst)
51*e1eccf28SAndroid Build Coastguard Worker
52*e1eccf28SAndroid Build Coastguard Worker
53*e1eccf28SAndroid Build Coastguard Workerdef install_directory(src, dst):
54*e1eccf28SAndroid Build Coastguard Worker    print('Copying ' + src)
55*e1eccf28SAndroid Build Coastguard Worker    shutil.copytree(src, dst)
56*e1eccf28SAndroid Build Coastguard Worker
57*e1eccf28SAndroid Build Coastguard Worker
58*e1eccf28SAndroid Build Coastguard Workerdef build(out_dir):
59*e1eccf28SAndroid Build Coastguard Worker    if sys.platform == 'darwin':
60*e1eccf28SAndroid Build Coastguard Worker        products = ('aosp_arm',)
61*e1eccf28SAndroid Build Coastguard Worker    else:
62*e1eccf28SAndroid Build Coastguard Worker        products = (
63*e1eccf28SAndroid Build Coastguard Worker            'aosp_arm',
64*e1eccf28SAndroid Build Coastguard Worker            'aosp_arm64',
65*e1eccf28SAndroid Build Coastguard Worker            # 'aosp_mips',
66*e1eccf28SAndroid Build Coastguard Worker            # 'aosp_mips64',
67*e1eccf28SAndroid Build Coastguard Worker            'aosp_x86',
68*e1eccf28SAndroid Build Coastguard Worker            'aosp_x86_64',
69*e1eccf28SAndroid Build Coastguard Worker        )
70*e1eccf28SAndroid Build Coastguard Worker    for product in products:
71*e1eccf28SAndroid Build Coastguard Worker        build_product(out_dir, product)
72*e1eccf28SAndroid Build Coastguard Worker
73*e1eccf28SAndroid Build Coastguard Worker
74*e1eccf28SAndroid Build Coastguard Workerdef build_product(out_dir, product):
75*e1eccf28SAndroid Build Coastguard Worker    env = dict(ORIG_ENV)
76*e1eccf28SAndroid Build Coastguard Worker    env['FORCE_BUILD_LLVM_COMPONENTS'] = 'true'
77*e1eccf28SAndroid Build Coastguard Worker    env['FORCE_BUILD_RS_COMPAT'] = 'true'
78*e1eccf28SAndroid Build Coastguard Worker    env['OUT_DIR'] = out_dir
79*e1eccf28SAndroid Build Coastguard Worker    env['SKIP_LLVM_TESTS'] = 'true'
80*e1eccf28SAndroid Build Coastguard Worker    env['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true'
81*e1eccf28SAndroid Build Coastguard Worker    env['TARGET_BUILD_VARIANT'] = 'userdebug'
82*e1eccf28SAndroid Build Coastguard Worker    env['TARGET_PRODUCT'] = product
83*e1eccf28SAndroid Build Coastguard Worker
84*e1eccf28SAndroid Build Coastguard Worker    if sys.platform == 'darwin':
85*e1eccf28SAndroid Build Coastguard Worker        targets = [
86*e1eccf28SAndroid Build Coastguard Worker            'llvm-rs-cc',
87*e1eccf28SAndroid Build Coastguard Worker            'bcc_compat',
88*e1eccf28SAndroid Build Coastguard Worker        ]
89*e1eccf28SAndroid Build Coastguard Worker    else:
90*e1eccf28SAndroid Build Coastguard Worker        targets = [
91*e1eccf28SAndroid Build Coastguard Worker            # PHONY target specified in frameworks/rs/Android.mk.
92*e1eccf28SAndroid Build Coastguard Worker            'rs-prebuilts-full',
93*e1eccf28SAndroid Build Coastguard Worker            # We have to explicitly specify the jar for JACK to build.
94*e1eccf28SAndroid Build Coastguard Worker            android_path('out/target/common/obj/JAVA_LIBRARIES/' +
95*e1eccf28SAndroid Build Coastguard Worker                'android-support-v8-renderscript_intermediates/classes.jar')
96*e1eccf28SAndroid Build Coastguard Worker        ]
97*e1eccf28SAndroid Build Coastguard Worker    subprocess.check_call(
98*e1eccf28SAndroid Build Coastguard Worker        ['build/soong/soong_ui.bash', '--make-mode'] + targets, cwd=android_path(), env=env)
99*e1eccf28SAndroid Build Coastguard Worker
100*e1eccf28SAndroid Build Coastguard Worker
101*e1eccf28SAndroid Build Coastguard Workerdef package_toolchain(build_dir, build_name, host, dist_dir):
102*e1eccf28SAndroid Build Coastguard Worker    package_name = 'renderscript-' + build_name
103*e1eccf28SAndroid Build Coastguard Worker    install_host_dir = build_path('install', host)
104*e1eccf28SAndroid Build Coastguard Worker    install_dir = os.path.join(install_host_dir, package_name)
105*e1eccf28SAndroid Build Coastguard Worker
106*e1eccf28SAndroid Build Coastguard Worker    # Remove any previously installed toolchain so it doesn't pollute the
107*e1eccf28SAndroid Build Coastguard Worker    # build.
108*e1eccf28SAndroid Build Coastguard Worker    if os.path.exists(install_host_dir):
109*e1eccf28SAndroid Build Coastguard Worker        shutil.rmtree(install_host_dir)
110*e1eccf28SAndroid Build Coastguard Worker
111*e1eccf28SAndroid Build Coastguard Worker    install_toolchain(build_dir, install_dir, host)
112*e1eccf28SAndroid Build Coastguard Worker
113*e1eccf28SAndroid Build Coastguard Worker    tarball_name = package_name + '-' + host
114*e1eccf28SAndroid Build Coastguard Worker    package_path = os.path.join(dist_dir, tarball_name) + '.tar.bz2'
115*e1eccf28SAndroid Build Coastguard Worker    print('Packaging ' + package_path)
116*e1eccf28SAndroid Build Coastguard Worker    args = [
117*e1eccf28SAndroid Build Coastguard Worker        'tar', '-cjC', install_host_dir, '-f', package_path, package_name
118*e1eccf28SAndroid Build Coastguard Worker    ]
119*e1eccf28SAndroid Build Coastguard Worker    subprocess.check_call(args)
120*e1eccf28SAndroid Build Coastguard Worker
121*e1eccf28SAndroid Build Coastguard Worker
122*e1eccf28SAndroid Build Coastguard Workerdef install_toolchain(build_dir, install_dir, host):
123*e1eccf28SAndroid Build Coastguard Worker    install_built_host_files(build_dir, install_dir, host)
124*e1eccf28SAndroid Build Coastguard Worker    install_clang_headers(build_dir, install_dir, host)
125*e1eccf28SAndroid Build Coastguard Worker    if not host.startswith('darwin'):
126*e1eccf28SAndroid Build Coastguard Worker        install_built_device_files(build_dir, install_dir, host)
127*e1eccf28SAndroid Build Coastguard Worker    install_license_files(install_dir)
128*e1eccf28SAndroid Build Coastguard Worker    # We need to package libwinpthread-1.dll for Windows. This is explicitly
129*e1eccf28SAndroid Build Coastguard Worker    # linked whenever pthreads is used, and the build system doesn't allow
130*e1eccf28SAndroid Build Coastguard Worker    # us to link just that library statically (ldflags are stripped out
131*e1eccf28SAndroid Build Coastguard Worker    # of ldlibs and vice-versa).
132*e1eccf28SAndroid Build Coastguard Worker    # Bug: http://b/34273721
133*e1eccf28SAndroid Build Coastguard Worker    if host.startswith('windows'):
134*e1eccf28SAndroid Build Coastguard Worker        install_winpthreads(install_dir)
135*e1eccf28SAndroid Build Coastguard Worker
136*e1eccf28SAndroid Build Coastguard Worker
137*e1eccf28SAndroid Build Coastguard Workerdef install_winpthreads(install_dir):
138*e1eccf28SAndroid Build Coastguard Worker      """Installs the winpthreads runtime to the Windows bin directory."""
139*e1eccf28SAndroid Build Coastguard Worker      lib_name = 'libwinpthread-1.dll'
140*e1eccf28SAndroid Build Coastguard Worker      mingw_dir = android_path(
141*e1eccf28SAndroid Build Coastguard Worker          'prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8')
142*e1eccf28SAndroid Build Coastguard Worker      # RenderScript NDK toolchains for Windows only contains 32-bit binaries.
143*e1eccf28SAndroid Build Coastguard Worker      lib_path = os.path.join(mingw_dir, 'x86_64-w64-mingw32/lib32', lib_name)
144*e1eccf28SAndroid Build Coastguard Worker
145*e1eccf28SAndroid Build Coastguard Worker      lib_install = os.path.join(install_dir, 'bin', lib_name)
146*e1eccf28SAndroid Build Coastguard Worker      install_file(lib_path, lib_install)
147*e1eccf28SAndroid Build Coastguard Worker
148*e1eccf28SAndroid Build Coastguard Worker
149*e1eccf28SAndroid Build Coastguard Workerdef install_built_host_files(build_dir, install_dir, host):
150*e1eccf28SAndroid Build Coastguard Worker    is_windows = host.startswith('windows')
151*e1eccf28SAndroid Build Coastguard Worker    is_darwin = host.startswith('darwin-x86')
152*e1eccf28SAndroid Build Coastguard Worker    bin_ext = '.exe' if is_windows else ''
153*e1eccf28SAndroid Build Coastguard Worker
154*e1eccf28SAndroid Build Coastguard Worker    if is_windows:
155*e1eccf28SAndroid Build Coastguard Worker        lib_ext = '.dll'
156*e1eccf28SAndroid Build Coastguard Worker    elif is_darwin:
157*e1eccf28SAndroid Build Coastguard Worker        lib_ext = '.dylib'
158*e1eccf28SAndroid Build Coastguard Worker    else:
159*e1eccf28SAndroid Build Coastguard Worker        lib_ext = '.so'
160*e1eccf28SAndroid Build Coastguard Worker
161*e1eccf28SAndroid Build Coastguard Worker    built_files = [
162*e1eccf28SAndroid Build Coastguard Worker        'bin/llvm-rs-cc' + bin_ext,
163*e1eccf28SAndroid Build Coastguard Worker        'bin/bcc_compat' + bin_ext,
164*e1eccf28SAndroid Build Coastguard Worker    ]
165*e1eccf28SAndroid Build Coastguard Worker
166*e1eccf28SAndroid Build Coastguard Worker    if is_windows:
167*e1eccf28SAndroid Build Coastguard Worker        built_files.extend([
168*e1eccf28SAndroid Build Coastguard Worker            'lib/libbcc' + lib_ext,
169*e1eccf28SAndroid Build Coastguard Worker            'lib/libbcinfo' + lib_ext,
170*e1eccf28SAndroid Build Coastguard Worker            'lib/libclang_android' + lib_ext,
171*e1eccf28SAndroid Build Coastguard Worker            'lib/libLLVM_android' + lib_ext,
172*e1eccf28SAndroid Build Coastguard Worker        ])
173*e1eccf28SAndroid Build Coastguard Worker    else:
174*e1eccf28SAndroid Build Coastguard Worker        built_files.extend([
175*e1eccf28SAndroid Build Coastguard Worker            'lib64/libbcc' + lib_ext,
176*e1eccf28SAndroid Build Coastguard Worker            'lib64/libbcinfo' + lib_ext,
177*e1eccf28SAndroid Build Coastguard Worker            'lib64/libclang_android' + lib_ext,
178*e1eccf28SAndroid Build Coastguard Worker            'lib64/libLLVM_android' + lib_ext,
179*e1eccf28SAndroid Build Coastguard Worker            'lib64/libc++' + lib_ext,
180*e1eccf28SAndroid Build Coastguard Worker        ])
181*e1eccf28SAndroid Build Coastguard Worker
182*e1eccf28SAndroid Build Coastguard Worker    for built_file in built_files:
183*e1eccf28SAndroid Build Coastguard Worker        dirname = os.path.dirname(built_file)
184*e1eccf28SAndroid Build Coastguard Worker        # Put dlls and exes into bin/ for windows.
185*e1eccf28SAndroid Build Coastguard Worker        # Bug: http://b/34273721
186*e1eccf28SAndroid Build Coastguard Worker        if is_windows:
187*e1eccf28SAndroid Build Coastguard Worker            dirname = 'bin'
188*e1eccf28SAndroid Build Coastguard Worker        install_path = os.path.join(install_dir, dirname)
189*e1eccf28SAndroid Build Coastguard Worker        if not os.path.exists(install_path):
190*e1eccf28SAndroid Build Coastguard Worker            os.makedirs(install_path)
191*e1eccf28SAndroid Build Coastguard Worker
192*e1eccf28SAndroid Build Coastguard Worker        built_path = os.path.join(build_dir, 'host', host, built_file)
193*e1eccf28SAndroid Build Coastguard Worker        install_file(built_path, install_path)
194*e1eccf28SAndroid Build Coastguard Worker
195*e1eccf28SAndroid Build Coastguard Worker        file_name = os.path.basename(built_file)
196*e1eccf28SAndroid Build Coastguard Worker
197*e1eccf28SAndroid Build Coastguard Worker        # Only strip bin files (not libs) on darwin.
198*e1eccf28SAndroid Build Coastguard Worker        if not is_darwin or built_file.startswith('bin/'):
199*e1eccf28SAndroid Build Coastguard Worker            subprocess.check_call(
200*e1eccf28SAndroid Build Coastguard Worker                ['strip', os.path.join(install_path, file_name)])
201*e1eccf28SAndroid Build Coastguard Worker
202*e1eccf28SAndroid Build Coastguard Worker
203*e1eccf28SAndroid Build Coastguard Workerdef install_clang_headers(build_dir, install_dir, host):
204*e1eccf28SAndroid Build Coastguard Worker    def should_copy(path):
205*e1eccf28SAndroid Build Coastguard Worker        if os.path.basename(path) in ('Makefile', 'CMakeLists.txt'):
206*e1eccf28SAndroid Build Coastguard Worker            return False
207*e1eccf28SAndroid Build Coastguard Worker        _, ext = os.path.splitext(path)
208*e1eccf28SAndroid Build Coastguard Worker        if ext == '.mk':
209*e1eccf28SAndroid Build Coastguard Worker            return False
210*e1eccf28SAndroid Build Coastguard Worker        return True
211*e1eccf28SAndroid Build Coastguard Worker
212*e1eccf28SAndroid Build Coastguard Worker    headers_src = android_path('external/clang/lib/Headers')
213*e1eccf28SAndroid Build Coastguard Worker    headers_dst = os.path.join(
214*e1eccf28SAndroid Build Coastguard Worker        install_dir, 'clang-include')
215*e1eccf28SAndroid Build Coastguard Worker    os.makedirs(headers_dst)
216*e1eccf28SAndroid Build Coastguard Worker    for header in os.listdir(headers_src):
217*e1eccf28SAndroid Build Coastguard Worker        if not should_copy(header):
218*e1eccf28SAndroid Build Coastguard Worker            continue
219*e1eccf28SAndroid Build Coastguard Worker        install_file(os.path.join(headers_src, header), headers_dst)
220*e1eccf28SAndroid Build Coastguard Worker
221*e1eccf28SAndroid Build Coastguard Worker    install_file(android_path('bionic/libc/include/stdatomic.h'), headers_dst)
222*e1eccf28SAndroid Build Coastguard Worker
223*e1eccf28SAndroid Build Coastguard Worker
224*e1eccf28SAndroid Build Coastguard Workerdef install_built_device_files(build_dir, install_dir, host):
225*e1eccf28SAndroid Build Coastguard Worker    product_to_arch = {
226*e1eccf28SAndroid Build Coastguard Worker        'generic': 'arm',
227*e1eccf28SAndroid Build Coastguard Worker        'generic_arm64': 'arm64',
228*e1eccf28SAndroid Build Coastguard Worker        # 'generic_mips': 'mips',
229*e1eccf28SAndroid Build Coastguard Worker        # 'generic_mips64': 'mips64el',
230*e1eccf28SAndroid Build Coastguard Worker        'generic_x86': 'x86',
231*e1eccf28SAndroid Build Coastguard Worker        'generic_x86_64': 'x86_64',
232*e1eccf28SAndroid Build Coastguard Worker    }
233*e1eccf28SAndroid Build Coastguard Worker
234*e1eccf28SAndroid Build Coastguard Worker    bc_lib = 'librsrt'
235*e1eccf28SAndroid Build Coastguard Worker
236*e1eccf28SAndroid Build Coastguard Worker    static_libs = {
237*e1eccf28SAndroid Build Coastguard Worker        'libRScpp_static',
238*e1eccf28SAndroid Build Coastguard Worker        'libcompiler_rt'
239*e1eccf28SAndroid Build Coastguard Worker    }
240*e1eccf28SAndroid Build Coastguard Worker
241*e1eccf28SAndroid Build Coastguard Worker    shared_libs = {
242*e1eccf28SAndroid Build Coastguard Worker        'libRSSupport',
243*e1eccf28SAndroid Build Coastguard Worker        'libRSSupportIO',
244*e1eccf28SAndroid Build Coastguard Worker        'libblasV8',
245*e1eccf28SAndroid Build Coastguard Worker    }
246*e1eccf28SAndroid Build Coastguard Worker
247*e1eccf28SAndroid Build Coastguard Worker    for product, arch in product_to_arch.items():
248*e1eccf28SAndroid Build Coastguard Worker        lib_dir = os.path.join(install_dir, 'platform', arch)
249*e1eccf28SAndroid Build Coastguard Worker        os.makedirs(lib_dir)
250*e1eccf28SAndroid Build Coastguard Worker
251*e1eccf28SAndroid Build Coastguard Worker        # Copy librsrt_ARCH.bc.
252*e1eccf28SAndroid Build Coastguard Worker        lib_name = bc_lib + '_' + arch + '.bc'
253*e1eccf28SAndroid Build Coastguard Worker        if not host.startswith('windows'):
254*e1eccf28SAndroid Build Coastguard Worker            built_lib = os.path.join(build_dir, 'host', host, 'lib64', lib_name)
255*e1eccf28SAndroid Build Coastguard Worker        else:
256*e1eccf28SAndroid Build Coastguard Worker            built_lib = os.path.join(build_dir, 'host', 'linux-x86', 'lib64', lib_name)
257*e1eccf28SAndroid Build Coastguard Worker        install_file(built_lib, os.path.join(lib_dir, bc_lib + '.bc'))
258*e1eccf28SAndroid Build Coastguard Worker
259*e1eccf28SAndroid Build Coastguard Worker        # Copy static libs and share libs.
260*e1eccf28SAndroid Build Coastguard Worker        product_dir = os.path.join(build_dir, 'target/product', product)
261*e1eccf28SAndroid Build Coastguard Worker        static_lib_dir = os.path.join(product_dir, 'obj/STATIC_LIBRARIES')
262*e1eccf28SAndroid Build Coastguard Worker        shared_lib_dir = os.path.join(product_dir, 'obj/SHARED_LIBRARIES')
263*e1eccf28SAndroid Build Coastguard Worker        for static_lib in static_libs:
264*e1eccf28SAndroid Build Coastguard Worker            built_lib = os.path.join(
265*e1eccf28SAndroid Build Coastguard Worker                static_lib_dir, static_lib + '_intermediates/' + static_lib + '.a')
266*e1eccf28SAndroid Build Coastguard Worker            lib_name = static_lib + '.a'
267*e1eccf28SAndroid Build Coastguard Worker            install_file(built_lib, os.path.join(lib_dir, lib_name))
268*e1eccf28SAndroid Build Coastguard Worker        for shared_lib in shared_libs:
269*e1eccf28SAndroid Build Coastguard Worker            built_lib = os.path.join(
270*e1eccf28SAndroid Build Coastguard Worker                shared_lib_dir, shared_lib + '_intermediates/' + shared_lib + '.so')
271*e1eccf28SAndroid Build Coastguard Worker            lib_name = shared_lib + '.so'
272*e1eccf28SAndroid Build Coastguard Worker            install_file(built_lib, os.path.join(lib_dir, lib_name))
273*e1eccf28SAndroid Build Coastguard Worker
274*e1eccf28SAndroid Build Coastguard Worker    # Copy renderscript-v8.jar.
275*e1eccf28SAndroid Build Coastguard Worker    lib_dir = os.path.join(install_dir, 'platform')
276*e1eccf28SAndroid Build Coastguard Worker    jar_dir = os.path.join(build_dir, 'target/common/obj/JAVA_LIBRARIES/'
277*e1eccf28SAndroid Build Coastguard Worker        'android-support-v8-renderscript_intermediates/classes.jar')
278*e1eccf28SAndroid Build Coastguard Worker    install_file(jar_dir, os.path.join(lib_dir, 'renderscript-v8.jar'))
279*e1eccf28SAndroid Build Coastguard Worker
280*e1eccf28SAndroid Build Coastguard Worker    # Copy RS runtime headers.
281*e1eccf28SAndroid Build Coastguard Worker    headers_dst_base = os.path.join(install_dir, 'platform', 'rs')
282*e1eccf28SAndroid Build Coastguard Worker
283*e1eccf28SAndroid Build Coastguard Worker    headers_src = android_path('frameworks/rs/script_api/include')
284*e1eccf28SAndroid Build Coastguard Worker    headers_dst = os.path.join(headers_dst_base, 'scriptc')
285*e1eccf28SAndroid Build Coastguard Worker    install_directory(headers_src, headers_dst)
286*e1eccf28SAndroid Build Coastguard Worker
287*e1eccf28SAndroid Build Coastguard Worker    # Copy RS C++ API headers.
288*e1eccf28SAndroid Build Coastguard Worker    headers_src = android_path('frameworks/rs/cpp/util')
289*e1eccf28SAndroid Build Coastguard Worker    headers_dst = os.path.join(headers_dst_base, 'cpp/util')
290*e1eccf28SAndroid Build Coastguard Worker    install_directory(headers_src, headers_dst)
291*e1eccf28SAndroid Build Coastguard Worker    install_file(android_path('frameworks/rs/rsDefines.h'), headers_dst_base)
292*e1eccf28SAndroid Build Coastguard Worker    install_file(android_path('frameworks/rs/cpp/RenderScript.h'), os.path.join(headers_dst_base, 'cpp'))
293*e1eccf28SAndroid Build Coastguard Worker    install_file(android_path('frameworks/rs/cpp/rsCppStructs.h'), os.path.join(headers_dst_base, 'cpp'))
294*e1eccf28SAndroid Build Coastguard Worker
295*e1eccf28SAndroid Build Coastguard Worker
296*e1eccf28SAndroid Build Coastguard Workerdef install_license_files(install_dir):
297*e1eccf28SAndroid Build Coastguard Worker    projects = (
298*e1eccf28SAndroid Build Coastguard Worker        'external/clang',
299*e1eccf28SAndroid Build Coastguard Worker        'external/compiler-rt',
300*e1eccf28SAndroid Build Coastguard Worker        'external/llvm',
301*e1eccf28SAndroid Build Coastguard Worker        'frameworks/compile/slang',
302*e1eccf28SAndroid Build Coastguard Worker        'frameworks/compile/libbcc',
303*e1eccf28SAndroid Build Coastguard Worker        # 'frameworks/rs', # No notice license file found.
304*e1eccf28SAndroid Build Coastguard Worker    )
305*e1eccf28SAndroid Build Coastguard Worker
306*e1eccf28SAndroid Build Coastguard Worker    notices = []
307*e1eccf28SAndroid Build Coastguard Worker    for project in projects:
308*e1eccf28SAndroid Build Coastguard Worker        project_path = android_path(project)
309*e1eccf28SAndroid Build Coastguard Worker        license_pattern = os.path.join(project_path, 'MODULE_LICENSE_*')
310*e1eccf28SAndroid Build Coastguard Worker        for license_file in glob.glob(license_pattern):
311*e1eccf28SAndroid Build Coastguard Worker            install_file(license_file, install_dir)
312*e1eccf28SAndroid Build Coastguard Worker        with open(os.path.join(project_path, 'NOTICE')) as notice_file:
313*e1eccf28SAndroid Build Coastguard Worker            notices.append(notice_file.read())
314*e1eccf28SAndroid Build Coastguard Worker    with open(os.path.join(install_dir, 'NOTICE'), 'w') as notice_file:
315*e1eccf28SAndroid Build Coastguard Worker        notice_file.write('\n'.join(notices))
316*e1eccf28SAndroid Build Coastguard Worker
317*e1eccf28SAndroid Build Coastguard Worker
318*e1eccf28SAndroid Build Coastguard Workerdef parse_args():
319*e1eccf28SAndroid Build Coastguard Worker    parser = argparse.ArgumentParser()
320*e1eccf28SAndroid Build Coastguard Worker
321*e1eccf28SAndroid Build Coastguard Worker    parser.add_argument(
322*e1eccf28SAndroid Build Coastguard Worker        '--build-name', default='dev', help='Release name for the package.')
323*e1eccf28SAndroid Build Coastguard Worker
324*e1eccf28SAndroid Build Coastguard Worker    return parser.parse_args()
325*e1eccf28SAndroid Build Coastguard Worker
326*e1eccf28SAndroid Build Coastguard Worker
327*e1eccf28SAndroid Build Coastguard Workerdef main():
328*e1eccf28SAndroid Build Coastguard Worker    args = parse_args()
329*e1eccf28SAndroid Build Coastguard Worker
330*e1eccf28SAndroid Build Coastguard Worker    if sys.platform.startswith('linux'):
331*e1eccf28SAndroid Build Coastguard Worker        hosts = ['linux-x86', 'windows-x86']
332*e1eccf28SAndroid Build Coastguard Worker    elif sys.platform == 'darwin':
333*e1eccf28SAndroid Build Coastguard Worker        hosts = ['darwin-x86']
334*e1eccf28SAndroid Build Coastguard Worker    else:
335*e1eccf28SAndroid Build Coastguard Worker        raise RuntimeError('Unsupported host: {}'.format(sys.platform))
336*e1eccf28SAndroid Build Coastguard Worker
337*e1eccf28SAndroid Build Coastguard Worker    out_dir = build_path()
338*e1eccf28SAndroid Build Coastguard Worker    build(out_dir=out_dir)
339*e1eccf28SAndroid Build Coastguard Worker
340*e1eccf28SAndroid Build Coastguard Worker    dist_dir = ORIG_ENV.get('DIST_DIR', out_dir)
341*e1eccf28SAndroid Build Coastguard Worker    for host in hosts:
342*e1eccf28SAndroid Build Coastguard Worker        package_toolchain(out_dir, args.build_name, host, dist_dir)
343*e1eccf28SAndroid Build Coastguard Worker
344*e1eccf28SAndroid Build Coastguard Worker
345*e1eccf28SAndroid Build Coastguard Workerif __name__ == '__main__':
346*e1eccf28SAndroid Build Coastguard Worker    main()
347