• 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 
Init(const std::string & build_dir,int checkType)27     static void Init(const std::string &build_dir, int checkType)
28     {
29         if (instance_ != nullptr) {
30             return;
31         }
32         instance_ = new OhosComponentChecker(build_dir, checkType);
33     }
34 
35     bool CheckAllDepsConfigs(const Target *target, const std::string label, Err *err) const;
36     bool CheckInnerApiIncludesOverRange(const Target *target, const std::string label, const std::string dir,
37         Err *err) const;
38     bool CheckInnerApiPublicDepsInner(const Target *target, const std::string label, const std::string deps,
39         Err *err) const;
40     bool CheckInnerApiNotLib(const Item *item, const OhosComponent *component, const std::string label, Err *err) const;
41     bool CheckInnerApiNotDeclare(const Item *item, const OhosComponent *component, const std::string label,
42         Err *err) const;
43     bool CheckIncludesAbsoluteDepsOther(const Target *target, const std::string label, const std::string includes,
44         Err *err) const;
45     bool CheckInnerApiVisibilityDenied(const Item *item, const OhosComponent *component, const std::string label,
46         const std::string deps, Err *err) const;
47     bool CheckTargetAbsoluteDepsOther(const Item *item, const OhosComponent *component, const std::string label,
48         const std::string deps, bool is_external_deps, Err *err) const;
49     bool CheckImportOther(const FunctionCallNode* function, const BuildSettings* build_settings,
50         const std::string label, const std::string deps, Err *err) const;
51 
getInstance()52     static OhosComponentChecker *getInstance()
53     {
54         return instance_;
55     }
56 
57 private:
58     int checkType_ = NONE;
59     bool ignoreTest_ = true;
60     std::string build_dir_;
61     static OhosComponentChecker *instance_;
62     bool InterceptAllDepsConfig(const Target *target, const std::string label, Err *err) const;
63     bool InterceptIncludesOverRange(const Target *target, const std::string label, const std::string dir,
64         Err *err) const;
65     bool InterceptInnerApiPublicDepsInner(const Target *target, const std::string label, const std::string deps,
66         Err *err) const;
67     bool InterceptInnerApiNotLib(const Item *item, const std::string label, Err *err) const;
68     bool InterceptInnerApiNotDeclare(const Item *item, const std::string label, Err *err) const;
69     bool InterceptIncludesAbsoluteDepsOther(const Target *target, const std::string label, const std::string includes,
70         Err *err) const;
71     bool InterceptInnerApiVisibilityDenied(const Item *item, const std::string from_label, const std::string to_label,
72         Err *err) const;
73     bool InterceptTargetAbsoluteDepsOther(const Item *item, const std::string label, const std::string deps,
74         Err *err) const;
75     bool InterceptImportOther(const FunctionCallNode* function, const std::string label, const std::string deps,
76         Err *err) const;
77     void GenerateScanList(const std::string path, const std::string subsystem, const std::string component,
78         const std::string label, const std::string deps) const;
OhosComponentChecker()79     OhosComponentChecker() {}
80     OhosComponentChecker(const std::string &build_dir, int checkType);
81     OhosComponentChecker &operator = (const OhosComponentChecker &) = delete;
82 };
83 
84 #endif // OHOS_COMPONENTS_CHECKER_H_
85