• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
name()21     const std::string &name() const
22     {
23         return name_;
24     }
subsystem()25     const std::string &subsystem() const
26     {
27         return subsystem_;
28     }
path()29     const std::string &path() const
30     {
31         return path_;
32     }
33 
34     void addInnerApi(const std::string &name, const std::string &label);
35 
36     const std::string &getInnerApi(const std::string &innerapi) const;
37 
38     void addInnerApiVisibility(const std::string &name, const std::vector<base::Value> &list);
39 
40     const std::vector<std::string> getInnerApiVisibility(const std::string &label) const;
41 
42     bool isInnerApi(const std::string &label) const;
43 
44 private:
45     std::string name_;
46     std::string subsystem_;
47     std::string path_;
48 
49     // InnerApi name to label map
50     std::map<std::string, std::string> innerapi_names_;
51 
52     // InnerApi label to name map
53     std::map<std::string, std::string> innerapi_labels_;
54 
55     // InnerApi lable to visibility map
56     std::map<std::string, std::vector<std::string>> innerapi_visibility_;
57 
58     OhosComponent &operator = (const OhosComponent &) = delete;
59 };
60 
61 class OhosComponentsImpl;
62 
63 class OhosComponents {
64 public:
65     OhosComponents();
66 
67     bool LoadOhosComponents(const std::string &build_dir, const Value *enable,
68         const Value *indep, const Value *product, Err *err);
69 
70     bool isOhosComponentsLoaded() const;
71 
72     bool isOhosIndepCompilerEnable();
73     bool GetExternalDepsLabel(const Value &external_dep, std::string &label,
74         const Label& current_toolchain, int &whole_status, Err *err) const;
75     bool GetPrivateDepsLabel(const Value &dep, std::string &label,
76         const Label& current_toolchain, int &whole_status, Err *err) const;
77     bool GetSubsystemName(const Value &part_name, std::string &label, Err *err) const;
78 
79     const OhosComponent *GetComponentByLabel(const std::string &label) const;
80 
81     void LoadOhosComponentsChecker(const std::string &build_dir, const Value *support, int checkType,
82         unsigned int ruleSwitch);
83 
84     void LoadOhosComponentsMapping(const std::string& build_dir, const Value *support, const Value *independent);
85 
86     const OhosComponent *GetComponentByName(const std::string &basicString);
87 
88 private:
89     OhosComponentsImpl *mgr = nullptr;
90 
91     OhosComponents &operator = (const OhosComponents &) = delete;
92 };
93 
94 #endif // TOOLS_GN_OHOS_COMPONENTS_H_
95