summaryrefslogtreecommitdiff
path: root/tools/aapt2/cmd/Compile.cpp
AgeCommit message (Collapse)Author
2021-03-29Prepare aapt2 for multiple ids per typeRyan Mitchell
For the SDK finalization changes, aapt2 must be able to handle resources of the same type having different type ids. The ResourceTable data structure currently stores package ids and type ids on ResourceTablePackage and ResourceTableType respectively. This prevents resource entries of the same type from having different type ids without having to create another ResourceTableType structure. JavaClassGenerator assumes each type only appears once in the ResourceTable and it would need to dedupe the types to ensure one class containing all the resource types ids is generated. TableFlattener on the other hand needs a separate ResourceTableType for each type/id combination so that the types are flattened into separate ResTable_types. This change simplifies aapt2's ResourceTable data structure: - Resource ids are stored exclusively on ResourceEntry structures meaning multiple entries can have different type ids while being stored in the same ResourceTableType. Classes like JavaClassGenerator can simply iterate over a type to see all the resources of the type regardless of what their type id is. - ResourceTable::GetPartitionedView() retrieves a list of resources sorted and partitioned by package id, type id, and entry id. Classes like TableFlattener can use this view to get separate ResourceTavleTypes for each different type id that a type has. These changes will also make it easy to have a resource span multiple type ids if it exhausts all of the entry ids in one type id. The new NewResourcesBuilder replaces the numerous setter methods on ResourceTable. Bug: 183102797 Test: aapt2_tests Change-Id: I60dbcb24143bb958333899cafa7d41faa226d203
2020-07-22Add --source-path flag to AAPT2 compilelukeedgar
This added flag uses a given value to replace the default absolute resource file path in the compiled resource file. This allows for relative file paths to be used instead of absolute file paths. Test: Compile_test.cpp Bug: 159611599 Change-Id: I5f1c99cf40e5d31fc54cda819c91640285986d2a
2020-01-07Add option to avoid clobbering visibility of <declare-styleable>Donald Chai
"aapt2 compile" marks styleables as public instead of preserving information from <public/> or --visibility options. This behavior can now be disabled via --preserve-visibility-of-styleables. Bug: 146649511 Change-Id: Ifb8ab396573d1393df737a59625e79e9cf2494a7 Tested: aapt2_tests
2019-08-28Allow compile output to be either a zip or dirRyan Mitchell
When passing a directory to compile using --zip or --dir, the -o flag had to represent a zip file the compiled contents would be written to. Now, if the path specified by the -o flag is a directory, the compiled files will be written to the directory rather than erroring out. Also when passing files to compile as file arguments, the -o flag had to represent an existing directory. Now, if the path is not an existing directory, the compiled files will create a zip file at the path that contains the compiled files. Test: manual Change-Id: I92a8e124d53cdb653eb3a7ec549f09f9ad0ef04f
2019-06-26Allows features to link to other feature splits without namespacing.Udam Saini
Add uses-split dependencies to AppInfo. At link time, this is used and allows features to reference other features, before resource namespacing is implemented in Android Studio. bug:135681292 Test: Link_test, ReferenceLinker_test, and integration tests. Change-Id: Ifdf0067e7370552b6b9d4d6d4713d4484b6ea154
2019-03-29Fix aapt2 pseudo-translating donottranslate* filesMihai Nita
Bug: 126423638 Test: After building android doing this in the 'out' folder: Test: Test: ./soong/host/linux-x86/bin/aapt d --values resources \ Test: ./target/product/sailfish/system/product/priv-app/SystemUIGoogle/SystemUIGoogle.apk \ Test: | less Test: Test: search for `system_ui_aod_date_pattern` in the output, found this: Test: (string8) "[éééḾḾḾð one two]" Test: (string8) "<U+200F><U+202E>eeeMMMd<U+202C><U+200F>" Test: (the en-XA and ar-XB pseudo-translated versions of the string) Test: Test: After the fix and rebuild the dump only finds the original English string ("eeeMMMd") Test: Also flashed the image, switched to en-XA, and left the phone around for more than 24 hours. Change-Id: I2fb7c5b5ee7d3d3200410593346682ed16559056
2019-03-11Compile all files in res/xml as xmlRyan Mitchell
AAPT(1) compiled all files in res/xml as xml. Continue to do the same to prevent regressions. Bug: 122321161 Test: manual Change-Id: I99c80da6d304c13ce911cd5258fd561f3c9e91b4
2019-03-05Add --trace_folder to aapt2Fabien Sanglard
Add a tracing API and instrument key functions in order to profile aapt2 bottleneck. The API allows to generate systrace fragment files. Impact on performance is neglibible with each Trace requiring less than 1us and the final Flush operation at the end of a command requiring around 40us. Bug: None Test: None Change-Id: I51b564d3694e9384679f43b878b32295527dddf6
2019-02-26Sort inputs to compile and linkRyan Mitchell
This change sorts the input files of compile and link and also traverses directories in sorted order in FileCollection::Create. This change attempts to fix non-determinism issues with aapt2. Bug: 122518436 Test: builds Change-Id: I615b8d7f1117e3850366760f16672f0cf5b02070
2019-01-22Optimize aapt2 compile for pngsRyan Mitchell
Do not copy the png data when compiling pngs. Bug: 122950060 Test: aapt2 compile -o . BaseAppPhoto1_copy.png Change-Id: I78fbdaa9a40ada406d7b07cf072d6cd76124168e
2019-01-17AAPT2: always say which file failed to compileIzabela Orlowska
Sometimes AAPT2 doesn't include the path of the file in the error message, or just outputs a warning where an error should be printed (but the overall build still fails without an error message). Let's always include the file path to make it easier for the users to find out the source of the failure. Fixes: 122856772 Test: manual Change-Id: Ibbbfd21b372792e5eaa40278186eb64cdfb0f60e
2019-01-04Merge "Fix/suppress aapt/aapt2 google-explicit-constructor warnings" am: ↵Chih-Hung Hsieh
cdf6be573f am: d42fe48c93 am: 0bf62f1309 Change-Id: Iffb7e4a145b172a35dd58b9450d4a5184d8b07f7
2019-01-04Fix/suppress aapt/aapt2 google-explicit-constructor warningsChih-Hung Hsieh
* Add explicit to conversion constructors/operators * Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters Bug: 28341362 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor Change-Id: Ie02101ea7c422e8add535c111a30a2f21ead0ace
2018-12-17Merge "Fix performance-for-range-copy warnings" am: bc29242288 am: 7adb73f332Chih-Hung Hsieh
am: 2296036a40 Change-Id: Ia99ea6c9633986e68340bc88983d06baa7a1c597
2018-12-17Fix performance-for-range-copy warningsChih-Hung Hsieh
Bug: 30413223 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance* Change-Id: Ie481e88025a7a1f3abde8ff63420d5ccd8577e52
2018-10-08libandroidfw: move ConfigDescription from aapt2 to libandroidfwMårten Kongstad
This is to allow idmap2 to access ConfigDescription. Test: libandroidfw_tests Test: aapt2_tests Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5 Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08libandroidfw: move ConfigDescription from aapt2 to libandroidfwMårten Kongstad
This is to allow idmap2 to access ConfigDescription. Test: libandroidfw_tests Test: aapt2_tests Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-03Fix failing Windows testsRyan Mitchell
Some tests were not written to run on Windows correctly. Compile also has a bug that caused using the --zip flag to fail on Windows. iswspace does count the non breaking space as Whiespace on Windows but not on Unix based systems Bug: 117156986 Change-Id: I999375162bdfdf86fb25992ee88e2962ab90b577 Test: aapt2_tests and wine aapt2_tests.exe
2018-08-14AAPT2: Compile --zip flagRyan Mitchell
Added a --zip flag similar to --dir that allows resources to be passed into "aapt2 compile" using a zip file. Also refactored Compile.cpp to be easier to mock and test in the future. Bug: 74574557 Test: aapt2_tests Change-Id: Idb90cb97e23a219525bdead38220cbf7bc6f3cab
2018-08-13Merge "AAPT2: partial files contain only local resources"TreeHugger Robot
2018-07-25AAPT2: partial files contain only local resourcesIzabela Orlowska
When writing a partial R file for the compiled file, only include resources defined locally - meaning those without a package. Do not write resources from other packages (e.g. "android"). Test: manual Bug: 73927419 Change-Id: I84241352e643ca1f22a581e6847372e2a4278824
2018-07-23Revert "AAPT2: Automatic Static Library Namespacing."Chris Warrington
This reverts commit 481f027ddc3e0ff0e1838a9375c1286e8ad70d70. Reason for revert: Not needed any more Bug: 111543815 Test: existing unit and integration tests Change-Id: I87b039192682636d81c2d33512495cb005c9504d
2018-07-13AAPT2: Refactor flags into commandsRyan Mitchell
Refactors the flag based command invocation into classes that make using subcommands easier. Test: manual tests of printing Change-Id: Ic8df6af0be30db552e32150afebecbfeec7e1075
2018-04-18AAPT2: include package name in styleable childrenIzabela Orlowska
When writing partial R files, also include the package of the styleable child: <declare-styleable name="ds1"> <attr name="font"/> <attr name="android:font"/> <attr name="tools:font"/> <attr name="com.foo.bar:font"/> </declare-styleable> will produce: default int styleable ds1_font default int styleable ds1_android_font default int styleable ds1_tools_font default int styleable ds1_com_foo_bar_font Bug: 73927419 Test: manual, see description Change-Id: Ica493408c7c6d9e7fae2b693c96fbc20a723ce08
2018-04-12Merge "AAPT: Multiple period legacy support and errors" into pi-dev am: ↵Ryan Mitchell
f845891031 am: 68dc7ca568 Change-Id: I9da94ea0e84ff3caf28597b1038ed6e4ac158280
2018-04-11AAPT: Multiple period legacy support and errorsy
AAPT would accept files with multiple periods in the filename as input. This lead to cases explained in b/74999475. This change adds error messages for files with multiple periods unless the legacy flag is present. With the legacy flag present, AAPT2 will behave like AAPT rather than throwing an error. Test: Added tests to aapt2_tests Bug: 73071563 Bug: 74999475 Change-Id: I28dfceeea7b39f8e4b9e6671e0fc8793cf388f52
2018-04-04Check the size of the strings in the StringPool before flattening.Ryan Mitchell
Test: Tested for normal functionality when string does not exceed maximum length and tests for detection of string that is too lonhg for UTF8i Bug: b/74176037 Change-Id: Ic71d3671a069e7012e8ca107e79e071499eebbf6 (cherry picked from commit a15c2a8957b9883cb293fdacaeabd7f2e037a0a5)
2018-03-30Merge "Check the size of the strings in the StringPool before flattening."TreeHugger Robot
2018-03-29Check the size of the strings in the StringPool before flattening.Ryan Mitchell
Test: Tested for normal functionality when string does not exceed maximum length and tests for detection of string that is too lonhg for UTF8i Bug: b/74176037 Change-Id: Ic71d3671a069e7012e8ca107e79e071499eebbf6
2018-03-27AAPT2: add flag for forcing visibility levelIzabela Orlowska
Test: manual Bug: 72735798 Change-Id: I29480e66384dd2da27e17ab454ac1fe8a033ee3e
2018-03-14AAPT2: Automatic Static Library Namespacing.Chris Warrington
Introduces a link flag --auto-namespace-static-lib for use when linking static libraries. When linking a static library with compiled sources that have references to resources in provided libraries without an explicit package name, the flag enables automatic inference of the package. If a resource is present in the package that is being compiled, that is used, otherwise the reference is rewritten to the highest precedence resource with matching name and type. Test: m out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests && \ $ANDROID_HOST_OUT/nativetest64/aapt2_tests/aapt2_tests Test: m frameworks/base/tools/aapt2/integration-tests Change-Id: I6c6017e054654d1f60782d0a428a7a2a47f8952b
2018-01-12AAPT2: always compile 9patch filesIzabela Orlowska
Test: existing tests Bug: 70578281 Change-Id: I7ffcbdd664108348182e71d01b1680e2399ec37c
2017-12-28AAPT2: Keep file enumeration consistent across platformsAdam Lesinski
Filesystem directory enumeration is platform dependent, so sort the files lexicographically according to source path before consuming them in the compile command. Bug: 70680618 Test: manual Change-Id: I6706dea2eb40cbaff8a586994dd1013976e4ced4
2017-12-20AAPT2: Add flag to compile command for outputting symbolsIzabela Orlowska
Only XML files can define resources inside of them, so the fragment R.txt will only be created for XML files. The fragment R.txt will contain files defined inside the XML files and the file itself. For example for res/layout/my_layout.xml that defines "@+id/myView" the fragment R.txt will contain "default int id myView" and "default int layout my_layout". Resources defined with the "public" keyword will have the word "public" in the partial R.txt, resources defined with the "java-symbol" keyword will have the word "private, and all other resources will have the word "default". If a string is declared in values/strings.xml as: '<string name="foo">text</string>' then the partial R.txt will contain "default int string foo". If the same string is also marked as public in the values/public.xml as: '<public type="string" name="foo" id="0x7f000001"/> then the partial R.txt for that file will cointain: "public int string foo". Also, the resource IDs will be skipped as this is only for compilation, proper IDs will be generated at linking phase. Test: manual Change-Id: I37d07d5ee4a9f2e5a60a54e48579eba86ae7dd60
2017-11-03AAPT2: Fix GetFileType for unicode and long paths on WindowsAdam Lesinski
Bug: 68262818 Test: manual Change-Id: I4f02e544e45865984ff4e021a7d1e83f8baf24c3
2017-10-19AAPT2: Define and Implement AAPT Container FormatAdam Lesinski
AAPT Container Format (.apc) is a simple container that enumerates the various intermediate files that AAPT2 generates during the compile phase. The format is defined in formats.md. For now, continue using the .flat extension for the container file, and keep making use of the .flata zip for storing multiple files. This will allow easier integration with existing build systems and allow the evolution of the APC format to better handle arbitrarily large files. Test: make aapt2_tests Change-Id: Id7216e5b76316bdd683f0fa4eaf2d2da273ba815
2017-10-04AAPT2: Move format related files under same directoryAdam Lesinski
Test: make aapt2_tests Change-Id: Id72cdfc12ba3add294048e60c55f2461344464bf
2017-09-28AAPT2: Cleanup proto classes/methods and add XML serializationAdam Lesinski
Test: make aapt2_tests Change-Id: I01ac2285af6771a683533c033a59ae6cfe875d93
2017-08-23AAPT2: Define intermediate compiled XML protoAdam Lesinski
This proto format is meant to encapsulate more information that is specific to Android and allows for easier validation and manipulation across tools. Test: make aapt2_tests Change-Id: I13bc34a460671fc0a36246be0d287a3d37d244d6
2017-08-03AAPT2: Fix windows unicode path issuesAdam Lesinski
Mingw64 was being difficult, so instead of defining a wmain entrypoint, the command line parameters are parsed manually using built-in Windows methods that support Unicode. The results are converted to UTF8 and handled just like the rest of the linux/mac version of the code. This also removes dependencies on std::istream in favour of a FileInputStream which calls the appropriate unicode version of open to read a file. No speed regressions found on Linux or MacOS. Bug: 62336414 Bug: 63830502 Test: manual Change-Id: I597da51e33729ed1b98bf246e7e773337fd3fee8
2017-05-30Merge "AAPT2: Follow symlinks when compiling" into oc-dev am: 6ea61f9c6dAdam Lesinski
am: c69611fd86 Change-Id: Idd8ebb98c04fcfd061c36c2e5dcd678d88c5a267
2017-05-26AAPT2: Follow symlinks when compilingAdam Lesinski
Bug: 62144459 Test: make AaptSymlinkTest Change-Id: Idb3ab1ece17c52bb4fd174ec4c08a9e173289e55
2017-05-23AAPT2: improve some error messagesAdam Lesinski
Test: manual Change-Id: I11c96f8c825ffd43b7f68cb24f2c0746d75845f5
2017-05-15AAPT2: Ignore trailing data after IEND chunk in PNGAdam Lesinski
libpng seems to do the same, so our chunk filter should not care what comes after. Bug: 38169876 Test: manual Change-Id: I020ddfe29ac3eb4d5ef9ace5611c6f6497de443d
2017-05-10AAPT2: Add option to disable PNG crunchingAdam Lesinski
When compiling, a developer may want to disable PNG crunching for a specific set of PNGs. Bug: 37729284 Test: manual Change-Id: I134f208f8bb212df07a4eef65b467985a6443375
2017-04-28AAPT2: Error reporting through JNI.Chris Warrington
Rather than relying on stderr being wired correctly. Test: Tests for JNI integration in studio-master-dev. Change-Id: I1c7e7130bc4e56d61de259a9596bee3a6b3520fb
2017-04-25Merge "AAPT2: Add better error message when processing invalid files" into ↵TreeHugger Robot
oc-dev
2017-04-24AAPT2: Add better error message when processing invalid filesAdam Lesinski
Instead of showing a failed mmap error, show a better error when a file being compiled is a directory or other unsupported file type. Bug: 37626838 Test: manual Change-Id: Ib9acf5f48ab5da37e79411c6a9f37c51f00f925f
2017-04-21AAPT2: Allow truncating of package namesAdam Lesinski
ResTable_package header only allows 127 UTF-16 characters, so AAPT would truncate the real package name to fit. AAPT2 would error-out on any package name longer than 127 UTF-16 characters. This strictness is not required except when building shared libraries, which use the full package name as a way of identifying the runtime assigned package ID to package name mapping. Bug: 36940145 Test: make aapt2_tests Change-Id: I7d2b7e50c7ab30c6a6c4f15d310e711f68e35091
2017-04-10AAPT2: Share split functionality between link and optimizeAdam Lesinski
Generating splits should be possible to do from the optimize command. This means that a lot of infrastructure around split APKs can be shared by both the optimize and link phase. Bug: 35925830 Change-Id: Ia88b9e4bff300a56353b2f7a4a2547c8eb43a299 Test: manual