Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "Common.h" |
| 18 | |
| 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <unistd.h> |
| 22 | |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 23 | #include <algorithm> |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 24 | #include <cctype> |
| 25 | #include <cerrno> |
| 26 | #include <cmath> |
| 27 | #include <cstdlib> |
| 28 | #include <cstring> |
| 29 | #include <initializer_list> |
| 30 | #include <memory> |
| 31 | #include <regex> |
| 32 | #include <string> |
| 33 | #include <unordered_set> |
| 34 | #include <vector> |
| 35 | |
| 36 | #include <android-base/file.h> |
Inseob Kim | 1ca03f3 | 2019-06-08 16:31:59 +0900 | [diff] [blame] | 37 | #include <android-base/logging.h> |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 38 | #include <android-base/strings.h> |
| 39 | #include <google/protobuf/text_format.h> |
| 40 | |
| 41 | #include "sysprop.pb.h" |
| 42 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 43 | using android::base::Result; |
| 44 | |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 45 | namespace { |
| 46 | |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 47 | std::string GenerateDefaultPropName(const sysprop::Properties& props, |
| 48 | const sysprop::Property& prop); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 49 | bool IsCorrectIdentifier(const std::string& name); |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 50 | Result<void> ValidateProp(const sysprop::Properties& props, |
| 51 | const sysprop::Property& prop); |
| 52 | Result<void> ValidateProps(const sysprop::Properties& props); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 53 | |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 54 | std::string GenerateDefaultPropName(const sysprop::Properties& props, |
| 55 | const sysprop::Property& prop) { |
| 56 | std::string ret; |
| 57 | |
| 58 | if (prop.access() != sysprop::ReadWrite) ret = "ro."; |
| 59 | |
| 60 | switch (props.owner()) { |
| 61 | case sysprop::Vendor: |
| 62 | ret += "vendor."; |
| 63 | break; |
| 64 | case sysprop::Odm: |
| 65 | ret += "odm."; |
| 66 | break; |
| 67 | default: |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | ret += prop.api_name(); |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 76 | bool IsCorrectIdentifier(const std::string& name) { |
| 77 | if (name.empty()) return false; |
| 78 | if (std::isalpha(name[0]) == 0 && name[0] != '_') return false; |
| 79 | |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 80 | return std::all_of(name.begin() + 1, name.end(), [](char ch) { |
| 81 | return std::isalnum(ch) != 0 || ch == '_'; |
| 82 | }); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Jiyong Park | 87d439d | 2019-11-27 19:24:07 +0900 | [diff] [blame] | 85 | bool IsCorrectName(const std::string& name, |
| 86 | const std::unordered_set<char>& allowed_chars) { |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 87 | if (name.empty()) return false; |
Jiyong Park | 87d439d | 2019-11-27 19:24:07 +0900 | [diff] [blame] | 88 | if (!std::isalpha(*name.begin())) return false; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 89 | |
Jiyong Park | 87d439d | 2019-11-27 19:24:07 +0900 | [diff] [blame] | 90 | return std::all_of(name.begin(), name.end(), [allowed_chars](char ch) { |
| 91 | return std::isalnum(ch) != 0 || allowed_chars.count(ch) != 0; |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 92 | }); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 93 | } |
| 94 | |
Jiyong Park | 87d439d | 2019-11-27 19:24:07 +0900 | [diff] [blame] | 95 | bool IsCorrectPropertyName(const std::string& name) { |
| 96 | std::unordered_set<char> allowed{'_', '-', '.'}; |
| 97 | if (android::base::StartsWith(name, "ctl.")) { |
| 98 | allowed.emplace('$'); |
| 99 | } |
| 100 | return IsCorrectName(name, allowed); |
| 101 | } |
| 102 | |
| 103 | bool IsCorrectApiName(const std::string& name) { |
| 104 | static std::unordered_set<char> allowed{'_', '-'}; |
| 105 | return IsCorrectName(name, allowed); |
| 106 | } |
| 107 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 108 | Result<void> ValidateProp(const sysprop::Properties& props, |
| 109 | const sysprop::Property& prop) { |
Jiyong Park | 87d439d | 2019-11-27 19:24:07 +0900 | [diff] [blame] | 110 | if (!IsCorrectApiName(prop.api_name())) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 111 | return Errorf("Invalid API name \"{}\"", prop.api_name()); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | if (prop.type() == sysprop::Enum || prop.type() == sysprop::EnumList) { |
| 115 | std::vector<std::string> names = |
| 116 | android::base::Split(prop.enum_values(), "|"); |
| 117 | if (names.empty()) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 118 | return Errorf("Enum values are empty for API \"{}\"", prop.api_name()); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | for (const std::string& name : names) { |
| 122 | if (!IsCorrectIdentifier(name)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 123 | return Errorf("Invalid enum value \"{}\" for API \"{}\"", name, |
| 124 | prop.api_name()); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | std::unordered_set<std::string> name_set; |
| 129 | for (const std::string& name : names) { |
Inseob Kim | f346e50 | 2019-01-04 10:32:39 +0900 | [diff] [blame] | 130 | if (!name_set.insert(ToUpper(name)).second) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 131 | return Errorf("Duplicated enum value \"{}\" for API \"{}\"", name, |
| 132 | prop.api_name()); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 137 | std::string prop_name = prop.prop_name(); |
| 138 | if (prop_name.empty()) prop_name = GenerateDefaultPropName(props, prop); |
| 139 | |
Jiyong Park | 87d439d | 2019-11-27 19:24:07 +0900 | [diff] [blame] | 140 | if (!IsCorrectPropertyName(prop_name)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 141 | return Errorf("Invalid prop name \"{}\"", prop.prop_name()); |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 142 | } |
| 143 | |
Inseob Kim | 3f452c0 | 2020-03-31 13:41:19 +0900 | [diff] [blame] | 144 | std::string legacy_name = prop.legacy_prop_name(); |
Inseob Kim | 96959fb | 2020-04-22 20:13:49 +0900 | [diff] [blame] | 145 | if (!legacy_name.empty()) { |
| 146 | if (!IsCorrectPropertyName(legacy_name)) { |
| 147 | return Errorf("Invalid legacy prop name \"{}\"", legacy_name); |
| 148 | } |
| 149 | if (prop.access() != sysprop::Readonly) { |
| 150 | return Errorf("Prop \"{}\" which has legacy_prop_name must be Readonly", |
| 151 | prop.prop_name()); |
| 152 | } |
Inseob Kim | 3f452c0 | 2020-03-31 13:41:19 +0900 | [diff] [blame] | 153 | } |
| 154 | |
Inseob Kim | fcb5db7 | 2019-03-15 14:33:01 +0900 | [diff] [blame] | 155 | static const std::regex vendor_regex( |
| 156 | "(init\\.svc\\.|ro\\.|persist\\.)?vendor\\..+|ro\\.hardware\\..+"); |
| 157 | static const std::regex odm_regex( |
| 158 | "(init\\.svc\\.|ro\\.|persist\\.)?odm\\..+|ro\\.hardware\\..+"); |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 159 | |
| 160 | switch (props.owner()) { |
| 161 | case sysprop::Platform: |
| 162 | if (std::regex_match(prop_name, vendor_regex) || |
| 163 | std::regex_match(prop_name, odm_regex)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 164 | return Errorf( |
| 165 | "Prop \"{}\" owned by platform cannot have vendor. or odm. " |
| 166 | "namespace", |
| 167 | prop_name); |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 168 | } |
| 169 | break; |
| 170 | case sysprop::Vendor: |
| 171 | if (!std::regex_match(prop_name, vendor_regex)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 172 | return Errorf( |
| 173 | "Prop \"{}\" owned by vendor should have vendor. namespace", |
| 174 | prop_name); |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 175 | } |
| 176 | break; |
| 177 | case sysprop::Odm: |
| 178 | if (!std::regex_match(prop_name, odm_regex)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 179 | return Errorf("Prop \"{}\" owned by odm should have odm. namespace", |
| 180 | prop_name); |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 181 | } |
| 182 | break; |
Inseob Kim | 8802c7d | 2018-11-02 15:01:47 +0900 | [diff] [blame] | 183 | default: |
| 184 | break; |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 185 | } |
| 186 | |
Inseob Kim | 1d166c2 | 2020-07-22 11:05:24 +0900 | [diff] [blame] | 187 | if (prop.access() == sysprop::ReadWrite && |
| 188 | android::base::StartsWith(prop_name, "ro.")) { |
| 189 | return Errorf("Prop \"{}\" is ReadWrite and also have prefix \"ro.\"", |
| 190 | prop_name); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 191 | } |
| 192 | |
Inseob Kim | 9c5147d | 2019-03-06 11:36:36 +0900 | [diff] [blame] | 193 | if (prop.integer_as_bool() && !(prop.type() == sysprop::Boolean || |
| 194 | prop.type() == sysprop::BooleanList)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 195 | return Errorf("Prop \"{}\" has integer_as_bool: true, but not a boolean", |
| 196 | prop_name); |
Inseob Kim | 9c5147d | 2019-03-06 11:36:36 +0900 | [diff] [blame] | 197 | } |
| 198 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 199 | return {}; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 200 | } |
| 201 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 202 | Result<void> ValidateProps(const sysprop::Properties& props) { |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 203 | std::vector<std::string> names = android::base::Split(props.module(), "."); |
| 204 | if (names.size() <= 1) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 205 | return Errorf("Invalid module name \"{}\"", props.module()); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | for (const auto& name : names) { |
| 209 | if (!IsCorrectIdentifier(name)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 210 | return Errorf("Invalid name \"{}\" in module", name); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 214 | if (props.prop_size() == 0) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 215 | return Errorf("There is no defined property"); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | for (int i = 0; i < props.prop_size(); ++i) { |
| 219 | const auto& prop = props.prop(i); |
Bernie Innocenti | 7ac8da4 | 2020-02-06 23:30:12 +0900 | [diff] [blame] | 220 | if (auto res = ValidateProp(props, prop); !res.ok()) return res; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | std::unordered_set<std::string> prop_names; |
Inseob Kim | 1d316fc | 2020-04-09 22:29:28 +0900 | [diff] [blame] | 224 | std::unordered_map<std::string, sysprop::Type> prop_types; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 225 | |
| 226 | for (int i = 0; i < props.prop_size(); ++i) { |
| 227 | const auto& prop = props.prop(i); |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 228 | auto res = prop_names.insert(ApiNameToIdentifier(prop.api_name())); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 229 | |
| 230 | if (!res.second) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 231 | return Errorf("Duplicated API name \"{}\"", prop.api_name()); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 232 | } |
Inseob Kim | 1d316fc | 2020-04-09 22:29:28 +0900 | [diff] [blame] | 233 | |
| 234 | std::vector<std::string> prop_names{prop.prop_name()}; |
| 235 | std::string legacy_name = prop.legacy_prop_name(); |
| 236 | if (!legacy_name.empty()) prop_names.push_back(legacy_name); |
| 237 | |
| 238 | sysprop::Type type = prop.type(); |
| 239 | |
| 240 | for (auto& name : prop_names) { |
| 241 | // get type if already exists. inserts mine if not. |
| 242 | sysprop::Type prev_type = prop_types.emplace(name, type).first->second; |
| 243 | if (prev_type != type) { |
| 244 | return Errorf("Type error on prop \"{}\": it's {} but was {}", name, |
| 245 | sysprop::Type_Name(type), sysprop::Type_Name(prev_type)); |
| 246 | } |
| 247 | } |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 248 | } |
| 249 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 250 | return {}; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 251 | } |
| 252 | |
Inseob Kim | 900fbad | 2019-06-26 14:09:20 +0900 | [diff] [blame] | 253 | void SetDefaultValues(sysprop::Properties* props) { |
| 254 | for (int i = 0; i < props->prop_size(); ++i) { |
| 255 | // set each optional field to its default value |
| 256 | sysprop::Property& prop = *props->mutable_prop(i); |
| 257 | if (prop.prop_name().empty()) |
| 258 | prop.set_prop_name(GenerateDefaultPropName(*props, prop)); |
| 259 | if (prop.scope() == sysprop::Scope::System) { |
| 260 | LOG(WARNING) << "Sysprop API " << prop.api_name() |
| 261 | << ": System scope is deprecated." |
| 262 | << " Please use Public scope instead."; |
| 263 | prop.set_scope(sysprop::Scope::Public); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 268 | } // namespace |
| 269 | |
Inseob Kim | b04d619 | 2018-12-14 08:33:16 +0900 | [diff] [blame] | 270 | bool IsListProp(const sysprop::Property& prop) { |
| 271 | switch (prop.type()) { |
| 272 | case sysprop::BooleanList: |
| 273 | case sysprop::IntegerList: |
| 274 | case sysprop::LongList: |
| 275 | case sysprop::DoubleList: |
| 276 | case sysprop::StringList: |
| 277 | case sysprop::EnumList: |
Inseob Kim | 22133ec | 2020-10-28 22:08:07 +0900 | [diff] [blame] | 278 | case sysprop::UIntList: |
| 279 | case sysprop::ULongList: |
Inseob Kim | b04d619 | 2018-12-14 08:33:16 +0900 | [diff] [blame] | 280 | return true; |
| 281 | default: |
| 282 | return false; |
| 283 | } |
| 284 | } |
| 285 | |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 286 | std::string GetModuleName(const sysprop::Properties& props) { |
| 287 | const std::string& module = props.module(); |
| 288 | return module.substr(module.rfind('.') + 1); |
| 289 | } |
| 290 | |
Inseob Kim | 472fb63 | 2020-03-21 03:29:39 +0900 | [diff] [blame] | 291 | std::vector<std::string> ParseEnumValues(const std::string& enum_values) { |
| 292 | return android::base::Split(enum_values, "|"); |
| 293 | } |
| 294 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 295 | Result<sysprop::Properties> ParseProps(const std::string& input_file_path) { |
| 296 | sysprop::Properties ret; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 297 | std::string file_contents; |
| 298 | |
| 299 | if (!android::base::ReadFileToString(input_file_path, &file_contents, true)) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 300 | return ErrnoErrorf("Error reading file {}", input_file_path); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 301 | } |
| 302 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 303 | if (!google::protobuf::TextFormat::ParseFromString(file_contents, &ret)) { |
| 304 | return Errorf("Error parsing file {}", input_file_path); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 305 | } |
| 306 | |
Inseob Kim | 1d316fc | 2020-04-09 22:29:28 +0900 | [diff] [blame] | 307 | SetDefaultValues(&ret); |
| 308 | |
| 309 | // validate after filling default values such as prop_name |
Bernie Innocenti | 7ac8da4 | 2020-02-06 23:30:12 +0900 | [diff] [blame] | 310 | if (auto res = ValidateProps(ret); !res.ok()) { |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 311 | return res.error(); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 312 | } |
| 313 | |
Inseob Kim | 900fbad | 2019-06-26 14:09:20 +0900 | [diff] [blame] | 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | Result<sysprop::SyspropLibraryApis> ParseApiFile( |
| 318 | const std::string& input_file_path) { |
| 319 | sysprop::SyspropLibraryApis ret; |
| 320 | std::string file_contents; |
| 321 | |
| 322 | if (!android::base::ReadFileToString(input_file_path, &file_contents, true)) { |
| 323 | return ErrnoErrorf("Error reading file {}", input_file_path); |
| 324 | } |
| 325 | |
| 326 | if (!google::protobuf::TextFormat::ParseFromString(file_contents, &ret)) { |
| 327 | return Errorf("Error parsing file {}", input_file_path); |
| 328 | } |
| 329 | |
| 330 | std::unordered_set<std::string> modules; |
| 331 | |
| 332 | for (int i = 0; i < ret.props_size(); ++i) { |
| 333 | sysprop::Properties* props = ret.mutable_props(i); |
| 334 | |
| 335 | if (!modules.insert(props->module()).second) { |
| 336 | return Errorf("Error parsing file {}: duplicated module {}", |
| 337 | input_file_path, props->module()); |
Inseob Kim | 1ca03f3 | 2019-06-08 16:31:59 +0900 | [diff] [blame] | 338 | } |
Inseob Kim | 900fbad | 2019-06-26 14:09:20 +0900 | [diff] [blame] | 339 | |
Inseob Kim | 1d316fc | 2020-04-09 22:29:28 +0900 | [diff] [blame] | 340 | SetDefaultValues(props); |
| 341 | |
| 342 | // validate after filling default values such as prop_name |
Bernie Innocenti | 7ac8da4 | 2020-02-06 23:30:12 +0900 | [diff] [blame] | 343 | if (auto res = ValidateProps(*props); !res.ok()) { |
Inseob Kim | 900fbad | 2019-06-26 14:09:20 +0900 | [diff] [blame] | 344 | return res.error(); |
| 345 | } |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 346 | } |
| 347 | |
Inseob Kim | 053b83d | 2019-06-26 13:41:51 +0900 | [diff] [blame] | 348 | return ret; |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 349 | } |
| 350 | |
Inseob Kim | f346e50 | 2019-01-04 10:32:39 +0900 | [diff] [blame] | 351 | std::string ToUpper(std::string str) { |
| 352 | for (char& ch : str) { |
| 353 | ch = toupper(ch); |
| 354 | } |
| 355 | return str; |
| 356 | } |
| 357 | |
Inseob Kim | 14e5187 | 2018-10-25 14:27:33 +0900 | [diff] [blame] | 358 | std::string ApiNameToIdentifier(const std::string& name) { |
| 359 | static const std::regex kRegexAllowed{"-|\\."}; |
| 360 | return (isdigit(name[0]) ? "_" : "") + |
| 361 | std::regex_replace(name, kRegexAllowed, "_"); |
Inseob Kim | 5f8f32c | 2018-08-24 11:10:44 +0900 | [diff] [blame] | 362 | } |