提交 fe213039 编写于 作者: C Caoruihong

chore: support prebuild sysroot

support build prebuilts before build ohos,
so that sysroot can be auto generated now.
Signed-off-by: NCaoruihong <crh.cao@huawei.com>
Change-Id: I6e5dc06cb3c4767904eaea4fd729544e92f15374
上级 ca40810f
......@@ -20,6 +20,10 @@ version_info = [ "VERSION=\"$ohos_version\"",
"BUILD_TIME=\"$ohos_build_datetime\""]
write_file("$root_build_dir/etc/version-info", version_info)
group("prebuilts") {
public_deps = [ "//prebuilts/lite/sysroot" ]
}
group("ohos") {
deps = []
if (ohos_build_target == "") {
......
......@@ -12,13 +12,7 @@
# limitations under the License.
config("cpu_arch") {
cflags = []
if (board_arch != "") {
cflags += [ "-march=$board_arch" ]
}
if (board_cpu != "") {
cflags += [ "-mcpu=$board_cpu" ]
}
cflags = target_arch_cflags
cflags_cc = cflags
ldflags = cflags
}
......@@ -112,56 +106,13 @@ config("pie_executable_config") {
ldflags = [ "-pie" ]
}
clang_dir = ""
target_kernel = ""
if(ohos_current_toolchain == "ohos_clang") {
if (ohos_build_compiler_dir != "") {
clang_dir = rebase_path("${ohos_build_compiler_dir}")
}
if (ohos_kernel_type == "liteos_a") {
target_kernel = "arm-liteos"
} else if (ohos_kernel_type == "linux") {
target_kernel = "arm-linux-ohosmusl"
}
copy("ohos_clang_runtime") {
sources = [
"${clang_dir}/lib/${target_kernel}/c++/libc++.so",
"${ohos_root_path}prebuilts/lite/sysroot/usr/lib/${target_kernel}/libc.so",
]
outputs = [ "$root_out_dir/libs/{{source_file_part}}" ]
}
}
config("ohos_clang") {
include_dirs = [
"${clang_dir}/include/c++/v1",
"//prebuilts/lite/sysroot/usr/include/${target_kernel}",
]
cflags = [
"--target=${target_kernel}",
"--sysroot=${ohos_root_path}prebuilts/lite/sysroot",
]
cflags_cc = cflags
ldflags = cflags
if (ohos_kernel_type == "linux") {
defines = [
"_LIBCPP_HAS_MUSL_LIBC",
"__BUILD_LINUX_WITH_CLANG",
"_LIBCPP_HAS_MUSL_LIBC",
"__BUILD_LINUX_WITH_CLANG",
]
}
ldflags += [
"-L${clang_dir}/lib/${target_kernel}/c++",
"-L${ohos_root_path}prebuilts/lite/sysroot/usr/lib/${target_kernel}",
"-L${clang_dir}/lib/clang/current/lib/${target_kernel}",
"-lclang_rt.builtins",
"-lc",
"-lc++",
"-lc++abi",
"--sysroot=${ohos_root_path}prebuilts/lite/sysroot",
]
}
config("release") {
......@@ -200,11 +151,6 @@ config("board_config") {
include_dirs = []
defines = []
cflags += board_cflags
if (board_configed_sysroot != "") {
cflags += [ "--sysroot=${board_configed_sysroot}" ]
cflags_cc += [ "--sysroot=${board_configed_sysroot}" ]
ldflags += [ "--sysroot=${board_configed_sysroot}" ]
}
cflags_cc += board_cxx_flags
ldflags += board_ld_flags
include_dirs += board_include_dirs
......
......@@ -21,6 +21,25 @@ if (target_cpu == "") {
target_cpu = board_cpu
}
target_arch_cflags = board_cflags + board_ld_flags
if (board_arch != "") {
target_arch_cflags += [ "-march=$board_arch" ]
}
if (board_cpu != "") {
target_arch_cflags += [ "-mcpu=$board_cpu" ]
}
arch = "arm"
if (ohos_kernel_type == "liteos_a") {
target_triple = "$arch-liteos"
} else if (ohos_kernel_type == "linux") {
target_triple = "$arch-linux-ohosmusl"
}
if (defined(board_configed_sysroot) && board_configed_sysroot != "") {
ohos_current_sysroot = board_configed_sysroot
}
# Only gcc available for liteos_m.
if (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "linux") {
use_board_toolchain = true
......@@ -33,16 +52,12 @@ if (host_os == "win") {
# Set current toolchain with to board configuration.
if (board_toolchain != "" && use_board_toolchain) {
ohos_current_toolchain = board_toolchain
ohos_current_toolchain_type = board_toolchain_type
ohos_build_compiler = ohos_current_toolchain_type
ohos_build_compiler = board_toolchain_type
if (board_toolchain_path != "") {
compile_prefix = "${board_toolchain_path}/${board_toolchain_prefix}"
} else {
compile_prefix = "${board_toolchain_prefix}"
}
ohos_current_toolchain_prefix = compile_prefix
ohos_current_sysroot = board_configed_sysroot
set_default_toolchain("//build/lite/toolchain:${board_toolchain}")
if (board_toolchain_type == "gcc") {
ohos_current_cc_command = "${compile_prefix}gcc$toolchain_cmd_suffix"
......@@ -55,27 +70,23 @@ if (board_toolchain != "" && use_board_toolchain) {
ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix"
ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix"
ohos_current_ar_command = "${compile_prefix}llvm-ar$toolchain_cmd_suffix"
ohos_current_as_command = ohos_current_cc_command
ohos_current_ld_command = ohos_current_cc_command
ohos_current_strip_command = "$compile_prefix/llvm-objcopy$toolchain_cmd_suffix --strip-all"
default_target_configs = [ "//build/lite/config:clang_opt" ]
}
# Overwrite ld cmd by customed cmd.
if(defined(board_customed_ld_cmd)) {
if(defined(board_customed_ld_cmd) && board_customed_ld_cmd != "") {
ohos_current_ld_command = board_customed_ld_cmd
}
} else {
# OHOS default toolchain: ohos_clang
ohos_current_toolchain = "ohos_clang"
# OHOS default toolchain
ohos_build_compiler = "clang"
hos_build_compiler = "clang"
ohos_clang_toolchain_dir = rebase_path("${ohos_build_compiler_dir}/bin")
compile_prefix = rebase_path("${ohos_build_compiler_dir}/bin")
ohos_current_cc_command = "${compile_prefix}/clang$toolchain_cmd_suffix"
ohos_current_cxx_command = "${compile_prefix}/clang++$toolchain_cmd_suffix"
ohos_current_ar_command = "${compile_prefix}/llvm-ar$toolchain_cmd_suffix"
ohos_current_as_command = ohos_current_cc_command
ohos_current_ld_command = ohos_current_cc_command
ohos_current_ld_command = ohos_current_cxx_command
ohos_current_strip_command =
"$ohos_clang_toolchain_dir/llvm-objcopy$toolchain_cmd_suffix --strip-all"
set_default_toolchain("//build/lite/toolchain:linux_x86_64_ohos_clang")
......@@ -142,3 +153,56 @@ set_defaults("shared_library") {
set_defaults("source_set") {
configs = default_target_configs
}
template("executable") {
executable(target_name) {
forward_variables_from(invoker, "*")
if (!defined(invoker.deps)) {
deps = [ "//build/lite:prebuilts" ]
} else {
deps += [ "//build/lite:prebuilts" ]
}
}
}
template("static_library") {
static_library(target_name) {
forward_variables_from(invoker, "*")
if (!defined(invoker.deps)) {
deps = [ "//build/lite:prebuilts" ]
} else {
deps += [ "//build/lite:prebuilts" ]
}
}
}
template("shared_library") {
shared_library(target_name) {
forward_variables_from(invoker, "*")
if (!defined(invoker.deps)) {
deps = [ "//build/lite:prebuilts" ]
} else {
deps += [ "//build/lite:prebuilts" ]
}
}
}
template("source_set") {
source_set(target_name) {
forward_variables_from(invoker, "*")
if (!defined(invoker.deps)) {
deps = [ "//build/lite:prebuilts" ]
} else {
deps += [ "//build/lite:prebuilts" ]
}
}
}
template("action") {
action(target_name) {
forward_variables_from(invoker, "*")
if (!defined(invoker.deps) || invoker.deps == []) {
deps = [ "//build/lite:prebuilts" ]
}
}
}
......@@ -73,8 +73,6 @@ template("lite_library") {
template("lite_component") {
assert(defined(invoker.features), "Component features is required.")
forward_variables_from(invoker, "*")
if (!defined(invoker.target_type)) {
target_type = "group"
} else if (invoker.target_type == "static_library") {
......@@ -87,6 +85,8 @@ template("lite_component") {
target(target_type, target_name) {
deps = []
forward_variables_from(invoker, "*")
# add component deps
if (defined(invoker.deps)) {
deps += invoker.deps
......
......@@ -11,226 +11,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/subsystem/aafwk/path.gni")
declare_args() {
ohos_test_args = ""
}
test_target_type = "executable"
if(ohos_test_args == "notest") {
test_target_type = "group"
}
# liteos c test template
test_common_include_dirs = [ "//third_party/googletest/googletest/include" ]
test_include_dirs = [
"//utils/native/lite/include",
"//kernel/liteos_a/kernel/include",
"//third_party/bounds_checking_function/include",
]
archive_dir_name = "test_info"
template("unittest") {
_output_dir = ""
if (defined(invoker.output_extension)) {
output_extension = invoker.output_extension
}
if (defined(invoker.output_dir)) {
_output_dir = invoker.output_dir
} else {
_output_dir = "${root_out_dir}/${archive_dir_name}/unittest"
}
# generate module list file in gn stage
# format like: unittest("componentName_test_xx")
list_tmp = string_split(target_name, "_test")
_part_name = list_tmp[0]
_module_list_file = string_join("",
[
root_out_dir,
"/${archive_dir_name}/module_list_files/",
_part_name,
"/",
_part_name,
"/",
target_name,
".mlf",
])
_sources_file_search_root_dir = string_join("",
[
root_out_dir,
"/${archive_dir_name}/gen",
])
_sources = ""
foreach(s, invoker.sources) {
_sources += s + ","
}
_arguments = [
"--target",
target_name,
"--target_label",
get_label_info(target_name, "label_with_toolchain"),
"--source_dir",
rebase_path(get_label_info(target_name, "dir"), root_out_dir),
"--test_type",
"unittest",
"--output_dir",
rebase_path(_output_dir),
"--module_list_file",
rebase_path(_module_list_file),
"--sources_file_search_root_dir",
rebase_path(_sources_file_search_root_dir),
"--sources",
_sources,
]
_gen_module_list_script = "//build/lite/testfwk/gen_module_list_files.py"
exec_script(_gen_module_list_script, _arguments)
target(test_target_type, target_name) {
if (ohos_test_args == "notest") {
not_needed(invoker, "*")
}
if (defined(invoker.output_dir)) {
output_dir = invoker.output_dir
}
if (defined(invoker.sources)) {
sources = invoker.sources
}
if (defined(invoker.include_dirs)) {
include_dirs = invoker.include_dirs
} else {
include_dirs = []
}
include_dirs += test_common_include_dirs
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
include_dirs += test_include_dirs
}
if (defined(invoker.deps)) {
deps = invoker.deps
} else {
deps = []
}
if (defined(invoker.public_deps)) {
public_deps = invoker.public_deps
}
if (defined(invoker.defines)) {
defines = invoker.defines
}
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
deps += [ "//test/developertest/third_party/lib/cpp:gtest_main" ]
}
if (defined(invoker.configs) && ohos_test_args != "notest") {
configs += invoker.configs
}
cflags = [ "-Wno-error" ]
if (defined(invoker.cflags)) {
cflags += invoker.cflags
}
ldflags = []
if (defined(invoker.ldflags)) {
ldflags += invoker.ldflags
}
if (ohos_current_toolchain_type != "clang") {
ldflags += [ "-lstdc++" ]
}
if (ohos_kernel_type == "linux") {
ldflags += [
"-lm",
"-pthread",
]
}
if (ohos_test_args == "notest") {
not_needed(["output_dir", "sources", "include_dirs", "deps", "public_deps", "defines", "configs", "cflags", "ldflags", "output_extension"])
}
}
}
template("moduletest") {
executable(target_name) {
output_dir = "${root_out_dir}/test/moduletest"
forward_variables_from(invoker, "*")
if (!defined(include_dirs)) {
include_dirs = []
}
include_dirs += test_common_include_dirs
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
include_dirs += test_include_dirs
}
if (!defined(deps)) {
deps = []
}
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
deps += [ "//test/developertest/third_party/lib/cpp:gtest_main" ]
}
if (!defined(configs)) {
configs = []
}
cflags = [ "-Wno-error" ]
ldflags = []
if (defined(invoker.ldflags)) {
ldflags += invoker.ldflags
}
if (ohos_current_toolchain_type != "clang") {
ldflags += [ "-lstdc++" ]
}
if (ohos_kernel_type == "linux") {
ldflags += [
"-lm",
"-pthread",
]
}
}
}
template("subsystem_test") {
assert(defined(invoker.test_components), "Test Components is required.")
group(target_name) {
deps = []
if (defined(invoker.test_components)) {
deps += invoker.test_components
}
}
}
template("fuzztest") {
executable(target_name) {
output_dir = "${root_out_dir}/test/fuzztest"
forward_variables_from(invoker, "*")
if (!defined(include_dirs)) {
include_dirs = []
}
include_dirs += test_common_include_dirs
include_dirs += [
"//test/tools/Secodefuzz/",
"//test/tools/Secodefuzz/common",
]
if (ohos_kernel_type == "liteos_a") {
include_dirs += test_include_dirs
}
if (!defined(deps)) {
deps = []
}
if (ohos_kernel_type == "liteos_a") {
deps += [
"//test/developertest/third_party/lib/cpp:gtest_main",
"//test/tools/Secodefuzz:secodefuzz",
]
}
if (!defined(configs)) {
configs = []
}
cflags = [ "-Wno-error" ]
ldflags = []
if (defined(invoker.ldflags)) {
ldflags += invoker.ldflags
}
if (ohos_current_toolchain_type != "clang") {
ldflags += [ "-lstdc++" ]
}
_fuzztest_output_dir = "$root_build_dir/fuzztest"
rebase_path(_fuzztest_output_dir, root_build_dir)
}
import("test/notest.gni")
} else {
import("test/test.gni")
}
# Copyright (c) 2020 Huawei Device Co., Ltd.
# 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.
template("unittest") {
group(target_name) {
not_needed(invoker, "*")
}
}
template("moduletest") {
group(target_name) {
not_needed(invoker, "*")
}
}
template("subsystem_test") {
group(target_name) {
not_needed(invoker, "*")
}
}
template("fuzztest") {
group(target_name) {
not_needed(invoker, "*")
}
}
# Copyright (c) 2020 Huawei Device Co., Ltd.
# 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("//build/lite/config/subsystem/aafwk/path.gni")
# liteos c test template
test_common_include_dirs = [ "//third_party/googletest/googletest/include" ]
test_include_dirs = [
"//utils/native/lite/include",
"//kernel/liteos_a/kernel/include",
"//third_party/bounds_checking_function/include",
]
template("unittest") {
archive_dir_name = "test_info"
_output_dir = ""
if (defined(invoker.output_dir)) {
_output_dir = invoker.output_dir
} else {
_output_dir = "${root_out_dir}/${archive_dir_name}/unittest"
}
# generate module list file in gn stage
# format like: unittest("componentName_test_xx")
list_tmp = string_split(target_name, "_test")
_part_name = list_tmp[0]
_module_list_file = string_join("",
[
root_out_dir,
"/${archive_dir_name}/module_list_files/",
_part_name,
"/",
_part_name,
"/",
target_name,
".mlf",
])
_sources_file_search_root_dir = string_join("",
[
root_out_dir,
"/${archive_dir_name}/gen",
])
_sources = ""
foreach(s, invoker.sources) {
_sources += s + ","
}
_arguments = [
"--target",
target_name,
"--target_label",
get_label_info(target_name, "label_with_toolchain"),
"--source_dir",
rebase_path(get_label_info(target_name, "dir"), root_out_dir),
"--test_type",
"unittest",
"--output_dir",
rebase_path(_output_dir),
"--module_list_file",
rebase_path(_module_list_file),
"--sources_file_search_root_dir",
rebase_path(_sources_file_search_root_dir),
"--sources",
_sources,
]
_gen_module_list_script = "//build/lite/testfwk/gen_module_list_files.py"
exec_script(_gen_module_list_script, _arguments)
executable(target_name) {
if (defined(invoker.output_dir)) {
output_dir = invoker.output_dir
}
if (defined(invoker.sources)) {
sources = invoker.sources
}
if (defined(invoker.include_dirs)) {
include_dirs = invoker.include_dirs
} else {
include_dirs = []
}
include_dirs += test_common_include_dirs
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
include_dirs += test_include_dirs
}
if (defined(invoker.deps)) {
deps = invoker.deps
} else {
deps = []
}
if (defined(invoker.public_deps)) {
public_deps = invoker.public_deps
}
if (defined(invoker.defines)) {
defines = invoker.defines
}
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
deps += [ "//test/developertest/third_party/lib/cpp:gtest_main" ]
}
if (defined(invoker.configs)) {
configs += invoker.configs
}
if (defined(invoker.output_extension)) {
output_extension = invoker.output_extension
}
cflags = [ "-Wno-error" ]
if (defined(invoker.cflags)) {
cflags += invoker.cflags
}
ldflags = []
if (defined(invoker.ldflags)) {
ldflags += invoker.ldflags
}
if (ohos_build_compiler != "clang") {
ldflags += [ "-lstdc++" ]
}
if (ohos_kernel_type == "linux") {
ldflags += [
"-lm",
"-pthread",
]
}
}
}
template("moduletest") {
executable(target_name) {
output_dir = "${root_out_dir}/test/moduletest"
forward_variables_from(invoker, "*")
if (!defined(include_dirs)) {
include_dirs = []
}
include_dirs += test_common_include_dirs
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
include_dirs += test_include_dirs
}
if (!defined(deps)) {
deps = []
}
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
deps += [ "//test/developertest/third_party/lib/cpp:gtest_main" ]
}
if (!defined(configs)) {
configs = []
}
cflags = [ "-Wno-error" ]
ldflags = []
if (defined(invoker.ldflags)) {
ldflags += invoker.ldflags
}
if (ohos_build_compiler != "clang") {
ldflags += [ "-lstdc++" ]
}
if (ohos_kernel_type == "linux") {
ldflags += [
"-lm",
"-pthread",
]
}
}
}
template("subsystem_test") {
assert(defined(invoker.test_components), "Test Components is required.")
group(target_name) {
deps = []
if (defined(invoker.test_components)) {
deps += invoker.test_components
}
}
}
template("fuzztest") {
executable(target_name) {
output_dir = "${root_out_dir}/test/fuzztest"
forward_variables_from(invoker, "*")
if (!defined(include_dirs)) {
include_dirs = []
}
include_dirs += test_common_include_dirs
include_dirs += [
"//test/tools/Secodefuzz/",
"//test/tools/Secodefuzz/common",
]
if (ohos_kernel_type == "liteos_a") {
include_dirs += test_include_dirs
}
if (!defined(deps)) {
deps = []
}
if (ohos_kernel_type == "liteos_a") {
deps += [
"//test/developertest/third_party/lib/cpp:gtest_main",
"//test/tools/Secodefuzz:secodefuzz",
]
}
if (!defined(configs)) {
configs = []
}
cflags = [ "-Wno-error" ]
ldflags = []
if (defined(invoker.ldflags)) {
ldflags += invoker.ldflags
}
if (ohos_build_compiler != "clang") {
ldflags += [ "-lstdc++" ]
}
_fuzztest_output_dir = "$root_build_dir/fuzztest"
rebase_path(_fuzztest_output_dir, root_build_dir)
}
}
......@@ -98,7 +98,7 @@ template("clang_toolchain") {
outfile = "bin/{{target_output_name}}{{output_extension}}"
rspfile = "$outfile.rsp"
custom_ld_flags = " "
command = "$cc {{ldflags}} {{inputs}} $custom_ld_flags -o $outfile"
command = "$ld {{ldflags}} {{inputs}} $custom_ld_flags -o $outfile"
if (need_strip) {
command += " && $strip $outfile"
}
......
......@@ -9,9 +9,9 @@
# 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.
# limitations under the License.
# Description: Native Development Kit Template
# Description: Native Development Kit Template
declare_args() {
ohos_build_ndk = false
......@@ -29,7 +29,7 @@ windows_system = "windows-x86_64"
linux_system = "linux-x86_64"
ndk_toolchain = "gcc"
if (ohos_current_toolchain_type == "clang") {
if (ohos_build_compiler == "clang") {
ndk_toolchain = "llvm"
}
ndk_windows_specific_out_dir = "${ndk_out_dir}/$ndk_toolchain"
......
......@@ -39,23 +39,15 @@ declare_args() {
ohos_kernel_type = ""
use_board_toolchain = true
# Current toolchain name
ohos_current_toolchain = ""
# Current toolchain type, clang or gcc.
ohos_current_toolchain_type = ""
# Current toolchain prefix. E.g. "/data/user1/riscv32/bin/riscv32-unknown-elf-".
ohos_current_toolchain_prefix = ""
# Current toolchain cc command. E.g. "/data/user1/riscv32/bin/riscv32-unknown-elf-gcc".
ohos_current_cc_command = ""
ohos_current_cxx_command = ""
ohos_current_ar_command = ""
ohos_current_as_command = ""
ohos_current_ld_command = ""
ohos_current_strip_command = ""
ohos_current_sysroot = []
# Current sysroot path. E.g. "//prebuilts/lite/sysroot".
ohos_current_sysroot = "//prebuilts/lite/sysroot"
}
if (product_path != "") {
......@@ -72,6 +64,7 @@ if (product_path != "") {
ohos_product_adapter_dir = product_config.product_adapter_dir
ohos_third_party_dir = product_config.third_party_dir
}
ohos_build_user = "jenkins"
ohos_build_host = host_os
ohos_build_roothash = ""
......
......@@ -96,7 +96,7 @@ template("clang_toolchain") {
unstripped_outfile = "{{output_dir}}/unstripped/bin/{{target_output_name}}{{output_extension}}"
}
command +=
"$cc {{ldflags}} {{inputs}} {{libs}} $custom_ld_flags -o $unstripped_outfile"
"$ld {{ldflags}} {{inputs}} {{libs}} $custom_ld_flags -o $unstripped_outfile"
if (need_strip) {
command += " && $strip \"$unstripped_outfile\" \"$outfile\""
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册