summaryrefslogtreecommitdiffstats
path: root/tools/aapt2
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-04-15 20:29:22 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-04-15 20:29:48 -0700
commit5886a92eb6dde5a406a62926f2914a908ca18d35 (patch)
treee7b70eb90a9bc39dc283b591d88ebe1bc012fbc5 /tools/aapt2
parent769de98f2dd41bfe39a1c9f76aefd1ad58942733 (diff)
downloadframeworks_base-5886a92eb6dde5a406a62926f2914a908ca18d35.zip
frameworks_base-5886a92eb6dde5a406a62926f2914a908ca18d35.tar.gz
frameworks_base-5886a92eb6dde5a406a62926f2914a908ca18d35.tar.bz2
Fix up the command line, add flags.
Change-Id: I420bd0212fc7541668bd095b88295564d3d11f6c
Diffstat (limited to 'tools/aapt2')
-rw-r--r--tools/aapt2/Flag.cpp14
-rw-r--r--tools/aapt2/Flag.h3
-rw-r--r--tools/aapt2/Main.cpp31
3 files changed, 34 insertions, 14 deletions
diff --git a/tools/aapt2/Flag.cpp b/tools/aapt2/Flag.cpp
index a563bfc..3b2ff51 100644
--- a/tools/aapt2/Flag.cpp
+++ b/tools/aapt2/Flag.cpp
@@ -16,6 +16,7 @@ struct Flag {
std::function<void(const StringPiece&)> action;
bool required;
bool* flagResult;
+ bool flagValueWhenSet;
bool parsed;
};
@@ -25,18 +26,19 @@ static std::vector<std::string> sArgs;
void optionalFlag(const StringPiece& name, const StringPiece& description,
std::function<void(const StringPiece&)> action) {
sFlags.push_back(
- Flag{ name.toString(), description.toString(), action, false, nullptr, false });
+ Flag{ name.toString(), description.toString(), action, false, nullptr, false, false });
}
void requiredFlag(const StringPiece& name, const StringPiece& description,
std::function<void(const StringPiece&)> action) {
sFlags.push_back(
- Flag{ name.toString(), description.toString(), action, true, nullptr, false });
+ Flag{ name.toString(), description.toString(), action, true, nullptr, false, false });
}
-void optionalSwitch(const StringPiece& name, const StringPiece& description, bool* result) {
- sFlags.push_back(
- Flag{ name.toString(), description.toString(), {}, false, result, false });
+void optionalSwitch(const StringPiece& name, const StringPiece& description, bool resultWhenSet,
+ bool* result) {
+ sFlags.push_back(Flag{
+ name.toString(), description.toString(), {}, false, result, resultWhenSet, false });
}
void usageAndDie(const StringPiece& command) {
@@ -73,7 +75,7 @@ void parse(int argc, char** argv, const StringPiece& command) {
match = true;
flag.parsed = true;
if (flag.flagResult) {
- *flag.flagResult = true;
+ *flag.flagResult = flag.flagValueWhenSet;
} else {
i++;
if (i >= argc) {
diff --git a/tools/aapt2/Flag.h b/tools/aapt2/Flag.h
index 4cadfc4..4745c35 100644
--- a/tools/aapt2/Flag.h
+++ b/tools/aapt2/Flag.h
@@ -16,7 +16,8 @@ void requiredFlag(const StringPiece& name, const StringPiece& description,
void optionalFlag(const StringPiece& name, const StringPiece& description,
std::function<void(const StringPiece&)> action);
-void optionalSwitch(const StringPiece& name, const StringPiece& description, bool* result);
+void optionalSwitch(const StringPiece& name, const StringPiece& description, bool resultWhenSet,
+ bool* result);
void usageAndDie(const StringPiece& command);
diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp
index b3e2768..03b9ba4 100644
--- a/tools/aapt2/Main.cpp
+++ b/tools/aapt2/Main.cpp
@@ -49,6 +49,8 @@
#include <unordered_set>
#include <utils/Errors.h>
+constexpr const char* kAaptVersionStr = "2.0-alpha";
+
using namespace aapt;
void printTable(const ResourceTable& table) {
@@ -318,8 +320,14 @@ struct AaptOptions {
// Whether to output verbose details about
// compilation.
bool verbose = false;
+
+ // Whether or not to auto-version styles or layouts
+ // referencing attributes defined in a newer SDK
+ // level than the style or layout is defined for.
+ bool versionStylesAndLayouts = true;
};
+
bool compileXml(const AaptOptions& options, const std::shared_ptr<ResourceTable>& table,
const CompileItem& item, std::queue<CompileItem>* outQueue, ZipFile* outApk) {
std::ifstream in(item.source.path, std::ifstream::binary);
@@ -333,10 +341,12 @@ bool compileXml(const AaptOptions& options, const std::shared_ptr<ResourceTable>
// No resolver, since we are not compiling attributes here.
XmlFlattener flattener(table, {});
- // We strip attributes that do not belong in this version of the resource.
- // Non-version qualified resources have an implicit version 1 requirement.
XmlFlattener::Options xmlOptions;
- xmlOptions.maxSdkAttribute = item.config.sdkVersion ? item.config.sdkVersion : 1;
+ if (options.versionStylesAndLayouts) {
+ // We strip attributes that do not belong in this version of the resource.
+ // Non-version qualified resources have an implicit version 1 requirement.
+ xmlOptions.maxSdkAttribute = item.config.sdkVersion ? item.config.sdkVersion : 1;
+ }
std::shared_ptr<BindingXmlPullParser> binding;
std::shared_ptr<XmlPullParser> parser = std::make_shared<SourceXmlPullParser>(in);
@@ -526,7 +536,10 @@ static AaptOptions prepareArgs(int argc, char** argv) {
AaptOptions options;
- if (command == "link") {
+ if (command == "--version" || command == "version") {
+ std::cout << kAaptVersionStr << std::endl;
+ exit(0);
+ } else if (command == "link") {
options.phase = AaptOptions::Phase::Link;
} else if (command == "compile") {
options.phase = AaptOptions::Phase::Compile;
@@ -544,6 +557,8 @@ static AaptOptions prepareArgs(int argc, char** argv) {
[&options](const StringPiece& arg) {
options.bindingOutput = Source{ arg.toString() };
});
+ flag::optionalSwitch("--no-version", "Disables automatic style and layout versioning",
+ false, &options.versionStylesAndLayouts);
} else if (options.phase == AaptOptions::Phase::Link) {
flag::requiredFlag("--manifest", "AndroidManifest.xml of your app",
@@ -568,8 +583,8 @@ static AaptOptions prepareArgs(int argc, char** argv) {
});
bool help = false;
- flag::optionalSwitch("-v", "enables verbose logging", &options.verbose);
- flag::optionalSwitch("-h", "displays this help menu", &help);
+ flag::optionalSwitch("-v", "enables verbose logging", true, &options.verbose);
+ flag::optionalSwitch("-h", "displays this help menu", true, &help);
// Build the command string for output (eg. "aapt2 compile").
std::string fullCommand = "aapt2";
@@ -896,7 +911,9 @@ bool compile(const AaptOptions& options, const std::shared_ptr<ResourceTable>& t
}
// Version all styles referencing attributes outside of their specified SDK version.
- versionStylesForCompat(table);
+ if (options.versionStylesAndLayouts) {
+ versionStylesForCompat(table);
+ }
// Open the output APK file for writing.
ZipFile outApk;