You set the variable "IPC_CORE_ROOT" here and it was unused before it went out of scope.
[OHOS INFO] root_out_dir=//out/hispark_pegasus/hispark_pegasus_mini_system
[OHOS INFO] root_build_dir=//out/hispark_pegasus/hispark_pegasus_mini_system
[OHOS INFO] root_gen_dir=//out/hispark_pegasus/hispark_pegasus_mini_system/gen
[OHOS INFO] current_toolchain=//build/lite/toolchain:riscv32-unknown-elf
[OHOS INFO] host_toolchain=//build/toolchain/linux:clang_x64
[OHOS INFO] ohos_build_compiler: gcc
[OHOS INFO] ohos_kernel_type: liteos_m
[OHOS INFO] ERROR at //foundation/communication/ipc/BUILD.gn:19:17: Assignment had no effect.
[OHOS INFO] IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
[OHOS INFO] ^--------------------------
[OHOS INFO] You set the variable "IPC_CORE_ROOT" here and it was unused before it went
[OHOS INFO] out of scope.
[OHOS INFO] See //build/ohos/ohos_part.gni:25:16: which caused the file to be included.
[OHOS INFO] _deps += [ get_label_info(module_label, "label_with_toolchain") ]
[OHOS INFO] ^--------------------------------------------------
[OHOS ERROR] ERROR at //foundation/communication/ipc/BUILD.gn:19:17: Assignment had no effect.
[OHOS ERROR] IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
[OHOS ERROR] ^--------------------------
[OHOS ERROR] You set the variable "IPC_CORE_ROOT" here and it was unused before it went
[OHOS ERROR] out of scope.
[OHOS ERROR] See //build/ohos/ohos_part.gni:25:16: which caused the file to be included.
[OHOS ERROR] _deps += [ get_label_info(module_label, "label_with_toolchain") ]
[OHOS ERROR] ^--------------------------------------------------
"IPC_CORE_ROOT"变量在离开作用域时没有被用上,一直不理解gn语法,后来各种试,然后再参考手册中找到个方法。
解决方法:
在gn-reference找到:
not_needed: Mark variables from scope as not needed.
not_needed(variable_list_or_star, variable_to_ignore_list = [])
not_needed(from_scope, variable_list_or_star, variable_to_ignore_list = [])
Mark the variables in the current or given scope as not needed, which means you will not get an error about unused variables for these. The variable_to_ignore_list allows excluding variables from "all matches" if variable_list_or_star is "*".
Example
not_needed("*", [ "config" ])
not_needed([ "data_deps", "deps" ])
not_needed(invoker, "*", [ "config" ])
not_needed(invoker, [ "data_deps", "deps" ])
没有被使用的变量必须使用not_needed函数标记出来,否则会报错。
故在foundation/communication/ipc/BUILD.gn中没有使用到的分支,标记下:
SUBSYSTEM_DIR = "//foundation/communication/ipc"
IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
group("ipc_components") {
if (os_level == "standard") {
deps = [
"$IPC_CORE_ROOT/src/core:ipc_common",
"$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core:ipc_core",
"$SUBSYSTEM_DIR/interfaces/innerkits/ipc_single:ipc_single",
]
if (!build_ohos_sdk) {
deps += [
"$SUBSYSTEM_DIR/interfaces/innerkits/libdbinder:libdbinder",
"$SUBSYSTEM_DIR/interfaces/innerkits/rust:rust_ipc_component",
]
}
} else {
# 这个分支没有使用到变量IPC_CORE_ROOT,故用下边函数标记下
not_needed([IPC_CORE_ROOT])
deps = [ "$SUBSYSTEM_DIR/interfaces/innerkits/c:rpc" ]
}
}
再次执行编译命令不再报错。