Skip to content

[android] Modify test scripts for aarch64 and modern NDKs. #19503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ foreach(SDK ${SWIFT_SDKS})
${PYTHON_EXECUTABLE} "${SWIFT_SOURCE_DIR}/utils/android/adb_push_built_products.py"
--ndk "${SWIFT_ANDROID_NDK_PATH}"
--destination "${SWIFT_ANDROID_DEPLOY_DEVICE_PATH}"
--destination-arch "${ARCH}"
# Build products like libswiftCore.so.
"${SWIFTLIB_DIR}/android"
# These two directories may contain the same libraries,
# but upload both to device just in case. Duplicates will be
# overwritten, and uploading doesn't take very long anyway.
"${SWIFT_ANDROID_${ARCH}_ICU_UC}"
"${SWIFT_ANDROID_${ARCH}_ICU_I18N}")
"${SWIFT_ANDROID_${ARCH}_ICU_I18N}"
"${SWIFT_ANDROID_${ARCH}_ICU_DATA}")
endif()
add_custom_target("upload-stdlib${VARIANT_SUFFIX}"
${command_upload_stdlib}
Expand Down
70 changes: 49 additions & 21 deletions test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -930,39 +930,68 @@ elif run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'windows-cygnus', 'wi
"clang++ -target %s %s" %
(config.variant_triple, clang_mcp_opt))
config.target_ld = "ld -L%r" % (make_path(test_resource_dir, config.target_sdk_name))
elif run_os == 'linux-androideabi':
elif run_os == 'linux-androideabi' or run_os == 'linux-android':
def get_architecture_value(**kwargs):
result = kwargs[run_cpu]
if result is None:
if run_cpu == "armv7s" or run_cpu == "armv7k":
result = kwargs["armv7"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite this as: if run_cpu.startswith('armv7'): return kwargs["armv7"]

elif run_cpu == "arm64":
result = kwards["aarch64"]
return result

ndk_platform_tuple = get_architecture_value(armv7="armeabi-v7a",
aarch64="arm64-v8a")
ndk_platform_triple = get_architecture_value(armv7="arm-linux-androideabi",
aarch64="aarch64-linux-android")
toolchain_directory_name = "{}-{}".format(ndk_platform_triple, config.android_ndk_gcc_version)
tools_directory = make_path(config.android_ndk_path, "toolchains",
toolchain_directory_name, "prebuilt", "linux-x86_64",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linux-x86_64 should really be based on the build (e.g. building on Windows, Darwin, or Linux)

ndk_platform_triple, "bin")
lit_config.note("Testing Android " + config.variant_triple)
config.target_object_format = "elf"
config.target_shared_library_prefix = 'lib'
config.target_shared_library_suffix = ".so"
config.target_swiftmodule_name = get_architecture_value(armv7="arm.swiftmodule",
aarch64="arm64.swiftmodule")
config.target_swiftdoc_name = get_architecture_value(armv7="arm.swiftdoc",
aarch64="arm64.swiftdoc")
config.target_runtime = "native"
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
config.target_sdk_name = "android"
android_linker_opt = "-L {libcxx} -L {libgcc}".format(
android_link_paths_opt = "-L {libcxx} -L {libgcc}".format(
libcxx=make_path(config.android_ndk_path,
"sources", "cxx-stl", "llvm-libc++", "libs",
"armeabi-v7a"),
"sources", "cxx-stl", "llvm-libc++", "libs", ndk_platform_tuple),
libgcc=make_path(config.android_ndk_path,
"toolchains",
"arm-linux-androideabi-{}".format(config.android_ndk_gcc_version),
"prebuilt", "linux-x86_64", "lib", "gcc",
"arm-linux-androideabi",
"toolchains", toolchain_directory_name, "prebuilt",
"linux-x86_64", "lib", "gcc", ndk_platform_triple,
"{}.x".format(config.android_ndk_gcc_version)))
# Since NDK r14 the headers are unified under $NDK_PATH/sysroot, so the -sdk
# switch is not enough. Additionally we have to include both the unified
# sysroot, and the architecture sysroot.
android_include_paths_opt = "-I {sysroot} -I {sysroot_arch}".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should use -isystem here instead as we do not want to see any warnings from the NDK, its the system.

sysroot=make_path(config.android_ndk_path, "sysroot", "usr", "include"),
sysroot_arch=make_path(config.android_ndk_path, "sysroot", "usr",
"include", ndk_platform_triple))
config.target_build_swift = (
'%s -target %s -sdk %r %s -Xlinker -pie %s %s %s %s %s'
% (config.swiftc, config.variant_triple, config.variant_sdk,
android_linker_opt, resource_dir_opt, mcp_opt,
config.swift_test_options,
'%s -target %s -sdk %r -tools-directory %r %s %s '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the .format version here?

'-use-ld=%s %s %s %s %s %s'
% (config.swiftc,
config.variant_triple, config.variant_sdk,
tools_directory, android_include_paths_opt, android_link_paths_opt,
config.android_linker_name,
resource_dir_opt, mcp_opt, config.swift_test_options,
config.swift_driver_test_options, swift_execution_tests_extra_flags))
config.target_codesign = "echo"
config.target_build_swift_dylib = (
"%s -parse-as-library -emit-library -o '\\1'"
% (config.target_build_swift))
config.target_add_rpath = r'-Xlinker -rpath -Xlinker \1'
config.target_swift_frontend = (
'%s -frontend -target %s -sdk %r %s %s %s %s'
'%s -frontend -target %s -sdk %r %s %s %s %s %s %s'
% (config.swift, config.variant_triple, config.variant_sdk,
android_linker_opt, resource_dir_opt, mcp_opt,
android_include_paths_opt, android_link_paths_opt, resource_dir_opt,
mcp_opt, config.swift_test_options,
config.swift_frontend_test_options))
subst_target_swift_frontend_mock_sdk = config.target_swift_frontend
subst_target_swift_frontend_mock_sdk_after = ""
Expand All @@ -978,19 +1007,18 @@ elif run_os == 'linux-androideabi':
subst_target_swift_ide_test_mock_sdk = config.target_swift_ide_test
subst_target_swift_ide_test_mock_sdk_after = ""
config.target_swiftc_driver = (
"%s -target %s -sdk %r %s %s %s" %
"%s -target %s -sdk %r -tools-directory %s %s %s %s -use-ld=%s" %
(config.swiftc, config.variant_triple, config.variant_sdk,
android_linker_opt, resource_dir_opt, mcp_opt))
tools_directory, android_link_paths_opt, resource_dir_opt, mcp_opt,
config.android_linker_name))
config.target_swift_modulewrap = (
'%s -modulewrap -target %s' %
(config.swiftc, config.variant_triple))
config.target_clang = (
"clang++ -target %s %s" %
(config.variant_triple, clang_mcp_opt))
"clang++ -target %s %s %s" %
(config.variant_triple, clang_mcp_opt, android_include_paths_opt))
config.target_ld = "{} -L{}".format(
make_path(config.android_ndk_path, 'toolchains',
'arm-linux-androideabi-{}'.format(config.android_ndk_gcc_version),
'prebuilt', 'linux-x86_64', 'arm-linux-androideabi', 'bin'),
tools_directory,
make_path(test_resource_dir, config.target_sdk_name))
# The Swift interpreter is not available when targeting Android.
config.available_features.remove('swift_interpreter')
Expand Down
6 changes: 6 additions & 0 deletions test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ if "@SWIFT_BUILD_SYNTAXPARSERLIB@" == "TRUE":
if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE":
config.available_features.add('sourcekit')

if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE":
config.android_linker_name = "lld"
else:
# even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android
config.android_linker_name = "gold"

# Let the main config do the real work.
if config.test_exec_root is None:
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
Expand Down
7 changes: 6 additions & 1 deletion validation-test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ if "@CMAKE_GENERATOR@" == "Xcode":

config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@")

if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE":
config.android_linker_name = "lld"
else:
# even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android
config.android_linker_name = "gold"

# Let the main config do the real work.
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
lit_config.load_config(config, "@SWIFT_SOURCE_DIR@/validation-test/lit.cfg")