-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out common standalone toolchain test code.
Test: ./validate.py --filter standalone_toolchain* Bug: android/ndk#310 Change-Id: Ie65713b0cbad177b1531ebf355e6df9baafab458
- Loading branch information
Showing
4 changed files
with
89 additions
and
122 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# | ||
# 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. | ||
# | ||
import logging | ||
import os | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
|
||
import build.lib.build_support | ||
|
||
|
||
def logger(): | ||
return logging.getLogger(__name__) | ||
|
||
|
||
def call_output(cmd, *args, **kwargs): | ||
logger().info('COMMAND: ' + ' '.join(cmd)) | ||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, *args, **kwargs) | ||
out, _ = proc.communicate() | ||
return proc.returncode, out | ||
|
||
|
||
def make_standalone_toolchain(arch, api, extra_args, install_dir): | ||
ndk_dir = os.environ['NDK'] | ||
make_standalone_toolchain_path = os.path.join( | ||
ndk_dir, 'build/tools/make_standalone_toolchain.py') | ||
|
||
cmd = [make_standalone_toolchain_path, '--force', | ||
'--install-dir=' + install_dir, '--arch=' + arch, | ||
'--api={}'.format(api)] + extra_args | ||
|
||
rc, out = call_output(cmd) | ||
return rc == 0, out | ||
|
||
|
||
def test_standalone_toolchain(arch, toolchain, install_dir, test_source): | ||
if toolchain == '4.9': | ||
triple = build.lib.build_support.arch_to_triple(arch) | ||
# x86 toolchain names are dumb: http://b/25800583 | ||
if arch == 'x86': | ||
triple = 'i686-linux-android' | ||
compiler_name = triple + '-g++' | ||
elif toolchain == 'clang': | ||
compiler_name = 'clang++' | ||
|
||
compiler = os.path.join(install_dir, 'bin', compiler_name) | ||
cmd = [compiler, test_source, '-Wl,--no-undefined', '-Wl,--fatal-warnings'] | ||
rc, out = call_output(cmd) | ||
return rc == 0, out | ||
|
||
|
||
def run_test(abi, api, toolchain, test_source, extra_args): | ||
arch = build.lib.build_support.abi_to_arch(abi) | ||
|
||
install_dir = tempfile.mkdtemp() | ||
try: | ||
success, out = make_standalone_toolchain( | ||
arch, api, extra_args, install_dir) | ||
if not success: | ||
return success, out | ||
return test_standalone_toolchain( | ||
arch, toolchain, install_dir, test_source) | ||
finally: | ||
shutil.rmtree(install_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters