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

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

Merge "AAPT2"

parents d945e6b4 6f6ceb7e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1333,7 +1333,11 @@ struct ResTable_entry
        FLAG_COMPLEX = 0x0001,
        // If set, this resource has been declared public, so libraries
        // are allowed to reference it.
        FLAG_PUBLIC = 0x0002
        FLAG_PUBLIC = 0x0002,
        // If set, this is a weak resource and may be overriden by strong
        // resources of the same name/type. This is only useful during
        // linking with other resource tables.
        FLAG_WEAK = 0x0004
    };
    uint16_t flags;
    

tools/aapt2/Android.mk

0 → 100644
+133 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This tool is prebuilt if we're doing an app-only build.
ifeq ($(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)),)

# ==========================================================
# Setup some common variables for the different build
# targets here.
# ==========================================================
LOCAL_PATH:= $(call my-dir)

main := Main.cpp
sources := \
	BigBuffer.cpp \
	BinaryResourceParser.cpp \
	ConfigDescription.cpp \
	Files.cpp \
	JavaClassGenerator.cpp \
	Linker.cpp \
	Locale.cpp \
	Logger.cpp \
	ManifestParser.cpp \
	ManifestValidator.cpp \
	ResChunkPullParser.cpp \
	Resolver.cpp \
	Resource.cpp \
	ResourceParser.cpp \
	ResourceTable.cpp \
	ResourceValues.cpp \
	SdkConstants.cpp \
	StringPool.cpp \
	TableFlattener.cpp \
	Util.cpp \
	ScopedXmlPullParser.cpp \
	SourceXmlPullParser.cpp \
	XliffXmlPullParser.cpp \
	XmlFlattener.cpp

testSources := \
	BigBuffer_test.cpp \
	Compat_test.cpp \
	ConfigDescription_test.cpp \
	JavaClassGenerator_test.cpp \
	Linker_test.cpp \
	Locale_test.cpp \
	ManifestParser_test.cpp \
	Maybe_test.cpp \
	ResourceParser_test.cpp \
	Resource_test.cpp \
	ResourceTable_test.cpp \
	ScopedXmlPullParser_test.cpp \
	StringPiece_test.cpp \
	StringPool_test.cpp \
	Util_test.cpp \
	XliffXmlPullParser_test.cpp \
	XmlFlattener_test.cpp

cIncludes :=

hostLdLibs := -lz
hostStaticLibs := \
	libandroidfw \
	libutils \
	liblog \
	libcutils \
	libexpat \
	libziparchive-host

cFlags := -Wall -Werror -Wno-unused-parameter -UNDEBUG
cppFlags := -std=c++11 -Wno-missing-field-initializers

# ==========================================================
# Build the host static library: libaapt2
# ==========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libaapt2

LOCAL_SRC_FILES := $(sources)
LOCAL_C_INCLUDES += $(cIncludes)
LOCAL_CFLAGS += $(cFlags)
LOCAL_CPPFLAGS += $(cppFlags)

include $(BUILD_HOST_STATIC_LIBRARY)


# ==========================================================
# Build the host tests: libaapt2_tests
# ==========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libaapt2_tests
LOCAL_MODULE_TAGS := tests

LOCAL_SRC_FILES := $(testSources)

LOCAL_C_INCLUDES += $(cIncludes)
LOCAL_STATIC_LIBRARIES += libaapt2 $(hostStaticLibs)
LOCAL_LDLIBS += $(hostLdLibs)
LOCAL_CFLAGS += $(cFlags)
LOCAL_CPPFLAGS += $(cppFlags)

include $(BUILD_HOST_NATIVE_TEST)

# ==========================================================
# Build the host executable: aapt2
# ==========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := aapt2

LOCAL_SRC_FILES := $(main)

LOCAL_C_INCLUDES += $(cIncludes)
LOCAL_STATIC_LIBRARIES += libaapt2 $(hostStaticLibs)
LOCAL_LDLIBS += $(hostLdLibs)
LOCAL_CFLAGS += $(cFlags)
LOCAL_CPPFLAGS += $(cppFlags)

include $(BUILD_HOST_EXECUTABLE)

endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK

tools/aapt2/AppInfo.h

0 → 100644
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AAPT_APP_INFO_H
#define AAPT_APP_INFO_H

#include <string>

namespace aapt {

/**
 * Holds basic information about the app being built. Most of this information
 * will come from the app's AndroidManifest.
 */
struct AppInfo {
    /**
     * App's package name.
     */
    std::u16string package;
};

} // namespace aapt

