diff --git a/build/gen.py b/build/gen.py
index 8b5795bf525a2ad004582b1988aefa02ea16c722..60142964616b6412a6449b412499b47d41b8d8f3 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -620,6 +620,7 @@ def WriteGNNinja(path, platform, host, options, args_list):
'src/gn/header_checker.cc',
'src/gn/import_manager.cc',
'src/gn/inherited_libraries.cc',
+ "src/gn/innerapis_publicinfo_generator.cc",
'src/gn/input_conversion.cc',
'src/gn/input_file.cc',
'src/gn/input_file_manager.cc',
@@ -648,6 +649,9 @@ def WriteGNNinja(path, platform, host, options, args_list):
'src/gn/ninja_tools.cc',
'src/gn/ninja_utils.cc',
'src/gn/ninja_writer.cc',
+ 'src/gn/ohos_components.cc',
+ "src/gn/ohos_components_checker.cc",
+ 'src/gn/ohos_variables.cc',
'src/gn/operators.cc',
'src/gn/output_conversion.cc',
'src/gn/output_file.cc',
@@ -771,6 +775,7 @@ def WriteGNNinja(path, platform, host, options, args_list):
'src/gn/ninja_target_command_util_unittest.cc',
'src/gn/ninja_target_writer_unittest.cc',
'src/gn/ninja_toolchain_writer_unittest.cc',
+ 'src/gn/ohos_components_unittest.cc',
'src/gn/operators_unittest.cc',
'src/gn/output_conversion_unittest.cc',
'src/gn/parse_tree_unittest.cc',
diff --git a/docs/reference.md b/docs/reference.md
index 51dcecc38df370760e0e91821b586f2fd7bf434b..eb9d74beacb778749017f9b98eb95dca0c299f95 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -120,6 +120,7 @@
* [defines: [string list] C preprocessor defines.](#var_defines)
* [depfile: [string] File name for input dependencies for actions.](#var_depfile)
* [deps: [label list] Private linked dependencies.](#var_deps)
+ * [external_deps: [label list] Declare external dependencies for OpenHarmony component.](#var_external_deps)
* [externs: [scope] Set of Rust crate-dependency pairs.](#var_externs)
* [framework_dirs: [directory list] Additional framework search directories.](#var_framework_dirs)
* [frameworks: [name list] Name of frameworks that must be linked.](#var_frameworks)
@@ -147,6 +148,7 @@
* [public: [file list] Declare public header files for a target.](#var_public)
* [public_configs: [label list] Configs applied to dependents.](#var_public_configs)
* [public_deps: [label list] Declare public dependencies.](#var_public_deps)
+ * [public_external_deps: [label list] Declare public external dependencies for OpenHarmony component.](#var_public_external_deps)
* [rebase: [boolean] Rebase collected metadata as files.](#var_rebase)
* [response_file_contents: [string list] Contents of .rsp file for actions.](#var_response_file_contents)
* [script: [file name] Script file for actions.](#var_script)
@@ -5463,6 +5465,26 @@
See also "public_deps".
```
+### **external_deps**: Declare external dependencies for OpenHarmony component.
+
+```
+ External dependencies are like private dependencies (see "gn help deps") but
+ expressed in the form of: component_name:innerapi_name.
+ * component and innerapi are defined by OpenHarmony bundle.json.
+ With external_deps, deps can be added without absolute path.
+
+ This variable is enabled by setting "ohos_components_support" in .gn file (see "gn help dotfile").
+```
+
+#### **Example**
+
+```
+ # This target "a" can include libinitapi from "init" component
+ executable("a") {
+ deps = [ ":b" ]
+ external_deps = [ "init:libinitapi" ]
+ }
+```
### **externs**: [scope] Set of Rust crate-dependency pairs.
```
@@ -6351,6 +6373,28 @@
public_deps = [ ":c" ]
}
```
+### **public_external_deps**: Declare public external dependencies for OpenHarmony component.
+
+```
+ Public external dependencies (public_external_deps) are like external_deps but additionally express that
+ the current target exposes the listed external_deps as part of its public API.
+
+ This variable is enabled by setting "ohos_components_support" in .gn file (see "gn help dotfile").
+```
+
+#### **Example**
+
+```
+ # Target "a" will include libinitapi from "init" component by deps "b":
+ executable("a") {
+ deps = [ ":b" ]
+ }
+
+ shared_library("b") {
+ deps = [ ":b" ]
+ public_external_deps = [ "init:libinitapi" ]
+ }
+```
### **rebase**: Rebase collected metadata as files.
```
@@ -6853,6 +6897,21 @@
When set specifies the minimum required version of Ninja. The default
required version is 1.7.2. Specifying a higher version might enable the
use of some of newer features that can make the build more efficient.
+
+ ohos_components_support [optional]
+ This parameter enable support for OpenHarmony components.
+ When enabled, gn will load components information from "build_configs/"
+ directory in the root_out_directory.
+
+ The following files will be loaded:
+ out/build_configs/parts_info/inner_kits_info.json (required):
+ Required InnerAPI information file for each OHOS component.
+ out/build_configs/component_override_map.json (optional):
+ Optional overrided component maps file.
+
+ For OpenHarmony system build, this value must be enabled to support
+ external_deps (see "gn help external_deps") and public_external_deps
+ (see "gn help public_external_deps").
```
#### **Example .gn file contents**
diff --git a/src/gn/build_settings.cc b/src/gn/build_settings.cc
index 22c11451f5a48323e39fb6c368613813b6e275e7..ae908bb04048189b7f68dec2fdc955f4f272b261 100644
--- a/src/gn/build_settings.cc
+++ b/src/gn/build_settings.cc
@@ -8,6 +8,7 @@
#include "base/files/file_util.h"
#include "gn/filesystem_utils.h"
+#include "gn/ohos_components.h"
BuildSettings::BuildSettings() = default;
@@ -74,3 +75,33 @@ void BuildSettings::ItemDefined(std::unique_ptr- item) const {
if (item_defined_callback_)
item_defined_callback_(std::move(item));
}
+
+void BuildSettings::SetOhosComponentsInfo(OhosComponents *ohos_components)
+{
+ ohos_components_ = ohos_components;
+}
+
+bool BuildSettings::GetExternalDepsLabel(const Value& external_dep, std::string& label, Err* err) const
+{
+ if (ohos_components_ == nullptr) {
+ *err = Err(external_dep, "You are using OpenHarmony external_deps, but no components information loaded.");
+ return false;
+ }
+ return ohos_components_->GetExternalDepsLabel(external_dep, label, err);
+}
+
+bool BuildSettings::is_ohos_components_enabled() const
+{
+ if (ohos_components_ != nullptr) {
+ return true;
+ }
+ return false;
+}
+
+const OhosComponent *BuildSettings::GetOhosComponent(const std::string& label) const
+{
+ if (ohos_components_ == nullptr) {
+ return nullptr;
+ }
+ return ohos_components_->GetComponentByLabel(label);
+}
diff --git a/src/gn/build_settings.h b/src/gn/build_settings.h
index 6c925e985e0f366f49574b16333ce9bd0167f552..d94b1231e785e25d735ac7c0e9311dd6e36565bb 100644
--- a/src/gn/build_settings.h
+++ b/src/gn/build_settings.h
@@ -20,6 +20,8 @@
#include "gn/version.h"
class Item;
+class OhosComponent;
+class OhosComponents;
// Settings for one build, which is one toplevel output directory. There
// may be multiple Settings objects that refer to this, one for each toolchain.
@@ -55,6 +57,12 @@ class BuildSettings {
base::FilePath python_path() const { return python_path_; }
void set_python_path(const base::FilePath& p) { python_path_ = p; }
+ // OpenHarmony components manager.
+ void SetOhosComponentsInfo(OhosComponents *ohos_components);
+ bool GetExternalDepsLabel(const Value& external_dep, std::string& label, Err* err) const;
+ bool is_ohos_components_enabled() const;
+ const OhosComponent *GetOhosComponent(const std::string& label) const;
+
// Required Ninja version.
const Version& ninja_required_version() const {
return ninja_required_version_;
@@ -141,6 +149,8 @@ class BuildSettings {
base::FilePath secondary_source_path_;
base::FilePath python_path_;
+ OhosComponents *ohos_components_ = nullptr;
+
// See 40045b9 for the reason behind using 1.7.2 as the default version.
Version ninja_required_version_{1, 7, 2};
bool no_stamp_files_ = false;
diff --git a/src/gn/copy_target_generator.cc b/src/gn/copy_target_generator.cc
index a0dc9242c964780715f54e14e7efb13d58aea8c0..8f25479f7200dd55faa5f30404ed0db889581175 100644
--- a/src/gn/copy_target_generator.cc
+++ b/src/gn/copy_target_generator.cc
@@ -6,6 +6,7 @@
#include "gn/build_settings.h"
#include "gn/filesystem_utils.h"
+#include "gn/ohos_variables.h"
#include "gn/parse_tree.h"
#include "gn/scope.h"
#include "gn/value.h"
@@ -18,6 +19,17 @@ CopyTargetGenerator::CopyTargetGenerator(Target* target,
CopyTargetGenerator::~CopyTargetGenerator() = default;
+bool CopyTargetGenerator::FillCopyLinkableFile()
+{
+ const Value* value = scope_->GetValue(variables::kCopyLinkableFile, true);
+ if (!value)
+ return true;
+ if (!value->VerifyTypeIs(Value::BOOLEAN, err_))
+ return false;
+ target_->set_copy_linkable_file(value->boolean_value());
+ return true;
+}
+
void CopyTargetGenerator::DoRun() {
target_->set_output_type(Target::COPY_FILES);
@@ -41,4 +53,7 @@ void CopyTargetGenerator::DoRun() {
"source_expansion\").");
return;
}
+
+ if (!FillCopyLinkableFile())
+ return;
}
diff --git a/src/gn/copy_target_generator.h b/src/gn/copy_target_generator.h
index c3098f52fbe39957637a9cc8a7e30ed3f5746b46..7b70b7415590a3bab2e70b5209cb363e224859c9 100644
--- a/src/gn/copy_target_generator.h
+++ b/src/gn/copy_target_generator.h
@@ -6,6 +6,7 @@
#define TOOLS_GN_COPY_TARGET_GENERATOR_H_
#include "gn/target_generator.h"
+#include "gn/ohos_variables.h"
// Populates a Target with the values from a copy rule.
class CopyTargetGenerator : public TargetGenerator {
@@ -22,6 +23,8 @@ class CopyTargetGenerator : public TargetGenerator {
private:
CopyTargetGenerator(const CopyTargetGenerator&) = delete;
CopyTargetGenerator& operator=(const CopyTargetGenerator&) = delete;
+
+ bool FillCopyLinkableFile();
};
#endif // TOOLS_GN_COPY_TARGET_GENERATOR_H_
diff --git a/src/gn/functions.cc b/src/gn/functions.cc
index 6294f79b712a6b985ad3e4ca98cf25ac41f92b04..79aad15fe1ed4946c64aef382975d6e081cc7920 100644
--- a/src/gn/functions.cc
+++ b/src/gn/functions.cc
@@ -16,6 +16,7 @@
#include "gn/config_values_generator.h"
#include "gn/err.h"
#include "gn/input_file.h"
+#include "gn/ohos_components_checker.h"
#include "gn/parse_node_value_adapter.h"
#include "gn/parse_tree.h"
#include "gn/pool.h"
@@ -667,6 +668,11 @@ Value RunImport(Scope* scope,
scope->settings()->import_manager().DoImport(import_file, function, scope,
err);
}
+ const OhosComponentChecker *checker = OhosComponentChecker::getInstance();
+ if (checker != nullptr) {
+ checker->CheckImportOther(function, scope->settings()->build_settings(),
+ input_dir.value(), import_file.value(), err);
+ }
return Value();
}
diff --git a/src/gn/functions_target.cc b/src/gn/functions_target.cc
index 74f53e915f62bfd5e5789917c9abc5e900f9cfd3..8bf3cd5e2b78f1fec9a2f88a554f349c575469a0 100644
--- a/src/gn/functions_target.cc
+++ b/src/gn/functions_target.cc
@@ -543,6 +543,10 @@ Examples
# names in the gen dir. This will just copy each file.
outputs = [ "$target_gen_dir/{{source_file_part}}" ]
}
+
+Variables
+
+ copy_linkable_file
)";
Value RunCopy(const FunctionCallNode* function,
diff --git a/src/gn/innerapis_publicinfo_generator.cc b/src/gn/innerapis_publicinfo_generator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3f56c87863ac4bec2b572b6e382655b99c532ee0
--- /dev/null
+++ b/src/gn/innerapis_publicinfo_generator.cc
@@ -0,0 +1,359 @@
+// Copyright 2024 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gn/innerapis_publicinfo_generator.h"
+
+#include
+#include
+#include
+#include
+
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/json/json_reader.h"
+#include "base/values.h"
+#include "gn/build_settings.h"
+#include "gn/config.h"
+#include "gn/filesystem_utils.h"
+#include "gn/functions.h"
+#include "gn/ohos_components.h"
+#include "gn/ohos_components_checker.h"
+#include "gn/parse_tree.h"
+#include "gn/settings.h"
+#include "gn/substitution_writer.h"
+#include "gn/target.h"
+#include "gn/value.h"
+
+namespace fs = std::filesystem;
+
+InnerApiPublicInfoGenerator *InnerApiPublicInfoGenerator::instance_ = nullptr;
+
+static bool StartWith(const std::string &str, const std::string prefix)
+{
+ return (str.rfind(prefix, 0) == 0);
+}
+
+static bool IsFileExists(const std::string &path)
+{
+ if (access(path.c_str(), F_OK) == 0) {
+ return true;
+ }
+ return false;
+}
+
+static void CreateDirectory(const std::string &path)
+{
+ int status = mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH);
+ if (status == -1 && errno != EEXIST) {
+ return;
+ }
+ size_t found = path.find('/');
+ while (found != std::string::npos) {
+ std::string subPath = path.substr(0, found + 1);
+ struct stat info;
+ if (!stat(subPath.c_str(), &info)) {
+ if ((info.st_mode & S_IFDIR) == 0) {
+ break;
+ }
+ } else {
+ CreateDirectory(subPath);
+ }
+ found = path.find('/', found + 1);
+ }
+}
+
+static std::string GetOutName(const Scope *scope, std::string targetName, const std::string type)
+{
+ std::string outputName = "";
+ std::string extension = "";
+ const Value *outputNameValue = scope->GetValue("output_name");
+ const Value *extensionValue = scope->GetValue("output_extension");
+ if (outputNameValue != nullptr) {
+ outputName = outputNameValue->string_value();
+ }
+ if (extensionValue != nullptr) {
+ extension = extensionValue->string_value();
+ }
+
+ if (outputName == "") {
+ outputName = targetName;
+ }
+ if (type == "shared_library") {
+ if (extension == "") {
+ extension = ".z.so";
+ } else {
+ extension = "." + extension;
+ }
+ if (!StartWith(outputName, "lib")) {
+ outputName = "lib" + outputName;
+ }
+ } else if (type == "static_library") {
+ extension = ".a";
+ if (!StartWith(outputName, "lib")) {
+ outputName = "lib" + outputName;
+ }
+ } else if (type == "rust_library") {
+ if (extension == "") {
+ extension = ".dylib.so";
+ } else {
+ extension = "." + extension;
+ }
+ if (!StartWith(outputName, "lib")) {
+ outputName = "lib" + outputName;
+ }
+ }
+ return outputName + extension;
+}
+
+static bool TraverIncludeDirs(const OhosComponentChecker *checker, const Target *target, const Scope *scope,
+ const std::string label, Err *err)
+{
+ const Value *includes = scope->GetValue("include_dirs");
+ if (includes != nullptr) {
+ const std::vector &includes_list = includes->list_value();
+ for (size_t i = 0; i < includes_list.size(); i++) {
+ SourceDir real_dir = scope->GetSourceDir().ResolveRelativeDir(includes_list[i], err,
+ scope->settings()->build_settings()->root_path_utf8());
+ if (!checker->CheckIncludesAbsoluteDepsOther(target, label, real_dir.value(), err)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool CheckIncludes(const OhosComponentChecker *checker, const std::string dir, bool isPublic,
+ const PublicConfigInfoParams ¶ms)
+{
+ const Target *target = params.target;
+ const std::string label = params.label;
+ Err *err = params.err;
+ if (isPublic) {
+ if (checker != nullptr) {
+ if (!checker->CheckInnerApiIncludesOverRange(target, label, dir, err)) {
+ return false;
+ }
+ }
+ }
+ if (checker != nullptr) {
+ if (!checker->CheckIncludesAbsoluteDepsOther(target, label, dir, err)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static std::string GetIncludeDirsInfo(const Config *config, const OhosComponentChecker *checker, bool isPublic,
+ const PublicConfigInfoParams ¶ms)
+{
+ std::string info = ",\n \"include_dirs\": [\n ";
+ const std::vector dirs = config->own_values().include_dirs();
+ bool first = true;
+ for (const SourceDir &dir : dirs) {
+ if (!first) {
+ info += ",\n ";
+ }
+ first = false;
+ info += "\"" + dir.value() + "\"";
+ if (!CheckIncludes(checker, dir.value(), isPublic, params)) {
+ return "";
+ }
+ }
+ info += "\n ]\n";
+ return info;
+}
+
+static std::string GetPublicConfigInfo(const PublicConfigInfoParams ¶ms, Scope *scope,
+ const UniqueVector &configs, const OhosComponentChecker *checker, bool isPublic)
+{
+ const Target *target = params.target;
+ const std::string label = params.label;
+ Err *err = params.err;
+ Scope::ItemVector *collector = scope->GetItemCollector();
+ std::string info = "[{";
+ bool firstConfig = true;
+ for (const auto &config : configs) {
+ if (!firstConfig) {
+ info += ", {";
+ }
+ firstConfig = false;
+ info += "\n \"label\": \"" + config.label.GetUserVisibleName(false) + "\"";
+ for (auto &item : *collector) {
+ if (item->label() != config.label)
+ continue;
+ Config *as_config = item->AsConfig();
+ if (!as_config) {
+ continue;
+ }
+ PublicConfigInfoParams params = { target, label, err };
+ info += GetIncludeDirsInfo(as_config, checker, isPublic, params);
+ }
+ info += " }";
+ }
+ info += "]";
+ return info;
+}
+
+std::string GetPublicConfigsInfo(const Target *target, const std::string &labelString, Scope *scope,
+ const OhosComponentChecker *checker, Err *err)
+{
+ std::string info = "";
+ const UniqueVector configs = target->public_configs();
+ if (configs.size() > 0) {
+ info += ",\n \"public_configs\": ";
+ PublicConfigInfoParams params = { target, labelString, err };
+ std::string tmp = GetPublicConfigInfo(params, scope, configs, checker, true);
+ if (tmp == "") {
+ return "";
+ }
+ info += tmp;
+ }
+ return info;
+}
+
+std::string GetAllDependentConfigsInfo(const Target *target, const std::string &labelString, Scope *scope,
+ const OhosComponentChecker *checker, Err *err)
+{
+ std::string info = "";
+ const UniqueVector all_configs = target->all_dependent_configs();
+ if (all_configs.size() > 0) {
+ info += ",\n \"all_dependent_configs\": ";
+ PublicConfigInfoParams params = { target, labelString, err };
+ std::string tmp = GetPublicConfigInfo(params, scope, all_configs, checker, true);
+ if (tmp == "") {
+ return "";
+ }
+ info += tmp;
+ if (checker != nullptr) {
+ if (!checker->CheckAllDepsConfigs(target, labelString, err)) {
+ return "";
+ }
+ }
+ }
+ return info;
+}
+
+std::string GetPrivateConfigsInfo(const Target *target, const std::string &labelString, Scope *scope,
+ const OhosComponentChecker *checker, Err *err)
+{
+ std::string info = "";
+ const UniqueVector private_configs = target->configs();
+ if (private_configs.size() > 0) {
+ PublicConfigInfoParams params = { target, labelString, err };
+ std::string tmp = GetPublicConfigInfo(params, scope, private_configs, checker, false);
+ if (tmp == "") {
+ return "";
+ }
+ }
+ return info;
+}
+
+
+std::string GetPublicHeadersInfo(const Target *target)
+{
+ std::string info = "";
+ const std::vector &headers = target->public_headers();
+ if (headers.size() > 0) {
+ info += ",\n \"public\": [\n ";
+ bool first = true;
+ for (const auto &header : headers) {
+ if (!first) {
+ info += ",\n ";
+ }
+ first = false;
+ info += "\"" + header.value() + "\"";
+ }
+ info += " ]";
+ }
+ return info;
+}
+
+std::string GetPublicDepsInfo(const Target *target, const std::string &labelString,
+ const OhosComponentChecker *checker, Err *err)
+{
+ std::string info = "";
+ const LabelTargetVector deps = target->public_deps();
+ if (deps.size() > 0) {
+ info += ",\n \"public_deps\": [\n ";
+ bool first = true;
+ for (const auto &dep : deps) {
+ if (!first) {
+ info += ",\n ";
+ }
+ first = false;
+ std::string dep_str = dep.label.GetUserVisibleName(false);
+ info += "\"" + dep_str + "\"";
+ if (checker == nullptr) {
+ continue;
+ }
+ if (!checker->CheckInnerApiPublicDepsInner(target, labelString, dep_str, err)) {
+ return "";
+ }
+ }
+ info += "\n ]";
+ }
+ return info;
+}
+
+std::string GetOutNameAndTypeInfo(const Scope *scope, const std::string &targetName, const std::string &type)
+{
+ std::string info = "";
+ const std::string name = GetOutName(scope, targetName, type);
+ info += ",\n \"out_name\":\"" + name + "\"";
+ info += ",\n \"type\":\"" + type + "\"";
+ info += "\n}\n";
+ return info;
+}
+
+void InnerApiPublicInfoGenerator::GeneratedInnerapiPublicInfo(Target *target, Label label, Scope *scope,
+ const std::string type, Err *err)
+{
+ if (target == nullptr || (ignoreTest_ && target->testonly())) {
+ return;
+ }
+ const OhosComponentChecker *checker = OhosComponentChecker::getInstance();
+
+ std::string labelString = label.GetUserVisibleName(false);
+ std::string info = "{\n";
+
+ info += " \"label\": \"" + labelString + "\"";
+ info += GetPublicConfigsInfo(target, labelString, scope, checker, err);
+ info += GetAllDependentConfigsInfo(target, labelString, scope, checker, err);
+ info += GetPrivateConfigsInfo(target, labelString, scope, checker, err);
+
+ if (checker != nullptr) {
+ if (!TraverIncludeDirs(checker, target, scope, labelString, err)) {
+ return;
+ }
+ }
+
+ if (target->all_headers_public()) {
+ info += ",\n \"public\": [ \"*\" ]";
+ } else {
+ info += GetPublicHeadersInfo(target);
+ }
+
+ info += GetPublicDepsInfo(target, labelString, checker, err);
+
+ const OhosComponent *component = target->ohos_component();
+ if (target->testonly() || component == nullptr || !component->isInnerApi(labelString)) {
+ return;
+ }
+ int pos = labelString.find(":");
+ std::string targetName = labelString.substr(pos + 1, labelString.length() - 1);
+ info += GetOutNameAndTypeInfo(scope, targetName, type);
+
+ const std::string dir = build_dir_ + "/" + component->subsystem() + "/" + component->name() + "/publicinfo";
+ fs::path path(dir);
+ fs::create_directories(path);
+ std::ofstream publicfile;
+ const std::string json_path = dir + "/" + targetName + ".json";
+ if (IsFileExists(json_path)) {
+ return;
+ }
+ publicfile.open(json_path, std::ios::out);
+ publicfile << info;
+ publicfile.close();
+ return;
+}
diff --git a/src/gn/innerapis_publicinfo_generator.h b/src/gn/innerapis_publicinfo_generator.h
new file mode 100644
index 0000000000000000000000000000000000000000..37b7dd7de811e9e48d3af22b1d93dfdd2602398c
--- /dev/null
+++ b/src/gn/innerapis_publicinfo_generator.h
@@ -0,0 +1,61 @@
+// Copyright 2024 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef INNERAPIS_PUBLICINFO_GENERATOR_H_
+#define INNERAPIS_PUBLICINFO_GENERATOR_H_
+
+#include
+
+#include "gn/build_settings.h"
+#include "gn/config.h"
+#include "gn/functions.h"
+#include "gn/ohos_components_checker.h"
+#include "gn/parse_tree.h"
+#include "gn/settings.h"
+#include "gn/substitution_writer.h"
+#include "gn/target.h"
+#include "gn/value.h"
+
+struct PublicConfigInfoParams {
+ const Target *target;
+ std::string label;
+ Err *err;
+};
+
+class InnerApiPublicInfoGenerator {
+public:
+ void GeneratedInnerapiPublicInfo(Target *target, Label label, Scope *scope, const std::string type, Err *err);
+
+ static InnerApiPublicInfoGenerator *getInstance()
+ {
+ return instance_;
+ }
+
+ static void Init(const std::string &build_dir, int checkType)
+ {
+ if (instance_ != nullptr) {
+ return;
+ }
+ instance_ = new InnerApiPublicInfoGenerator(build_dir, checkType);
+ }
+
+private:
+ bool ignoreTest_ = true;
+ std::string build_dir_;
+ int checkType_ = OhosComponentChecker::CheckType::NONE;
+ static InnerApiPublicInfoGenerator *instance_;
+ InnerApiPublicInfoGenerator(const std::string &build_dir, int checkType)
+ {
+ checkType_ = checkType;
+ build_dir_ = build_dir;
+ if (checkType == OhosComponentChecker::CheckType::SCAN_ALL ||
+ checkType == OhosComponentChecker::CheckType::INTERCEPT_ALL) {
+ ignoreTest_ = false;
+ }
+ }
+ InnerApiPublicInfoGenerator() {}
+ InnerApiPublicInfoGenerator &operator = (const InnerApiPublicInfoGenerator &) = delete;
+};
+
+#endif // INNERAPIS_PUBLICINFO_GENERATOR_H_
diff --git a/src/gn/item.cc b/src/gn/item.cc
index 3a3a166b36c606665cd7f6bf48facd2a0aeef1cd..bedb1da2bb93feb03f3c2d8823b20adb7b6aba96 100644
--- a/src/gn/item.cc
+++ b/src/gn/item.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "gn/settings.h"
+#include "gn/build_settings.h"
Item::Item(const Settings* settings,
const Label& label,
@@ -13,7 +14,9 @@ Item::Item(const Settings* settings,
: settings_(settings),
label_(label),
build_dependency_files_(build_dependency_files),
- defined_from_(nullptr) {}
+ defined_from_(nullptr) {
+ component = settings->build_settings()->GetOhosComponent(label.GetUserVisibleName(false));
+ }
Item::~Item() = default;
diff --git a/src/gn/item.h b/src/gn/item.h
index dd1a60662fbf1376025c50946693155313c81541..efa034676c92c95fdb26b8fd575a33b29a7e2eb6 100644
--- a/src/gn/item.h
+++ b/src/gn/item.h
@@ -13,6 +13,7 @@
#include "gn/visibility.h"
class Config;
+class OhosComponent;
class ParseNode;
class Pool;
class Settings;
@@ -71,6 +72,8 @@ class Item {
// returns false on failure.
virtual bool OnResolved(Err* err);
+ const OhosComponent *ohos_component() const { return component; };
+
private:
bool CheckTestonly(Err* err) const;
@@ -81,6 +84,8 @@ class Item {
bool testonly_ = false;
Visibility visibility_;
+
+ const OhosComponent *component;
};
#endif // TOOLS_GN_ITEM_H_
diff --git a/src/gn/label_ptr.h b/src/gn/label_ptr.h
index cf30772c042ca0f58de6a323729d97004dbf7715..451acade4c927187ccad75cf25973be65bc40387 100644
--- a/src/gn/label_ptr.h
+++ b/src/gn/label_ptr.h
@@ -35,6 +35,7 @@ struct LabelPtrPair {
~LabelPtrPair() = default;
Label label;
+ bool is_external_deps;
const T* ptr = nullptr;
// The origin of this dependency. This will be null for internally generated
diff --git a/src/gn/ninja_binary_target_writer.cc b/src/gn/ninja_binary_target_writer.cc
index e3e36e56e0a1de5fe7de116724aa5ec8ab406fb2..4f9385966bb4d3de412653f1dc86f024de2ce7fa 100644
--- a/src/gn/ninja_binary_target_writer.cc
+++ b/src/gn/ninja_binary_target_writer.cc
@@ -159,7 +159,10 @@ void NinjaBinaryTargetWriter::ClassifyDependency(
if (can_link_libs && dep->builds_swift_module())
classified_deps->swiftmodule_deps.push_back(dep);
- if (target_->source_types_used().RustSourceUsed() &&
+ if (dep->output_type() == Target::COPY_FILES &&
+ dep->IsLinkable()) {
+ classified_deps->linkable_deps.push_back(dep);
+ } else if (target_->source_types_used().RustSourceUsed() &&
(target_->output_type() == Target::RUST_LIBRARY ||
target_->output_type() == Target::STATIC_LIBRARY) &&
dep->IsLinkable()) {
diff --git a/src/gn/ohos_components.cc b/src/gn/ohos_components.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ace5ad38acb48957dfc1783a15eac8e9566c9ec4
--- /dev/null
+++ b/src/gn/ohos_components.cc
@@ -0,0 +1,485 @@
+// Copyright (c) 2024 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "gn/ohos_components.h"
+
+#include
+#include
+#include