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

Commit 36c73a59 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

AAPT2: Expose split support to command line

Bug:30445078
Change-Id: If4b8530dba71b9059b8e62c04757da99c1119d22
parent 534376f3
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,16 @@ struct AppInfo {
     * The App's minimum SDK version.
     */
    Maybe<std::string> minSdkVersion;

    /**
     * The Version code of the app.
     */
    Maybe<uint32_t> versionCode;

    /**
     * The revision code of the app.
     */
    Maybe<uint32_t> revisionCode;
};

} // namespace aapt
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ namespace aapt {
static const char* sMajorVersion = "2";

// Update minor version whenever a feature or flag is added.
static const char* sMinorVersion = "0";
static const char* sMinorVersion = "1";

int printVersion() {
    std::cerr << "Android Asset Packaging Tool (aapt) "
+14 −7
Original line number Diff line number Diff line
@@ -500,8 +500,8 @@ std::unique_ptr<Item> ResourceParser::parseXml(xml::XmlPullParser* parser, const
    };

    // Process the raw value.
    std::unique_ptr<Item> processedItem = ResourceUtils::parseItemForAttribute(rawValue, typeMask,
                                                                               onCreateReference);
    std::unique_ptr<Item> processedItem = ResourceUtils::tryParseItemForAttribute(
            rawValue, typeMask, onCreateReference);
    if (processedItem) {
        // Fix up the reference.
        if (Reference* ref = valueCast<Reference>(processedItem.get())) {
@@ -528,20 +528,24 @@ std::unique_ptr<Item> ResourceParser::parseXml(xml::XmlPullParser* parser, const
bool ResourceParser::parseString(xml::XmlPullParser* parser, ParsedResource* outResource) {
    bool formatted = true;
    if (Maybe<StringPiece> formattedAttr = xml::findAttribute(parser, "formatted")) {
        if (!ResourceUtils::tryParseBool(formattedAttr.value(), &formatted)) {
        Maybe<bool> maybeFormatted = ResourceUtils::parseBool(formattedAttr.value());
        if (!maybeFormatted) {
            mDiag->error(DiagMessage(outResource->source)
                         << "invalid value for 'formatted'. Must be a boolean");
            return false;
        }
        formatted = maybeFormatted.value();
    }

    bool translateable = mOptions.translatable;
    if (Maybe<StringPiece> translateableAttr = xml::findAttribute(parser, "translatable")) {
        if (!ResourceUtils::tryParseBool(translateableAttr.value(), &translateable)) {
        Maybe<bool> maybeTranslateable = ResourceUtils::parseBool(translateableAttr.value());
        if (!maybeTranslateable) {
            mDiag->error(DiagMessage(outResource->source)
                         << "invalid value for 'translatable'. Must be a boolean");
            return false;
        }
        translateable = maybeTranslateable.value();
    }

    outResource->value = parseXml(parser, android::ResTable_map::TYPE_STRING, kNoRawString);
@@ -590,7 +594,7 @@ bool ResourceParser::parsePublic(xml::XmlPullParser* parser, ParsedResource* out
    outResource->name.type = *parsedType;

    if (Maybe<StringPiece> maybeIdStr = xml::findNonEmptyAttribute(parser, "id")) {
        Maybe<ResourceId> maybeId = ResourceUtils::tryParseResourceId(maybeIdStr.value());
        Maybe<ResourceId> maybeId = ResourceUtils::parseResourceId(maybeIdStr.value());
        if (!maybeId) {
            mDiag->error(DiagMessage(outResource->source)
                         << "invalid resource ID '" << maybeId.value() << "' in <public>");
@@ -630,7 +634,7 @@ bool ResourceParser::parsePublicGroup(xml::XmlPullParser* parser, ParsedResource
        return false;
    }

    Maybe<ResourceId> maybeId = ResourceUtils::tryParseResourceId(maybeIdStr.value());
    Maybe<ResourceId> maybeId = ResourceUtils::parseResourceId(maybeIdStr.value());
    if (!maybeId) {
        mDiag->error(DiagMessage(outResource->source)
                     << "invalid resource ID '" << maybeIdStr.value() << "' in <public-group>");
@@ -1058,14 +1062,17 @@ bool ResourceParser::parseArrayImpl(xml::XmlPullParser* parser, ParsedResource*

    bool translateable = mOptions.translatable;
    if (Maybe<StringPiece> translateableAttr = xml::findAttribute(parser, "translatable")) {
        if (!ResourceUtils::tryParseBool(translateableAttr.value(), &translateable)) {
        Maybe<bool> maybeTranslateable = ResourceUtils::parseBool(translateableAttr.value());
        if (!maybeTranslateable) {
            mDiag->error(DiagMessage(outResource->source)
                         << "invalid value for 'translatable'. Must be a boolean");
            return false;
        }
        translateable = maybeTranslateable.value();
    }
    array->setTranslateable(translateable);


    bool error = false;
    const size_t depth = parser->getDepth();
    while (xml::XmlPullParser::nextChildNode(parser, depth)) {
+26 −24
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ bool parseResourceName(const StringPiece& str, ResourceNameRef* outRef, bool* ou
    return true;
}

bool tryParseReference(const StringPiece& str, ResourceNameRef* outRef, bool* outCreate,
bool parseReference(const StringPiece& str, ResourceNameRef* outRef, bool* outCreate,
                       bool* outPrivate) {
    StringPiece trimmedStr(util::trimWhitespace(str));
    if (trimmedStr.empty()) {
@@ -171,10 +171,10 @@ bool tryParseReference(const StringPiece& str, ResourceNameRef* outRef, bool* ou
}

bool isReference(const StringPiece& str) {
    return tryParseReference(str, nullptr, nullptr, nullptr);
    return parseReference(str, nullptr, nullptr, nullptr);
}

bool tryParseAttributeReference(const StringPiece& str, ResourceNameRef* outRef) {
bool parseAttributeReference(const StringPiece& str, ResourceNameRef* outRef) {
    StringPiece trimmedStr(util::trimWhitespace(str));
    if (trimmedStr.empty()) {
        return false;
@@ -208,7 +208,7 @@ bool tryParseAttributeReference(const StringPiece& str, ResourceNameRef* outRef)
}

bool isAttributeReference(const StringPiece& str) {
    return tryParseAttributeReference(str, nullptr);
    return parseAttributeReference(str, nullptr);
}

/*
@@ -271,13 +271,13 @@ Maybe<Reference> parseStyleParentReference(const StringPiece& str, std::string*
std::unique_ptr<Reference> tryParseReference(const StringPiece& str, bool* outCreate) {
    ResourceNameRef ref;
    bool privateRef = false;
    if (tryParseReference(str, &ref, outCreate, &privateRef)) {
    if (parseReference(str, &ref, outCreate, &privateRef)) {
        std::unique_ptr<Reference> value = util::make_unique<Reference>(ref);
        value->privateReference = privateRef;
        return value;
    }

    if (tryParseAttributeReference(str, &ref)) {
    if (parseAttributeReference(str, &ref)) {
        if (outCreate) {
            *outCreate = false;
        }
@@ -420,23 +420,26 @@ std::unique_ptr<BinaryPrimitive> tryParseColor(const StringPiece& str) {
    return error ? std::unique_ptr<BinaryPrimitive>() : util::make_unique<BinaryPrimitive>(value);
}

bool tryParseBool(const StringPiece& str, bool* outValue) {
Maybe<bool> parseBool(const StringPiece& str) {
    StringPiece trimmedStr(util::trimWhitespace(str));
    if (trimmedStr == "true" || trimmedStr == "TRUE" || trimmedStr == "True") {
        if (outValue) {
            *outValue = true;
        }
        return true;
        return Maybe<bool>(true);
    } else if (trimmedStr == "false" || trimmedStr == "FALSE" || trimmedStr == "False") {
        if (outValue) {
            *outValue = false;
        return Maybe<bool>(false);
    }
        return true;
    return {};
}
    return false;

Maybe<uint32_t> parseInt(const StringPiece& str) {
    std::u16string str16 = util::utf8ToUtf16(str);
    android::Res_value value;
    if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) {
        return value.data;
    }
    return {};
}

Maybe<ResourceId> tryParseResourceId(const StringPiece& str) {
Maybe<ResourceId> parseResourceId(const StringPiece& str) {
    StringPiece trimmedStr(util::trimWhitespace(str));

    std::u16string str16 = util::utf8ToUtf16(trimmedStr);
@@ -452,7 +455,7 @@ Maybe<ResourceId> tryParseResourceId(const StringPiece& str) {
    return {};
}

Maybe<int> tryParseSdkVersion(const StringPiece& str) {
Maybe<int> parseSdkVersion(const StringPiece& str) {
    StringPiece trimmedStr(util::trimWhitespace(str));

    std::u16string str16 = util::utf8ToUtf16(trimmedStr);
@@ -470,12 +473,11 @@ Maybe<int> tryParseSdkVersion(const StringPiece& str) {
}

std::unique_ptr<BinaryPrimitive> tryParseBool(const StringPiece& str) {
    bool result = false;
    if (tryParseBool(str, &result)) {
    if (Maybe<bool> maybeResult = parseBool(str)) {
        android::Res_value value = {};
        value.dataType = android::Res_value::TYPE_INT_BOOLEAN;

        if (result) {
        if (maybeResult.value()) {
            value.data = 0xffffffffu;
        } else {
            value.data = 0;
@@ -542,7 +544,7 @@ uint32_t androidTypeToAttributeTypeMask(uint16_t type) {
    };
}

std::unique_ptr<Item> parseItemForAttribute(
std::unique_ptr<Item> tryParseItemForAttribute(
        const StringPiece& value,
        uint32_t typeMask,
        std::function<void(const ResourceName&)> onCreateReference) {
@@ -602,11 +604,11 @@ std::unique_ptr<Item> parseItemForAttribute(
 * We successively try to parse the string as a resource type that the Attribute
 * allows.
 */
std::unique_ptr<Item> parseItemForAttribute(
std::unique_ptr<Item> tryParseItemForAttribute(
        const StringPiece& str, const Attribute* attr,
        std::function<void(const ResourceName&)> onCreateReference) {
    const uint32_t typeMask = attr->typeMask;
    std::unique_ptr<Item> value = parseItemForAttribute(str, typeMask, onCreateReference);
    std::unique_ptr<Item> value = tryParseItemForAttribute(str, typeMask, onCreateReference);
    if (value) {
        return value;
    }
+19 −14
Original line number Diff line number Diff line
@@ -28,11 +28,6 @@
namespace aapt {
namespace ResourceUtils {

/**
 * Convert an android::ResTable::resource_name to an aapt::ResourceName struct.
 */
Maybe<ResourceName> toResourceName(const android::ResTable::resource_name& name);

/*
 * Extracts the package, type, and name from a string of the format:
 *
@@ -60,7 +55,7 @@ bool parseResourceName(const StringPiece& str, ResourceNameRef* outResource,
 * If '+' was present in the reference, `outCreate` is set to true.
 * If '*' was present in the reference, `outPrivate` is set to true.
 */
bool tryParseReference(const StringPiece& str, ResourceNameRef* outReference,
bool parseReference(const StringPiece& str, ResourceNameRef* outReference,
                    bool* outCreate = nullptr, bool* outPrivate = nullptr);

/*
@@ -72,7 +67,7 @@ bool isReference(const StringPiece& str);
 * Returns true if the string was parsed as an attribute reference (?[package:][type/]name),
 * with `outReference` set to the parsed reference.
 */
bool tryParseAttributeReference(const StringPiece& str, ResourceNameRef* outReference);
bool parseAttributeReference(const StringPiece& str, ResourceNameRef* outReference);

/**
 * Returns true if the string is in the form of an attribute reference(?[package:][type/]name).
@@ -80,19 +75,29 @@ bool tryParseAttributeReference(const StringPiece& str, ResourceNameRef* outRefe
bool isAttributeReference(const StringPiece& str);

/**
 * Returns true if the value is a boolean, putting the result in `outValue`.
 * Convert an android::ResTable::resource_name to an aapt::ResourceName struct.
 */
Maybe<ResourceName> toResourceName(const android::ResTable::resource_name& name);

/**
 * Returns a boolean value if the string is equal to TRUE, true, True, FALSE, false, or False.
 */
Maybe<bool> parseBool(const StringPiece& str);

/**
 * Returns a uint32_t if the string is an integer.
 */
bool tryParseBool(const StringPiece& str, bool* outValue);
Maybe<uint32_t> parseInt(const StringPiece& str);

/**
 * Returns an ID if it the string represented a valid ID.
 */
Maybe<ResourceId> tryParseResourceId(const StringPiece& str);
Maybe<ResourceId> parseResourceId(const StringPiece& str);

/**
 * Parses an SDK version, which can be an integer, or a letter from A-Z.
 */
Maybe<int> tryParseSdkVersion(const StringPiece& str);
Maybe<int> parseSdkVersion(const StringPiece& str);

/*
 * Returns a Reference, or None Maybe instance if the string `str` was parsed as a
@@ -161,11 +166,11 @@ std::unique_ptr<BinaryPrimitive> tryParseFlagSymbol(const Attribute* enumAttr,
 * The callback function onCreateReference is called when the parsed item is a
 * reference to an ID that must be created (@+id/foo).
 */
std::unique_ptr<Item> parseItemForAttribute(
std::unique_ptr<Item> tryParseItemForAttribute(
        const StringPiece& value, const Attribute* attr,
        std::function<void(const ResourceName&)> onCreateReference = {});

std::unique_ptr<Item> parseItemForAttribute(
std::unique_ptr<Item> tryParseItemForAttribute(
        const StringPiece& value, uint32_t typeMask,
        std::function<void(const ResourceName&)> onCreateReference = {});

Loading