mirror of
https://gitee.com/openharmony/third_party_gn
synced 2024-11-27 03:40:25 +00:00
revert 在 publicinfo 中增加 flags 信息
Signed-off-by: flying <pengmengjie1@huawei.com>
This commit is contained in:
parent
4f0f88a819
commit
2bd1c92071
@ -687,7 +687,6 @@ def WriteGNNinja(path, platform, host, options, args_list):
|
||||
'src/gn/import_manager.cc',
|
||||
'src/gn/inherited_libraries.cc',
|
||||
"src/gn/innerapis_publicinfo_generator.cc",
|
||||
"src/gn/install_info_generator.cc",
|
||||
'src/gn/input_conversion.cc',
|
||||
'src/gn/input_file.cc',
|
||||
'src/gn/input_file_manager.cc',
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "gn/substitution_writer.h"
|
||||
#include "gn/target.h"
|
||||
#include "gn/value.h"
|
||||
#include "gn/variables.h"
|
||||
|
||||
InnerApiPublicInfoGenerator *InnerApiPublicInfoGenerator::instance_ = nullptr;
|
||||
|
||||
@ -137,45 +136,7 @@ static std::string GetIncludeDirsInfo(const Config *config, const OhosComponentC
|
||||
return "";
|
||||
}
|
||||
}
|
||||
info += "\n ]";
|
||||
return info;
|
||||
}
|
||||
|
||||
static std::string GetFlagsInfo(const Config *config)
|
||||
{
|
||||
std::string info;
|
||||
|
||||
#define GET_FLAGS_INFO(flags) \
|
||||
const std::vector<std::string> flags = config->own_values().flags(); \
|
||||
if (!flags.empty()) { \
|
||||
info +=",\n \""; \
|
||||
info += #flags; \
|
||||
info += "\": [\n "; \
|
||||
bool first_##flags = true; \
|
||||
for (const std::string &flag : flags) { \
|
||||
if (!first_##flags) { \
|
||||
info += ",\n "; \
|
||||
} \
|
||||
first_##flags = false; \
|
||||
info += "\"" + flag + "\""; \
|
||||
} \
|
||||
info += "\n ]"; \
|
||||
}
|
||||
|
||||
GET_FLAGS_INFO(arflags)
|
||||
GET_FLAGS_INFO(asmflags)
|
||||
GET_FLAGS_INFO(cflags)
|
||||
GET_FLAGS_INFO(cflags_c)
|
||||
GET_FLAGS_INFO(cflags_cc)
|
||||
GET_FLAGS_INFO(cflags_objc)
|
||||
GET_FLAGS_INFO(cflags_objcc)
|
||||
GET_FLAGS_INFO(ldflags)
|
||||
GET_FLAGS_INFO(rustflags)
|
||||
GET_FLAGS_INFO(swiftflags)
|
||||
|
||||
#undef GET_FLAGS_INFO
|
||||
|
||||
info += "\n";
|
||||
info += "\n ]\n";
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -203,7 +164,6 @@ static std::string GetPublicConfigInfo(const PublicConfigInfoParams ¶ms, Sco
|
||||
}
|
||||
PublicConfigInfoParams params = { target, label, err };
|
||||
info += GetIncludeDirsInfo(as_config, checker, isPublic, params);
|
||||
info += GetFlagsInfo(as_config);
|
||||
}
|
||||
info += " }";
|
||||
}
|
||||
@ -382,4 +342,4 @@ void InnerApiPublicInfoGenerator::GeneratedInnerapiPublicInfo(Target *target, La
|
||||
publicfile << info;
|
||||
publicfile.close();
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
// 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/install_info_generator.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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"
|
||||
#include "gn/variables.h"
|
||||
|
||||
InstallInfoGenerator *InstallInfoGenerator::instance_ = nullptr;
|
||||
std::unordered_map<std::string, std::vector<std::string>> InstallInfoGenerator::labelInstallInfo_{};
|
||||
|
||||
namespace {
|
||||
bool StartWith(const std::string &str, const std::string prefix)
|
||||
{
|
||||
return (str.rfind(prefix, 0) == 0);
|
||||
}
|
||||
|
||||
bool EndWith(const std::string &str, const std::string suffix)
|
||||
{
|
||||
auto pos = str.rfind(suffix);
|
||||
return (pos != std::string::npos)
|
||||
&& (pos + suffix.size() == str.size());
|
||||
}
|
||||
|
||||
bool IsFileExists(const std::string &path)
|
||||
{
|
||||
if (access(path.c_str(), F_OK) == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::string GetInstallImages(const std::vector<std::string>& install_images)
|
||||
{
|
||||
std::string info = "";
|
||||
if (!install_images.empty()) {
|
||||
info += ",\n \"install_images\":[";
|
||||
bool first = true;
|
||||
for (const auto& item : install_images) {
|
||||
if (first) {
|
||||
first = false;
|
||||
info += "\n \"" + item + "\"";
|
||||
} else {
|
||||
info += ",\n \"" + item + "\"";
|
||||
}
|
||||
}
|
||||
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 + "\"";
|
||||
return info;
|
||||
}
|
||||
|
||||
std::string GetComponentInfo(const std::string &subsystem, const std::string &component, const std::string &path)
|
||||
{
|
||||
std::string info = "";
|
||||
info += ",\n \"subsystem\":\"" + subsystem + "\"";
|
||||
info += ",\n \"component\":\"" + component + "\"";
|
||||
info += ",\n \"path\":\"" + path + "\"";
|
||||
info += "\n}\n";
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
void InstallInfoGenerator::GeneratedInstallInfo(Target *target, Label label,
|
||||
Scope *scope, const std::string type, Err *err)
|
||||
{
|
||||
if (target == nullptr || (ignoreTest_ && target->testonly())) {
|
||||
return;
|
||||
}
|
||||
|
||||
const OhosComponent *component = target->ohos_component();
|
||||
if (target->testonly() || component == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Value* install_images_list = scope->GetValue("install_images");
|
||||
const std::string COLLECT_SUFFIX{"__collect"};
|
||||
std::string labelString = label.GetUserVisibleName(false);
|
||||
std::string labelCollect = labelString + COLLECT_SUFFIX;
|
||||
if (install_images_list != nullptr && EndWith(labelString, COLLECT_SUFFIX)) {
|
||||
if (labelInstallInfo_.find(labelString) == labelInstallInfo_.end()) {
|
||||
labelInstallInfo_[labelString] = {};
|
||||
}
|
||||
for (const auto& item : install_images_list->list_value()) {
|
||||
labelInstallInfo_[labelString].emplace_back(item.string_value());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (labelInstallInfo_.find(labelCollect) == labelInstallInfo_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string info = "{\n \"label\": \"" + labelString + "\"";
|
||||
info += GetInstallImages(labelInstallInfo_.at(labelCollect));
|
||||
int pos = labelString.find(":");
|
||||
std::string targetName = labelString.substr(pos + 1, labelString.length() - 1);
|
||||
info += GetOutNameAndTypeInfo(scope, targetName, type);
|
||||
info += GetComponentInfo(component->subsystem(), component->name(), component->path());
|
||||
|
||||
const std::string dir = build_dir_ + "/" + component->subsystem() + "/" + component->name() + "/install_info";
|
||||
base::FilePath path(dir);
|
||||
base::CreateDirectory(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;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
// 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 INSTALL_INFO_GENERATOR_H_
|
||||
#define INSTALL_INFO_GENERATOR_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#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 InstallInfoParams {
|
||||
const Target *target;
|
||||
std::string label;
|
||||
Err *err;
|
||||
};
|
||||
|
||||
class InstallInfoGenerator {
|
||||
public:
|
||||
void GeneratedInstallInfo(Target *target, Label label, Scope *scope, const std::string type, Err *err);
|
||||
|
||||
static InstallInfoGenerator *getInstance()
|
||||
{
|
||||
return instance_;
|
||||
}
|
||||
|
||||
static void Init(const std::string &build_dir, int checkType)
|
||||
{
|
||||
if (instance_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
instance_ = new InstallInfoGenerator(build_dir, checkType);
|
||||
}
|
||||
|
||||
private:
|
||||
bool ignoreTest_ = true;
|
||||
std::string build_dir_;
|
||||
int checkType_ = OhosComponentChecker::CheckType::NONE;
|
||||
static InstallInfoGenerator *instance_;
|
||||
static std::unordered_map<std::string, std::vector<std::string>> labelInstallInfo_;
|
||||
InstallInfoGenerator(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;
|
||||
}
|
||||
}
|
||||
InstallInfoGenerator() {}
|
||||
InstallInfoGenerator &operator = (const InstallInfoGenerator &) = delete;
|
||||
};
|
||||
|
||||
#endif // INSTALL_INFO_GENERATOR_H_
|
@ -15,7 +15,6 @@
|
||||
#include "gn/err.h"
|
||||
#include "gn/filesystem_utils.h"
|
||||
#include "gn/innerapis_publicinfo_generator.h"
|
||||
#include "gn/install_info_generator.h"
|
||||
#include "gn/ohos_components_checker.h"
|
||||
#include "gn/ohos_components_impl.h"
|
||||
#include "gn/ohos_components_mapping.h"
|
||||
@ -273,7 +272,7 @@ void OhosComponentsImpl::LoadInnerApi(const std::string &component_name, const s
|
||||
for (const base::Value &kv : innerapis) {
|
||||
const base::Value *label = kv.FindKey("label");
|
||||
const base::Value *name = kv.FindKey("name");
|
||||
|
||||
|
||||
if (!label || !name) {
|
||||
continue;
|
||||
}
|
||||
@ -324,7 +323,7 @@ void OhosComponentsImpl::LoadToolchain(const Value *product)
|
||||
if (!content_value->GetAsDictionary(&content_dict)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (const auto com : content_dict->DictItems()) {
|
||||
if (com.first == "product_toolchain_label") {
|
||||
toolchain_ = com.second.GetString();
|
||||
@ -580,12 +579,10 @@ void OhosComponents::LoadOhosComponentsChecker(const std::string &build_dir, con
|
||||
if (checkType > OhosComponentChecker::CheckType::INTERCEPT_ALL ||
|
||||
checkType <= OhosComponentChecker::CheckType::NONE) {
|
||||
InnerApiPublicInfoGenerator::Init(build_dir, 0);
|
||||
InstallInfoGenerator::Init(build_dir, 0);
|
||||
return;
|
||||
}
|
||||
OhosComponentChecker::Init(build_dir, checkType);
|
||||
InnerApiPublicInfoGenerator::Init(build_dir, checkType);
|
||||
InstallInfoGenerator::Init(build_dir, checkType);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -605,4 +602,4 @@ void OhosComponents::LoadOhosComponentsMapping(const std::string& build_dir,
|
||||
|
||||
OhosComponentMapping::Init(build_dir);
|
||||
return;
|
||||
}
|
||||
}
|
@ -22,7 +22,6 @@
|
||||
#include "gn/generated_file_target_generator.h"
|
||||
#include "gn/group_target_generator.h"
|
||||
#include "gn/innerapis_publicinfo_generator.h"
|
||||
#include "gn/install_info_generator.h"
|
||||
#include "gn/metadata.h"
|
||||
#include "gn/ohos_components.h"
|
||||
#include "gn/ohos_variables.h"
|
||||
@ -174,12 +173,6 @@ void TargetGenerator::GenerateTarget(Scope* scope,
|
||||
if (instance != nullptr) {
|
||||
instance->GeneratedInnerapiPublicInfo(target.get(), label, scope, output_type, err);
|
||||
}
|
||||
|
||||
InstallInfoGenerator* install_info_instance = InstallInfoGenerator::getInstance();
|
||||
if (install_info_instance != nullptr) {
|
||||
install_info_instance->GeneratedInstallInfo(target.get(), label, scope, output_type, err);
|
||||
}
|
||||
|
||||
collector->push_back(std::move(target));
|
||||
}
|
||||
|
||||
@ -498,4 +491,4 @@ bool TargetGenerator::FillWriteRuntimeDeps() {
|
||||
target_->set_write_runtime_deps_output(output_file);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user