• 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 OHOS_COMPONENTS_CHECKER_H_
6 #define OHOS_COMPONENTS_CHECKER_H_
7 
8 #include "gn/build_settings.h"
9 #include "gn/config.h"
10 #include "gn/functions.h"
11 #include "gn/parse_tree.h"
12 #include "gn/settings.h"
13 #include "gn/substitution_writer.h"
14 #include "gn/target.h"
15 #include "gn/value.h"
16 
17 class OhosComponentChecker {
18 public:
19     enum CheckType {
20         NONE = 0,
21         SCAN_IGNORE_TEST,
22         SCAN_ALL,
23         INTERCEPT_IGNORE_TEST,
24         INTERCEPT_ALL
25     };
26     enum BinaryLeftShift {
27         UNKNOWN = 0,
28         ALL_DEPS_CONFIG_BINARY,
29         INCLUDE_OVER_RANGE_BINARY,
30         INNERAPI_PUBLIC_DEPS_INNER_BINARY,
31         INNERAPI_NOT_LIB_BINARY,
32         DEPS_NOT_LIB_BINARY,
33         INNERAPI_NOT_DECLARE_BINARY,
34         INCLUDES_ABSOLUTE_DEPS_OTHER_BINARY,
35         TARGET_ABSOLUTE_DEPS_OTHER_BINARY,
36         IMPORT_OTHER_BINARY,
37         INNERAPI_VISIBILITY_DENIED,
38         ALL
39     };
40 
Init(const std::string & build_dir,int checkType,unsigned int ruleSwitch)41     static void Init(const std::string &build_dir, int checkType, unsigned int ruleSwitch)
42     {
43         if (instance_ != nullptr) {
44             return;
45         }
46         instance_ = new OhosComponentChecker(build_dir, checkType, ruleSwitch);
47     }
48 
49     bool CheckAllDepsConfigs(const Target *target, const std::string &label, Err *err) const;
50     bool CheckInnerApiIncludesOverRange(const Target *target, const std::string &label, const std::string &dir,
51         Err *err) const;
52     bool CheckInnerApiPublicDepsInner(const Target *target, const std::string &label, const std::string &deps,
53         Err *err) const;
54     bool CheckInnerApiNotLib(const Item *item, const OhosComponent *component, const std::string &label,
55         const std::string &deps, Err *err) const;
56     bool CheckInnerApiNotDeclare(const Item *item, const OhosComponent *component, const std::string &label,
57         Err *err) const;
58     bool CheckIncludesAbsoluteDepsOther(const Target *target, const std::string &label, const std::string &includes,
59         Err *err) const;
60     bool CheckInnerApiVisibilityDenied(const Item *item, const OhosComponent *component, const std::string &label,
61         const std::string &deps, Err *err) const;
62     bool CheckTargetAbsoluteDepsOther(const Item *item, const OhosComponent *component, const std::string &label,
63         const std::string &deps, bool is_external_deps, Err *err) const;
64     bool CheckImportOther(const FunctionCallNode *function, const BuildSettings *build_settings,
65         const std::string &label, const std::string &deps, Err *err) const;
66 
getInstance()67     static OhosComponentChecker *getInstance()
68     {
69         return instance_;
70     }
71 
72 private:
73     int checkType_ = NONE;
74     bool ignoreTest_ = true;
75     unsigned int ruleSwitch_;
76     std::string build_dir_;
77     static OhosComponentChecker *instance_;
78     bool InterceptAllDepsConfig(const Target *target, const std::string &label, Err *err) const;
79     bool InterceptIncludesOverRange(const Target *target, const std::string &label, const std::string &dir,
80         Err *err) const;
81     bool InterceptInnerApiPublicDepsInner(const Target *target, const std::string &label, const std::string &deps,
82         Err *err) const;
83     bool InterceptInnerApiNotLib(const Item *item, const std::string &label, Err *err) const;
84     bool InterceptDepsNotLib(const Item *item, const std::string &label, const std::string &deps, Err *err) const;
85     bool InterceptInnerApiNotDeclare(const Item *item, const std::string &label, Err *err) const;
86     bool InterceptIncludesAbsoluteDepsOther(const Target *target, const std::string &label, const std::string &includes,
87         Err *err) const;
88     bool InterceptInnerApiVisibilityDenied(const Item *item, const std::string &from_label, const std::string &to_label,
89         Err *err) const;
90     bool InterceptTargetAbsoluteDepsOther(const Item *item, const std::string &label, const std::string &deps,
91         Err *err) const;
92     bool InterceptImportOther(const FunctionCallNode* function, const std::string &label, const std::string &deps,
93         Err *err) const;
94     void GenerateScanList(const std::string &path, const std::string &subsystem, const std::string &component,
95         const std::string &label, const std::string &deps) const;
OhosComponentChecker()96     OhosComponentChecker() {}
97     OhosComponentChecker(const std::string &build_dir, int checkType, unsigned int ruleSwitch);
98     OhosComponentChecker &operator = (const OhosComponentChecker &) = delete;
99 };
100 
101 #endif // OHOS_COMPONENTS_CHECKER_H_
102