blob: 7214f1a68d2c7125dcacb75d9f811058a71f79e7 [file] [log] [blame]
Adam Lesinskid0f492d2017-04-03 18:12:45 -07001/*
2 * Copyright (C) 2017 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 "cmd/Util.h"
18
19#include <vector>
20
21#include "android-base/logging.h"
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020022#include "androidfw/ConfigDescription.h"
23#include "androidfw/Locale.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070024
Adam Lesinskid0f492d2017-04-03 18:12:45 -070025#include "ResourceUtils.h"
26#include "ValueVisitor.h"
27#include "split/TableSplitter.h"
28#include "util/Maybe.h"
29#include "util/Util.h"
30
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020031using ::android::ConfigDescription;
32using ::android::LocaleValue;
Adam Lesinski6b372992017-08-09 10:54:23 -070033using ::android::StringPiece;
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -070034using ::android::base::StringPrintf;
Adam Lesinskid0f492d2017-04-03 18:12:45 -070035
36namespace aapt {
37
38Maybe<uint16_t> ParseTargetDensityParameter(const StringPiece& arg, IDiagnostics* diag) {
39 ConfigDescription preferred_density_config;
40 if (!ConfigDescription::Parse(arg, &preferred_density_config)) {
41 diag->Error(DiagMessage() << "invalid density '" << arg << "' for --preferred-density option");
42 return {};
43 }
44
45 // Clear the version that can be automatically added.
46 preferred_density_config.sdkVersion = 0;
47
48 if (preferred_density_config.diff(ConfigDescription::DefaultConfig()) !=
49 ConfigDescription::CONFIG_DENSITY) {
50 diag->Error(DiagMessage() << "invalid preferred density '" << arg << "'. "
51 << "Preferred density must only be a density value");
52 return {};
53 }
54 return preferred_density_config.density;
55}
56
57bool ParseSplitParameter(const StringPiece& arg, IDiagnostics* diag, std::string* out_path,
58 SplitConstraints* out_split) {
59 CHECK(diag != nullptr);
60 CHECK(out_path != nullptr);
61 CHECK(out_split != nullptr);
62
Adam Lesinskidb091572017-04-13 12:48:56 -070063#ifdef _WIN32
64 const char sSeparator = ';';
65#else
66 const char sSeparator = ':';
67#endif
68
69 std::vector<std::string> parts = util::Split(arg, sSeparator);
Adam Lesinskid0f492d2017-04-03 18:12:45 -070070 if (parts.size() != 2) {
71 diag->Error(DiagMessage() << "invalid split parameter '" << arg << "'");
Adam Lesinskidb091572017-04-13 12:48:56 -070072 diag->Note(DiagMessage() << "should be --split path/to/output.apk" << sSeparator
73 << "<config>[,<config>...].");
Adam Lesinskid0f492d2017-04-03 18:12:45 -070074 return false;
75 }
76
77 *out_path = parts[0];
Todd Kennedy9fbdf892018-08-28 16:31:15 -070078 out_split->name = parts[1];
Adam Lesinskid0f492d2017-04-03 18:12:45 -070079 for (const StringPiece& config_str : util::Tokenize(parts[1], ',')) {
80 ConfigDescription config;
81 if (!ConfigDescription::Parse(config_str, &config)) {
82 diag->Error(DiagMessage() << "invalid config '" << config_str << "' in split parameter '"
83 << arg << "'");
84 return false;
85 }
86 out_split->configs.insert(config);
87 }
88 return true;
89}
90
91std::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args,
92 IDiagnostics* diag) {
93 std::unique_ptr<AxisConfigFilter> filter = util::make_unique<AxisConfigFilter>();
94 for (const std::string& config_arg : args) {
95 for (const StringPiece& config_str : util::Tokenize(config_arg, ',')) {
96 ConfigDescription config;
97 LocaleValue lv;
98 if (lv.InitFromFilterString(config_str)) {
99 lv.WriteTo(&config);
100 } else if (!ConfigDescription::Parse(config_str, &config)) {
101 diag->Error(DiagMessage() << "invalid config '" << config_str << "' for -c option");
102 return {};
103 }
104
105 if (config.density != 0) {
106 diag->Warn(DiagMessage() << "ignoring density '" << config << "' for -c option");
107 } else {
108 filter->AddConfig(config);
109 }
110 }
111 }
112 return std::move(filter);
113}
114
115// Adjust the SplitConstraints so that their SDK version is stripped if it
116// is less than or equal to the minSdk. Otherwise the resources that have had
117// their SDK version stripped due to minSdk won't ever match.
118std::vector<SplitConstraints> AdjustSplitConstraintsForMinSdk(
119 int min_sdk, const std::vector<SplitConstraints>& split_constraints) {
120 std::vector<SplitConstraints> adjusted_constraints;
121 adjusted_constraints.reserve(split_constraints.size());
122 for (const SplitConstraints& constraints : split_constraints) {
123 SplitConstraints constraint;
124 for (const ConfigDescription& config : constraints.configs) {
Todd Kennedy9fbdf892018-08-28 16:31:15 -0700125 const ConfigDescription &configToInsert = (config.sdkVersion <= min_sdk)
126 ? config.CopyWithoutSdkVersion()
127 : config;
128 // only add the config if it actually selects something
129 if (configToInsert != ConfigDescription::DefaultConfig()) {
130 constraint.configs.insert(configToInsert);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700131 }
132 }
Todd Kennedy9fbdf892018-08-28 16:31:15 -0700133 constraint.name = constraints.name;
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700134 adjusted_constraints.push_back(std::move(constraint));
135 }
136 return adjusted_constraints;
137}
138
139static xml::AaptAttribute CreateAttributeWithId(const ResourceId& id) {
Adam Lesinskic744ae82017-05-17 19:28:38 -0700140 return xml::AaptAttribute(Attribute(), id);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700141}
142
Adam Lesinski6b372992017-08-09 10:54:23 -0700143static xml::NamespaceDecl CreateAndroidNamespaceDecl() {
144 xml::NamespaceDecl decl;
145 decl.prefix = "android";
146 decl.uri = xml::kSchemaAndroid;
147 return decl;
148}
149
Donald Chai414e48a2017-11-09 21:06:52 -0800150// Returns a copy of 'name' which conforms to the regex '[a-zA-Z]+[a-zA-Z0-9_]*' by
151// replacing nonconforming characters with underscores.
152//
153// See frameworks/base/core/java/android/content/pm/PackageParser.java which
154// checks this at runtime.
Izabela Orlowska10560192018-04-13 11:56:35 +0100155std::string MakePackageSafeName(const std::string &name) {
Donald Chaib8f078c2017-10-18 23:51:18 -0700156 std::string result(name);
Donald Chai414e48a2017-11-09 21:06:52 -0800157 bool first = true;
Donald Chaib8f078c2017-10-18 23:51:18 -0700158 for (char &c : result) {
Donald Chai414e48a2017-11-09 21:06:52 -0800159 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
160 first = false;
161 continue;
Donald Chaib8f078c2017-10-18 23:51:18 -0700162 }
Donald Chai414e48a2017-11-09 21:06:52 -0800163 if (!first) {
164 if (c >= '0' && c <= '9') {
165 continue;
166 }
167 }
168
169 c = '_';
170 first = false;
Donald Chaib8f078c2017-10-18 23:51:18 -0700171 }
172 return result;
173}
174
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700175std::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info,
176 const SplitConstraints& constraints) {
177 const ResourceId kVersionCode(0x0101021b);
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -0700178 const ResourceId kVersionCodeMajor(0x01010576);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700179 const ResourceId kRevisionCode(0x010104d5);
180 const ResourceId kHasCode(0x0101000c);
181
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700182 std::unique_ptr<xml::Element> manifest_el = util::make_unique<xml::Element>();
Adam Lesinski6b372992017-08-09 10:54:23 -0700183 manifest_el->namespace_decls.push_back(CreateAndroidNamespaceDecl());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700184 manifest_el->name = "manifest";
185 manifest_el->attributes.push_back(xml::Attribute{"", "package", app_info.package});
186
187 if (app_info.version_code) {
188 const uint32_t version_code = app_info.version_code.value();
189 manifest_el->attributes.push_back(xml::Attribute{
190 xml::kSchemaAndroid, "versionCode", std::to_string(version_code),
191 CreateAttributeWithId(kVersionCode),
192 util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_DEC, version_code)});
193 }
194
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -0700195 if (app_info.version_code_major) {
196 const uint32_t version_code_major = app_info.version_code_major.value();
197 manifest_el->attributes.push_back(xml::Attribute{
198 xml::kSchemaAndroid, "versionCodeMajor", std::to_string(version_code_major),
199 CreateAttributeWithId(kVersionCodeMajor),
200 util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_DEC, version_code_major)});
201 }
202
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700203 if (app_info.revision_code) {
204 const uint32_t revision_code = app_info.revision_code.value();
205 manifest_el->attributes.push_back(xml::Attribute{
206 xml::kSchemaAndroid, "revisionCode", std::to_string(revision_code),
207 CreateAttributeWithId(kRevisionCode),
208 util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_DEC, revision_code)});
209 }
210
211 std::stringstream split_name;
212 if (app_info.split_name) {
213 split_name << app_info.split_name.value() << ".";
214 }
Donald Chaib8f078c2017-10-18 23:51:18 -0700215 std::vector<std::string> sanitized_config_names;
216 for (const auto &config : constraints.configs) {
217 sanitized_config_names.push_back(MakePackageSafeName(config.toString().string()));
218 }
219 split_name << "config." << util::Joiner(sanitized_config_names, "_");
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700220
221 manifest_el->attributes.push_back(xml::Attribute{"", "split", split_name.str()});
222
223 if (app_info.split_name) {
224 manifest_el->attributes.push_back(
225 xml::Attribute{"", "configForSplit", app_info.split_name.value()});
226 }
227
Adam Lesinski6b372992017-08-09 10:54:23 -0700228 // Splits may contain more configurations than originally desired (fall-back densities, etc.).
229 // This makes programmatic discovery of split targeting difficult. Encode the original
Adam Lesinski3d632392017-07-24 17:08:32 -0700230 // split constraints intended for this split.
231 std::stringstream target_config_str;
232 target_config_str << util::Joiner(constraints.configs, ",");
233 manifest_el->attributes.push_back(xml::Attribute{"", "targetConfig", target_config_str.str()});
234
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700235 std::unique_ptr<xml::Element> application_el = util::make_unique<xml::Element>();
236 application_el->name = "application";
237 application_el->attributes.push_back(
238 xml::Attribute{xml::kSchemaAndroid, "hasCode", "false", CreateAttributeWithId(kHasCode),
239 util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_BOOLEAN, 0u)});
240
241 manifest_el->AppendChild(std::move(application_el));
Adam Lesinski6b372992017-08-09 10:54:23 -0700242
243 std::unique_ptr<xml::XmlResource> doc = util::make_unique<xml::XmlResource>();
244 doc->root = std::move(manifest_el);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700245 return doc;
246}
247
Adam Lesinski8780eb62017-10-31 17:44:39 -0700248static Maybe<std::string> ExtractCompiledString(const xml::Attribute& attr,
249 std::string* out_error) {
250 if (attr.compiled_value != nullptr) {
251 const String* compiled_str = ValueCast<String>(attr.compiled_value.get());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700252 if (compiled_str != nullptr) {
253 if (!compiled_str->value->empty()) {
254 return *compiled_str->value;
255 } else {
256 *out_error = "compiled value is an empty string";
257 return {};
258 }
259 }
260 *out_error = "compiled value is not a string";
261 return {};
262 }
263
264 // Fallback to the plain text value if there is one.
Adam Lesinski8780eb62017-10-31 17:44:39 -0700265 if (!attr.value.empty()) {
266 return attr.value;
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700267 }
268 *out_error = "value is an empty string";
269 return {};
270}
271
Adam Lesinski8780eb62017-10-31 17:44:39 -0700272static Maybe<uint32_t> ExtractCompiledInt(const xml::Attribute& attr, std::string* out_error) {
273 if (attr.compiled_value != nullptr) {
274 const BinaryPrimitive* compiled_prim = ValueCast<BinaryPrimitive>(attr.compiled_value.get());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700275 if (compiled_prim != nullptr) {
276 if (compiled_prim->value.dataType >= android::Res_value::TYPE_FIRST_INT &&
277 compiled_prim->value.dataType <= android::Res_value::TYPE_LAST_INT) {
278 return compiled_prim->value.data;
279 }
280 }
281 *out_error = "compiled value is not an integer";
282 return {};
283 }
284
285 // Fallback to the plain text value if there is one.
Adam Lesinski8780eb62017-10-31 17:44:39 -0700286 Maybe<uint32_t> integer = ResourceUtils::ParseInt(attr.value);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700287 if (integer) {
288 return integer;
289 }
290 std::stringstream error_msg;
Adam Lesinski8780eb62017-10-31 17:44:39 -0700291 error_msg << "'" << attr.value << "' is not a valid integer";
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700292 *out_error = error_msg.str();
293 return {};
294}
295
Adam Lesinski8780eb62017-10-31 17:44:39 -0700296static Maybe<int> ExtractSdkVersion(const xml::Attribute& attr, std::string* out_error) {
297 if (attr.compiled_value != nullptr) {
298 const BinaryPrimitive* compiled_prim = ValueCast<BinaryPrimitive>(attr.compiled_value.get());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700299 if (compiled_prim != nullptr) {
300 if (compiled_prim->value.dataType >= android::Res_value::TYPE_FIRST_INT &&
301 compiled_prim->value.dataType <= android::Res_value::TYPE_LAST_INT) {
302 return compiled_prim->value.data;
303 }
304 *out_error = "compiled value is not an integer or string";
305 return {};
306 }
307
Adam Lesinski8780eb62017-10-31 17:44:39 -0700308 const String* compiled_str = ValueCast<String>(attr.compiled_value.get());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700309 if (compiled_str != nullptr) {
310 Maybe<int> sdk_version = ResourceUtils::ParseSdkVersion(*compiled_str->value);
311 if (sdk_version) {
312 return sdk_version;
313 }
314
315 *out_error = "compiled string value is not a valid SDK version";
316 return {};
317 }
318 *out_error = "compiled value is not an integer or string";
319 return {};
320 }
321
322 // Fallback to the plain text value if there is one.
Adam Lesinski8780eb62017-10-31 17:44:39 -0700323 Maybe<int> sdk_version = ResourceUtils::ParseSdkVersion(attr.value);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700324 if (sdk_version) {
325 return sdk_version;
326 }
327 std::stringstream error_msg;
Adam Lesinski8780eb62017-10-31 17:44:39 -0700328 error_msg << "'" << attr.value << "' is not a valid SDK version";
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700329 *out_error = error_msg.str();
330 return {};
331}
332
Adam Lesinski8780eb62017-10-31 17:44:39 -0700333Maybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
334 IDiagnostics* diag) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700335 // Make sure the first element is <manifest> with package attribute.
Adam Lesinski8780eb62017-10-31 17:44:39 -0700336 const xml::Element* manifest_el = xml_res.root.get();
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700337 if (manifest_el == nullptr) {
338 return {};
339 }
340
341 AppInfo app_info;
342
343 if (!manifest_el->namespace_uri.empty() || manifest_el->name != "manifest") {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700344 diag->Error(DiagMessage(xml_res.file.source) << "root tag must be <manifest>");
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700345 return {};
346 }
347
Adam Lesinski8780eb62017-10-31 17:44:39 -0700348 const xml::Attribute* package_attr = manifest_el->FindAttribute({}, "package");
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700349 if (!package_attr) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700350 diag->Error(DiagMessage(xml_res.file.source) << "<manifest> must have a 'package' attribute");
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700351 return {};
352 }
353
354 std::string error_msg;
Adam Lesinski8780eb62017-10-31 17:44:39 -0700355 Maybe<std::string> maybe_package = ExtractCompiledString(*package_attr, &error_msg);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700356 if (!maybe_package) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700357 diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700358 << "invalid package name: " << error_msg);
359 return {};
360 }
361 app_info.package = maybe_package.value();
362
Adam Lesinski8780eb62017-10-31 17:44:39 -0700363 if (const xml::Attribute* version_code_attr =
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700364 manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCode")) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700365 Maybe<uint32_t> maybe_code = ExtractCompiledInt(*version_code_attr, &error_msg);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700366 if (!maybe_code) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700367 diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700368 << "invalid android:versionCode: " << error_msg);
369 return {};
370 }
371 app_info.version_code = maybe_code.value();
372 }
373
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -0700374 if (const xml::Attribute* version_code_major_attr =
375 manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor")) {
376 Maybe<uint32_t> maybe_code = ExtractCompiledInt(*version_code_major_attr, &error_msg);
377 if (!maybe_code) {
378 diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
379 << "invalid android:versionCodeMajor: " << error_msg);
380 return {};
381 }
382 app_info.version_code_major = maybe_code.value();
383 }
384
Adam Lesinski8780eb62017-10-31 17:44:39 -0700385 if (const xml::Attribute* revision_code_attr =
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700386 manifest_el->FindAttribute(xml::kSchemaAndroid, "revisionCode")) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700387 Maybe<uint32_t> maybe_code = ExtractCompiledInt(*revision_code_attr, &error_msg);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700388 if (!maybe_code) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700389 diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700390 << "invalid android:revisionCode: " << error_msg);
391 return {};
392 }
393 app_info.revision_code = maybe_code.value();
394 }
395
Adam Lesinski8780eb62017-10-31 17:44:39 -0700396 if (const xml::Attribute* split_name_attr = manifest_el->FindAttribute({}, "split")) {
397 Maybe<std::string> maybe_split_name = ExtractCompiledString(*split_name_attr, &error_msg);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700398 if (!maybe_split_name) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700399 diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700400 << "invalid split name: " << error_msg);
401 return {};
402 }
403 app_info.split_name = maybe_split_name.value();
404 }
405
Adam Lesinski8780eb62017-10-31 17:44:39 -0700406 if (const xml::Element* uses_sdk_el = manifest_el->FindChild({}, "uses-sdk")) {
407 if (const xml::Attribute* min_sdk =
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700408 uses_sdk_el->FindAttribute(xml::kSchemaAndroid, "minSdkVersion")) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700409 Maybe<int> maybe_sdk = ExtractSdkVersion(*min_sdk, &error_msg);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700410 if (!maybe_sdk) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700411 diag->Error(DiagMessage(xml_res.file.source.WithLine(uses_sdk_el->line_number))
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700412 << "invalid android:minSdkVersion: " << error_msg);
413 return {};
414 }
415 app_info.min_sdk_version = maybe_sdk.value();
416 }
417 }
418 return app_info;
419}
420
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -0700421void SetLongVersionCode(xml::Element* manifest, uint64_t version) {
422 // Write the low bits of the version code to android:versionCode
423 auto version_code = manifest->FindOrCreateAttribute(xml::kSchemaAndroid, "versionCode");
424 version_code->value = StringPrintf("0x%08x", (uint32_t) (version & 0xffffffff));
425 version_code->compiled_value = ResourceUtils::TryParseInt(version_code->value);
426
427 auto version_high = (uint32_t) (version >> 32);
428 if (version_high != 0) {
429 // Write the high bits of the version code to android:versionCodeMajor
430 auto version_major = manifest->FindOrCreateAttribute(xml::kSchemaAndroid, "versionCodeMajor");
431 version_major->value = StringPrintf("0x%08x", version_high);
432 version_major->compiled_value = ResourceUtils::TryParseInt(version_major->value);
433 } else {
434 manifest->RemoveAttribute(xml::kSchemaAndroid, "versionCodeMajor");
435 }
436}
437
Izabela Orlowska0faba5f2018-06-01 12:06:31 +0100438std::regex GetRegularExpression(const std::string &input) {
Izabela Orlowska5b89b2d2019-11-27 18:37:09 +0000439 // Standard ECMAScript grammar.
Izabela Orlowska0faba5f2018-06-01 12:06:31 +0100440 std::regex case_insensitive(
Izabela Orlowska5b89b2d2019-11-27 18:37:09 +0000441 input, std::regex_constants::ECMAScript);
Izabela Orlowska0faba5f2018-06-01 12:06:31 +0100442 return case_insensitive;
443}
444
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700445} // namespace aapt