1 // Copyright (c) 2024 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_GN_OHOS_COMPONENTS_H_ 6 #define TOOLS_GN_OHOS_COMPONENTS_H_ 7 8 #include <map> 9 #include <mutex> 10 11 #include "base/files/file_path.h" 12 #include "base/values.h" 13 #include "gn/err.h" 14 #include "gn/value.h" 15 16 class OhosComponent { 17 public: 18 OhosComponent(); 19 OhosComponent(const char *name, const char *subsystem, const char *path, 20 const std::vector<std::string> &modulePath, bool special_parts_switch); 21 name()22 const std::string &name() const 23 { 24 return name_; 25 } subsystem()26 const std::string &subsystem() const 27 { 28 return subsystem_; 29 } path()30 const std::string &path() const 31 { 32 return path_; 33 } modulePath()34 const std::vector<std::string> &modulePath() const 35 { 36 return module_path_; 37 } specialPartsSwitch()38 const bool &specialPartsSwitch() const 39 { 40 return special_parts_switch_; 41 } 42 void addInnerApi(const std::string &name, const std::string &label); 43 44 const std::string &getInnerApi(const std::string &innerapi) const; 45 46 void addInnerApiVisibility(const std::string &name, const std::vector<base::Value> &list); 47 48 const std::vector<std::string> getInnerApiVisibility(const std::string &label) const; 49 50 bool isInnerApi(const std::string &label) const; 51 52 private: 53 std::string name_; 54 std::string subsystem_; 55 std::string path_; 56 std::vector<std::string> module_path_; 57 bool special_parts_switch_ = false; 58 59 // InnerApi name to label map 60 std::map<std::string, std::string> innerapi_names_; 61 62 // InnerApi label to name map 63 std::map<std::string, std::string> innerapi_labels_; 64 65 // InnerApi lable to visibility map 66 std::map<std::string, std::vector<std::string>> innerapi_visibility_; 67 68 OhosComponent &operator = (const OhosComponent &) = delete; 69 }; 70 71 class OhosComponentsImpl; 72 73 class OhosComponents { 74 public: 75 OhosComponents(); 76 77 bool LoadOhosComponents(const std::string &build_dir, const Value *enable, 78 const Value *indep, const Value *product, bool special_parts_switch, Err *err); 79 80 bool isOhosComponentsLoaded() const; 81 82 bool isOhosIndepCompilerEnable(); 83 bool GetExternalDepsLabel(const Value &external_dep, std::string &label, 84 const Label& current_toolchain, int &whole_status, Err *err) const; 85 bool GetPrivateDepsLabel(const Value &dep, std::string &label, 86 const Label& current_toolchain, int &whole_status, Err *err) const; 87 bool GetSubsystemName(const Value &part_name, std::string &label, Err *err) const; 88 89 const OhosComponent *GetComponentByLabel(const std::string &label) const; 90 91 void LoadOhosComponentsChecker(const std::string &build_dir, const Value *support, int checkType, 92 unsigned int ruleSwitch); 93 94 void LoadOhosComponentsMapping(const std::string& build_dir, const Value *support, const Value *independent); 95 96 const OhosComponent *GetComponentByName(const std::string &basicString); 97 98 private: 99 OhosComponentsImpl *mgr = nullptr; 100 101 OhosComponents &operator = (const OhosComponents &) = delete; 102 }; 103 104 #endif // TOOLS_GN_OHOS_COMPONENTS_H_ 105