diff --git a/BUILD.gn b/BUILD.gn index c83e6e2d3e8a985bfd28e7c4c3b0422d84dbf2b3..bd824558b5b1b7f1706f93c38a17fc5e926c7ba9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -97,7 +97,7 @@ if (is_lite_system && current_os == "ohos") { action("create_porting_src") { script = "scripts/porting.sh" - sources = [ "//third_party/musl" ] + sources_dir = [ "//third_party/musl" ] outdir = [ "${target_out_dir}/${musl_ported_dir}" ] @@ -132,7 +132,7 @@ if (is_lite_system && current_os == "ohos") { "scripts/create_syscall.sh", ] - args = [ "-i" ] + rebase_path(sources) + args = [ "-i" ] + rebase_path(sources_dir) args += [ "-o" ] + rebase_path(outdir) args += [ "-p" ] + [ "${musl_target_os}" ] @@ -210,43 +210,93 @@ if (is_lite_system && current_os == "ohos") { deps = [ ":create_porting_src" ] } - action("make_uapi") { + # if uapi_dir does not exist, then make uapi from linux_kernel_dir + if (exec_script("/bin/sh", + [ + "-c", + "if [ ! -d " + rebase_path(uapi_dir) + + " ]; then echo true; else echo false; fi", + ], + "value")) { kernel_dir = rebase_path(linux_kernel_dir) - kernel_out_dir = rebase_path(get_path_info("${kernel_dir}/", "out_dir")) + kernel_out_dir = "${kernel_dir}/make_output" uapi_dir = "${kernel_out_dir}/usr/include" make_uapi_cmd = "rm -rf ${uapi_dir}" make_uapi_cmd += " && make -C ${kernel_dir} -sj headers O=${kernel_out_dir} ARCH=${target_cpu}" make_uapi_cmd += " && cp -f ${kernel_dir}/drivers/staging/android/uapi/ashmem.h ${uapi_dir}/linux/ashmem.h" make_uapi_cmd += " && sed -i '/#define _INPUT_H/i#define _UAPI_INPUT_H' ${uapi_dir}/linux/input.h" make_uapi_cmd += " && sed -i '/struct __kernel_sockaddr_storage/i#define sockaddr_storage __kernel_sockaddr_storage' ${uapi_dir}/linux/socket.h" - outputs = [ "${target_out_dir}/" + rebase_path(uapi_dir, target_out_dir) ] - script = "/bin/sh" - args = [ "-c" ] - args += [ make_uapi_cmd ] + args_make_uapi = [ "-c" ] + args_make_uapi += [ make_uapi_cmd ] + exec_script("/bin/sh", args_make_uapi, "value") + uapi_from = "make" + } else { + uapi_from = "local" } - # if uapi_dir does not exist, then make uapi from linux_kernel_dir - if (exec_script("/bin/sh", - [ - "-c", - "if [ ! -d " + rebase_path(uapi_dir) + - " ]; then echo true; else echo false; fi", - ], - "value")) { - uapi_dir = get_path_info("${linux_kernel_dir}/", "out_dir") + "/usr/include" - uapi_deps = [ ":make_uapi" ] + uapi_full_path = rebase_path(uapi_dir) + arguments_uapi = [ "-c" ] + + # exclude these files because they need special treatment + if (uapi_from == "make") { + exclude_files = "asm|scsi" } else { - uapi_deps = [] + exclude_files = "asm-arm|asm-arm64|scsi" + } + + arguments_uapi += + [ "ls ${uapi_full_path} | grep -Ev " + "\"" + "${exclude_files}" + "\"" ] + uspi_files = exec_script("/bin/sh", arguments_uapi, "list lines") + + # Generate a copy target for each file + foreach(file, uspi_files) { + copy("copy_uapi_${file}") { + sources = [ "${uapi_dir}/${file}" ] + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/${file}" ] + } } - action("copy_uapi") { - outputs = [ "${target_out_dir}/${musl_inc_out_dir}" ] - inputs = [ uapi_dir ] - deps = uapi_deps - script = "scripts/copy_uapi.sh" - args = [ "-i" ] + rebase_path(inputs) - args += [ "-o" ] + rebase_path(outputs) - args += [ "-t" ] + [ "${musl_arch}" ] + group("copy_uapi_scsi") { + deps = [] + sources = [] + outputs = [] + uapi_scsi_dir = rebase_path("${uapi_dir}/scsi") + arguments_scsi = [ "-c" ] + arguments_scsi += [ "ls ${uapi_scsi_dir}" ] + uapi_scsi_files = exec_script("/bin/sh", arguments_scsi, "list lines") + + # Generate a copy target for each file in scsi dir to avoid being influenced by musl_copy_inc_scsi output + foreach(file, uapi_scsi_files) { + copy("copy_uapi_scsi_${file}") { + sources += [ "${uapi_dir}/scsi/${file}" ] + outputs += [ "${target_out_dir}/${musl_inc_out_dir}/scsi/${file}" ] + } + deps += [ ":copy_uapi_scsi_${file}" ] + } + } + + copy("copy_uapi_asm") { + if (uapi_from == "local") { + if ("${musl_arch}" == "arm") { + file_name = "asm-arm" + } else { # aarch64 and x86_64 use same file + file_name = "asm-arm64" + } + sources = [ "${uapi_dir}/${file_name}/asm" ] + } else { + sources = [ "${uapi_dir}/asm" ] + } + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/asm" ] + } + + group("copy_uapi") { + deps = [ ":copy_uapi_scsi" ] + + # We need do different processing for asm according to the source of uapi + deps += [ ":copy_uapi_asm" ] + foreach(file, uspi_files) { + deps += [ ":copy_uapi_${file}" ] + } } copy("musl_copy_inc_bits") {