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 PUBLIC_DEPS_BINARY, 39 LIB_DIRS_BINARY, 40 ALL 41 }; 42 Init(const std::string & build_dir,int checkType,unsigned int ruleSwitch)43 static void Init(const std::string &build_dir, int checkType, unsigned int ruleSwitch) 44 { 45 if (instance_ != nullptr) { 46 return; 47 } 48 instance_ = new OhosComponentChecker(build_dir, checkType, ruleSwitch); 49 } 50 51 bool CheckAllDepsConfigs(const Target *target, const std::string &label, Err *err) const; 52 bool CheckInnerApiIncludesOverRange(const Target *target, const std::string &label, const std::string &dir, 53 Err *err) const; 54 bool CheckInnerApiPublicDepsInner(const Target *target, const std::string &label, const std::string &deps, 55 Err *err) const; 56 bool CheckPublicDeps(const Target *target, const std::string &label, const std::string &deps, 57 Err *err) const; 58 bool CheckLibDir(const Target *target, const std::string &label, const std::string &dir, Err *err) const; 59 bool CheckInnerApiNotLib(const Item *item, const OhosComponent *component, const std::string &label, 60 const std::string &deps, Err *err) const; 61 bool CheckInnerApiNotDeclare(const Item *item, const OhosComponent *component, const std::string &label, 62 Err *err) const; 63 bool CheckIncludesAbsoluteDepsOther(const Target *target, const std::string &label, const std::string &includes, 64 Err *err) const; 65 bool CheckInnerApiVisibilityDenied(const Item *item, const OhosComponent *component, const std::string &label, 66 const std::string &deps, Err *err) const; 67 bool CheckTargetAbsoluteDepsOther(const Item *item, const OhosComponent *component, const std::string &label, 68 const std::string &deps, bool is_external_deps, Err *err) const; 69 bool CheckImportOther(const FunctionCallNode *function, const BuildSettings *build_settings, 70 const std::string &label, const std::string &deps, Err *err) const; 71 getInstance()72 static OhosComponentChecker *getInstance() 73 { 74 return instance_; 75 } 76 77 private: 78 int checkType_ = NONE; 79 bool ignoreTest_ = true; 80 unsigned int ruleSwitch_; 81 std::string build_dir_; 82 static OhosComponentChecker *instance_; 83 bool InterceptAllDepsConfig(const Target *target, const std::string &label, Err *err) const; 84 bool InterceptIncludesOverRange(const Target *target, const std::string &label, const std::string &dir, 85 Err *err) const; 86 bool InterceptInnerApiPublicDepsInner(const Target *target, const std::string &label, const std::string &deps, 87 Err *err) const; 88 bool InterceptPublicDeps(const Target *target, const std::string &label, const std::string &deps, 89 Err *err) const; 90 bool InterceptLibDir(const Target *target, const std::string &label, const std::string &dir, Err *err) const; 91 bool InterceptInnerApiNotLib(const Item *item, const std::string &label, Err *err) const; 92 bool InterceptDepsNotLib(const Item *item, const std::string &label, const std::string &deps, Err *err) const; 93 bool InterceptInnerApiNotDeclare(const Item *item, const std::string &label, Err *err) const; 94 bool InterceptIncludesAbsoluteDepsOther(const Target *target, const std::string &label, const std::string &includes, 95 Err *err) const; 96 bool InterceptInnerApiVisibilityDenied(const Item *item, const std::string &from_label, const std::string &to_label, 97 Err *err) const; 98 bool InterceptTargetAbsoluteDepsOther(const Item *item, const std::string &label, const std::string &deps, 99 Err *err) const; 100 bool InterceptImportOther(const FunctionCallNode* function, const std::string &label, const std::string &deps, 101 Err *err) const; 102 void GenerateScanList(const std::string &path, const std::string &subsystem, const std::string &component, 103 const std::string &label, const std::string &deps) const; OhosComponentChecker()104 OhosComponentChecker() {} 105 OhosComponentChecker(const std::string &build_dir, int checkType, unsigned int ruleSwitch); 106 OhosComponentChecker &operator = (const OhosComponentChecker &) = delete; 107 }; 108 109 #endif // OHOS_COMPONENTS_CHECKER_H_ 110