Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85229422 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "Fix up the command line, add flags."

parents 03b3dccf 5886a92e
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -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) {
+2 −1
Original line number Diff line number Diff line
@@ -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);

+24 −7
Original line number Diff line number Diff line
@@ -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, {});

    XmlFlattener::Options xmlOptions;
    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.
    XmlFlattener::Options xmlOptions;
        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.
    if (options.versionStylesAndLayouts) {
        versionStylesForCompat(table);
    }

    // Open the output APK file for writing.
    ZipFile outApk;