#endif // AAPT_APP_INFO_H
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "BigBuffer.h"

#include <algorithm>
#include <memory>
#include <vector>

namespace aapt {

void* BigBuffer::nextBlockImpl(size_t size) {
    if (!mBlocks.empty()) {
        Block& block = mBlocks.back();
        if (block.mBlockSize - block.size >= size) {
            void* outBuffer = block.buffer.get() + block.size;
            block.size += size;
            mSize += size;
            return outBuffer;
        }
    }

    const size_t actualSize = std::max(mBlockSize, size);

    Block block = {};

    // Zero-allocate the block's buffer.
    block.buffer = std::unique_ptr<uint8_t[]>(new uint8_t[actualSize]());
    assert(block.buffer);

    block.size = size;
    block.mBlockSize = actualSize;

    mBlocks.push_back(std::move(block));
    mSize += size;
    return mBlocks.back().buffer.get();
}

} // namespace aapt
+158 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AAPT_BIG_BUFFER_H
#define AAPT_BIG_BUFFER_H

#include <cstring>
#include <memory>
#include <vector>

namespace aapt {

/**
 * Inspired by protobuf's ZeroCopyOutputStream, offers blocks of memory
 * in which to write without knowing the full size of the entire payload.
 * This is essentially a list of memory blocks. As one fills up, another
 * block is allocated and appended to the end of the list.
 */
class BigBuffer {
public:
    /**
     * A contiguous block of allocated memory.
     */
    struct Block {
        /**
         * Pointer to the memory.
         */
        std::unique_ptr<uint8_t[]> buffer;

        /**
         * Size of memory that is currently occupied. The actual
         * allocation may be larger.
         */
        size_t size;

    private:
        friend class BigBuffer;

        /**
         * The size of the memory block allocation.
         */
        size_t mBlockSize;
    };

    typedef std::vector<Block>::const_iterator const_iterator;

    /**
     * Create a BigBuffer with block allocation sizes
     * of blockSize.
     */
    BigBuffer(size_t blockSize);

    BigBuffer(const BigBuffer&) = delete; // No copying.

    BigBuffer(BigBuffer&& rhs);

    /**
     * Number of occupied bytes in all the allocated blocks.
     */
    size_t size() const;

    /**
     * Returns a pointer to an array of T, where T is
     * a POD type. The elements are zero-initialized.
     */
    template <typename T>
    T* nextBlock(size_t count = 1);

    /**
     * Moves the specified BigBuffer into this one. When this method
     * returns, buffer is empty.
     */
    void appendBuffer(BigBuffer&& buffer);

    /**
     * Pads the block with 'bytes' bytes of zero values.
     */
    void pad(size_t bytes);

    /**
     * Pads the block so that it aligns on a 4 byte boundary.
     */
    void align4();

    const_iterator begin() const;
    const_iterator end() const;

private:
    /**
     * Returns a pointer to a buffer of the requested size.
     * The buffer is zero-initialized.
     */
    void* nextBlockImpl(size_t size);

    size_t mBlockSize;
    size_t mSize;
    std::vector<Block> mBlocks;
};

inline BigBuffer::BigBuffer(size_t blockSize) : mBlockSize(blockSize), mSize(0) {
}

inline BigBuffer::BigBuffer(BigBuffer&& rhs) :
        mBlockSize(rhs.mBlockSize), mSize(rhs.mSize), mBlocks(std::move(rhs.mBlocks)) {
}

inline size_t BigBuffer::size() const {
    return mSize;
}

template <typename T>
inline T* BigBuffer::nextBlock(size_t count) {
    assert(count != 0);
    return reinterpret_cast<T*>(nextBlockImpl(sizeof(T) * count));
}

inline void BigBuffer::appendBuffer(BigBuffer&& buffer) {
    std::move(buffer.mBlocks.begin(), buffer.mBlocks.end(), std::back_inserter(mBlocks));
    mSize += buffer.mSize;
    buffer.mBlocks.clear();
    buffer.mSize = 0;
}

inline void BigBuffer::pad(size_t bytes) {
    nextBlock<char>(bytes);
}

inline void BigBuffer::align4() {
    const size_t unaligned = mSize % 4;
    if (unaligned != 0) {
        pad(4 - unaligned);
    }
}

inline BigBuffer::const_iterator BigBuffer::begin() const {
    return mBlocks.begin();
}

inline BigBuffer::const_iterator BigBuffer::end() const {
    return mBlocks.end();
}

} // namespace aapt

#endif // AAPT_BIG_BUFFER_H
Loading