Skip to content

Commit

Permalink
chore: refine build scripts (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Jan 19, 2025
1 parent 3b9cc49 commit 6949e69
Show file tree
Hide file tree
Showing 70 changed files with 254 additions and 218 deletions.
16 changes: 8 additions & 8 deletions build/ten_runtime/feature/prepare_integration_test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __init__(self):
self.src_app: str
self.src_app_language: str
self.generated_app_src_root_dir_name: str
self.replace_files_after_install_app: list[str]
self.replace_files_after_install_all: list[str]
self.replace_paths_after_install_app: list[str]
self.replace_paths_after_install_all: list[str]


def dump_integration_test_preparation_info_json(args: ArgumentInfo):
Expand All @@ -30,8 +30,8 @@ def dump_integration_test_preparation_info_json(args: ArgumentInfo):
"src_app": args.src_app,
"src_app_language": args.src_app_language,
"generated_app_src_root_dir_name": args.generated_app_src_root_dir_name,
"replace_files_after_install_app": args.replace_files_after_install_app,
"replace_files_after_install_all": args.replace_files_after_install_all,
"replace_paths_after_install_app": args.replace_paths_after_install_app,
"replace_paths_after_install_all": args.replace_paths_after_install_all,
}

resource_dir = os.path.join(
Expand Down Expand Up @@ -112,14 +112,14 @@ def copy_replacement_files(
)

parser.add_argument(
"--replace-files-after-install-app",
"--replace-paths-after-install-app",
type=str,
action="append",
help="List of files to replace after installing app",
)

parser.add_argument(
"--replace-files-after-install-all",
"--replace-paths-after-install-all",
type=str,
action="append",
help="List of files to replace after installing all",
Expand All @@ -132,13 +132,13 @@ def copy_replacement_files(

copy_replacement_files(
args,
args.replace_files_after_install_app,
args.replace_paths_after_install_app,
"files_to_be_replaced_after_install_app",
)

copy_replacement_files(
args,
args.replace_files_after_install_all,
args.replace_paths_after_install_all,
"files_to_be_replaced_after_install_all",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ def split(input: str, split_key: str) -> tuple[str, str]:

def replace_normal_files_or_merge_json_files(replaced_files: list[str]) -> None:
for res in replaced_files:
res_src, res_dest = split(res, "=>")
src, dest = split(res, "=>")

if not os.path.exists(res_src):
raise Exception(f"{res_src} does not exist.")
if not os.path.exists(src):
raise Exception(f"{src} does not exist.")

if (
res_src.endswith(".json")
and res_dest.endswith(".json")
and os.path.exists(res_dest)
src.endswith(".json")
and dest.endswith(".json")
and os.path.exists(dest)
):
merge_json_file_at_root_level(res_src, res_dest)
merge_json_file_at_root_level(src, dest)
else:
fs_utils.copy(res_src, res_dest)
fs_utils.copy(src, dest)


if __name__ == "__main__":
Expand Down
137 changes: 67 additions & 70 deletions build/ten_runtime/feature/test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -108,61 +108,60 @@ template("ten_package_test_prepare_app") {
all_deps +=
[ ":${test_case_unique_target_name}_${_target_name}_install_app" ]

# replace_files_after_install_app
# replace_paths_after_install_app
replace_files_after_install_app_deps = []
replace_files_after_install_app_dests = []

if (defined(invoker.replace_files_after_install_app) &&
invoker.replace_files_after_install_app != []) {
replace_file_index = 0
if (defined(invoker.replace_paths_after_install_app) &&
invoker.replace_paths_after_install_app != []) {
replace_path_index = 0

foreach(replace_file, invoker.replace_files_after_install_app) {
replace_file_info = {
foreach(replace_path, invoker.replace_paths_after_install_app) {
replace_path_info = {
}
replace_file_info =

replace_path_info =
exec_script("//.gnfiles/build/scripts/get_src_and_dest_file.py",
[
"--input-string",
replace_file,
"--delimiter",
replace_path,
"--src-dest-delimiter",
"=>",
"--delimiter",
"|",
"--src-base-delimiter",
":",
],
"json")

replace_file_src_paths = []
replace_file_src_paths = replace_file_info.sources
replace_file_src_path = replace_file_src_paths[0]
replace_file_dest_path =
"${test_case_out_dir_rel_path}/${replace_file_info.destination}"
replace_src_path = replace_path_info.source
replace_dest_path =
"${test_case_out_dir_rel_path}/${replace_path_info.destination}"

replace_file_src_abs_path = rebase_path(replace_file_src_path)
replace_file_dest_abs_path = rebase_path(replace_file_dest_path)
replace_src_abs_path = rebase_path(replace_src_path)
replace_dest_abs_path = rebase_path(replace_dest_path)

action(
"${test_case_unique_target_name}_${_target_name}_after_install_app_replace_file_${replace_file_index}") {
"${test_case_unique_target_name}_${_target_name}_after_install_app_replace_file_${replace_path_index}") {
script = "//build/ten_runtime/feature/replace_normal_files_or_merge_json_files.py"

args = [
"--replaced-files",
"${replace_file_src_abs_path}=>${replace_file_dest_abs_path}",
"${replace_src_abs_path}=>${replace_dest_abs_path}",
]

# Wait for the completion of 'install_app'.
inputs = []
sources = [ replace_file_src_path ]
outputs = [ replace_file_dest_path ]
sources = [ replace_src_path ]
outputs = [ replace_dest_path ]

# Need to wait the completion of the app construction phase.
deps =
[ ":${test_case_unique_target_name}_${_target_name}_install_app" ]
}

replace_files_after_install_app_deps += [ ":${test_case_unique_target_name}_${_target_name}_after_install_app_replace_file_${replace_file_index}" ]
replace_files_after_install_app_dests += [ replace_file_dest_path ]
replace_files_after_install_app_deps += [ ":${test_case_unique_target_name}_${_target_name}_after_install_app_replace_file_${replace_path_index}" ]
replace_files_after_install_app_dests += [ replace_dest_path ]

replace_file_index += 1
replace_path_index += 1
}
}

Expand Down Expand Up @@ -228,59 +227,58 @@ template("ten_package_test_prepare_app") {
[ ":${test_case_unique_target_name}_${_target_name}_install_all" ]

# ===============================
# replace_files_after_install_all
replace_files_after_install_all_deps = []
replace_files_after_install_all_dests = []
# replace_paths_after_install_all
deps_for_replace_paths_after_install_all = []
dests_for_replace_paths_after_install_all = []

if (defined(invoker.replace_files_after_install_all) &&
invoker.replace_files_after_install_all != []) {
replace_file_index = 0
if (defined(invoker.replace_paths_after_install_all) &&
invoker.replace_paths_after_install_all != []) {
replace_path_index = 0

foreach(replace_file, invoker.replace_files_after_install_all) {
replace_file_info = {
foreach(replace_path, invoker.replace_paths_after_install_all) {
replace_path_info = {
}
replace_file_info =

replace_path_info =
exec_script("//.gnfiles/build/scripts/get_src_and_dest_file.py",
[
"--input-string",
replace_file,
"--delimiter",
replace_path,
"--src-dest-delimiter",
"=>",
"--delimiter",
"|",
"--src-base-delimiter",
":",
],
"json")

replace_file_src_paths = []
replace_file_src_paths = replace_file_info.sources
replace_file_src_path = replace_file_src_paths[0]
replace_file_dest_path =
"${test_case_out_dir_rel_path}/${replace_file_info.destination}"
replace_src_path = replace_path_info.source
replace_dest_path =
"${test_case_out_dir_rel_path}/${replace_path_info.destination}"

replace_file_src_abs_path = rebase_path(replace_file_src_path)
replace_file_dest_abs_path = rebase_path(replace_file_dest_path)
replace_src_abs_path = rebase_path(replace_src_path)
replace_dest_abs_path = rebase_path(replace_dest_path)

action(
"${test_case_unique_target_name}_${_target_name}_after_install_all_replace_file_${replace_file_index}") {
"${test_case_unique_target_name}_${_target_name}_after_install_all_replace_file_${replace_path_index}") {
script = "//build/ten_runtime/feature/replace_normal_files_or_merge_json_files.py"
args = [
"--replaced-files",
"${replace_file_src_abs_path}=>${replace_file_dest_abs_path}",
"${replace_src_abs_path}=>${replace_dest_abs_path}",
]

sources = [ replace_file_src_path ]
outputs = [ replace_file_dest_path ]
sources = [ replace_src_path ]
outputs = [ replace_dest_path ]

deps = [
":${test_case_unique_target_name}_${_target_name}_install_all",
":${test_case_unique_target_name}_${_target_name}_install_app",
]
}

replace_files_after_install_all_deps += [ ":${test_case_unique_target_name}_${_target_name}_after_install_all_replace_file_${replace_file_index}" ]
replace_files_after_install_all_dests += [ replace_file_dest_path ]
deps_for_replace_paths_after_install_all += [ ":${test_case_unique_target_name}_${_target_name}_after_install_all_replace_file_${replace_path_index}" ]
dests_for_replace_paths_after_install_all += [ replace_dest_path ]

replace_file_index += 1
replace_path_index += 1
}
}

Expand Down Expand Up @@ -339,7 +337,7 @@ template("ten_package_test_prepare_app") {
}

sources = replace_files_after_install_app_dests +
replace_files_after_install_all_dests
dests_for_replace_paths_after_install_all
outputs = [ build_app_dummy_output_file ]

forward_variables_from(invoker,
Expand All @@ -356,7 +354,7 @@ template("ten_package_test_prepare_app") {
":${test_case_unique_target_name}_${_target_name}_install_all",
":${test_case_unique_target_name}_${_target_name}_install_app",
] + replace_files_after_install_app_deps +
replace_files_after_install_all_deps
deps_for_replace_paths_after_install_all
}

all_deps += [ ":${test_case_unique_target_name}_${_target_name}_build" ]
Expand All @@ -382,22 +380,22 @@ template("ten_package_test_prepare_app") {
invoker.generated_app_src_root_dir_name,
]

if (defined(invoker.replace_files_after_install_app) &&
invoker.replace_files_after_install_app != []) {
foreach(replace_file, invoker.replace_files_after_install_app) {
if (defined(invoker.replace_paths_after_install_app) &&
invoker.replace_paths_after_install_app != []) {
foreach(replace_path, invoker.replace_paths_after_install_app) {
args += [
"--replace-files-after-install-app",
replace_file,
"--replace-paths-after-install-app",
replace_path,
]
}
}

if (defined(invoker.replace_files_after_install_all) &&
invoker.replace_files_after_install_all != []) {
foreach(replace_file, invoker.replace_files_after_install_all) {
if (defined(invoker.replace_paths_after_install_all) &&
invoker.replace_paths_after_install_all != []) {
foreach(replace_path, invoker.replace_paths_after_install_all) {
args += [
"--replace-files-after-install-all",
replace_file,
"--replace-paths-after-install-all",
replace_path,
]
}
}
Expand Down Expand Up @@ -515,21 +513,20 @@ template("ten_package_test_prepare_auxiliary_resources") {
foreach(resource, invoker.resources) {
resource_info = {
}

resource_info =
exec_script("//.gnfiles/build/scripts/get_src_and_dest_file.py",
[
"--input-string",
resource,
"--delimiter",
"--src-dest-delimiter",
"=>",
"--delimiter",
"|",
"--src-base-delimiter",
":",
],
"json")

resource_src_paths = []
resource_src_paths = resource_info.sources
resource_src_path = resource_src_paths[0]
resource_src_path = resource_info.source
resource_dest_path =
"${test_case_out_dir_rel_path}/${resource_info.destination}"

Expand Down
Loading

0 comments on commit 6949e69

Please sign in to comment.