Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 17 | #ifndef AAPT2_COMPILE_H |
| 18 | #define AAPT2_COMPILE_H |
| 19 | |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 20 | #include <androidfw/StringPiece.h> |
| 21 | |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 22 | #include <optional> |
| 23 | |
| 24 | #include "Command.h" |
| 25 | #include "ResourceTable.h" |
| 26 | #include "androidfw/IDiagnostics.h" |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 27 | #include "format/Archive.h" |
| 28 | #include "process/IResourceTableConsumer.h" |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 29 | |
| 30 | namespace aapt { |
| 31 | |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 32 | struct CompileOptions { |
| 33 | std::string output_path; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 34 | std::optional<std::string> source_path; |
| 35 | std::optional<std::string> res_dir; |
| 36 | std::optional<std::string> res_zip; |
| 37 | std::optional<std::string> generate_text_symbols_path; |
Brandon Liu | 5274e06 | 2023-05-25 22:41:10 +0000 | [diff] [blame] | 38 | std::optional<std::string> pseudo_localize_gender_values; |
| 39 | std::optional<std::string> pseudo_localize_gender_ratio; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 40 | std::optional<Visibility::Level> visibility; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 41 | bool pseudolocalize = false; |
| 42 | bool no_png_crunch = false; |
| 43 | bool legacy_mode = false; |
Donald Chai | 94e4a01 | 2020-01-06 13:52:41 -0800 | [diff] [blame] | 44 | // See comments on aapt::ResourceParserOptions. |
| 45 | bool preserve_visibility_of_styleables = false; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 46 | bool verbose = false; |
Inseob Kim | 5fe521e | 2023-09-15 16:38:50 +0900 | [diff] [blame] | 47 | std::optional<std::string> product_; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 50 | /** Parses flags and compiles resources to be used in linking. */ |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 51 | class CompileCommand : public Command { |
| 52 | public: |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 53 | explicit CompileCommand(android::IDiagnostics* diagnostic) |
| 54 | : Command("compile", "c"), diagnostic_(diagnostic) { |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 55 | SetDescription("Compiles resources to be linked into an apk."); |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame] | 56 | AddRequiredFlag("-o", "Output path", &options_.output_path, Command::kPath); |
| 57 | AddOptionalFlag("--dir", "Directory to scan for resources", &options_.res_dir, Command::kPath); |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 58 | AddOptionalFlag("--zip", "Zip file containing the res directory to scan for resources", |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame] | 59 | &options_.res_zip, Command::kPath); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 60 | AddOptionalFlag("--output-text-symbols", |
| 61 | "Generates a text file containing the resource symbols in the\n" |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame] | 62 | "specified file", &options_.generate_text_symbols_path, Command::kPath); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 63 | AddOptionalSwitch("--pseudo-localize", "Generate resources for pseudo-locales " |
| 64 | "(en-XA and ar-XB)", &options_.pseudolocalize); |
| 65 | AddOptionalSwitch("--no-crunch", "Disables PNG processing", &options_.no_png_crunch); |
| 66 | AddOptionalSwitch("--legacy", "Treat errors that used to be valid in AAPT as warnings", |
| 67 | &options_.legacy_mode); |
Donald Chai | 94e4a01 | 2020-01-06 13:52:41 -0800 | [diff] [blame] | 68 | AddOptionalSwitch("--preserve-visibility-of-styleables", |
| 69 | "If specified, apply the same visibility rules for\n" |
| 70 | "styleables as are used for all other resources.\n" |
| 71 | "Otherwise, all stylesables will be made public.", |
| 72 | &options_.preserve_visibility_of_styleables); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 73 | AddOptionalFlag("--visibility", |
| 74 | "Sets the visibility of the compiled resources to the specified\n" |
| 75 | "level. Accepted levels: public, private, default", &visibility_); |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 76 | AddOptionalSwitch("-v", "Enables verbose logging", &options_.verbose); |
Fabien Sanglard | 2d34e76 | 2019-02-21 15:13:29 -0800 | [diff] [blame] | 77 | AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.", |
| 78 | &trace_folder_); |
lukeedgar | 19b8ebf | 2020-06-23 10:43:42 +0100 | [diff] [blame] | 79 | AddOptionalFlag("--source-path", |
| 80 | "Sets the compiled resource file source file path to the given string.", |
| 81 | &options_.source_path); |
Brandon Liu | 5274e06 | 2023-05-25 22:41:10 +0000 | [diff] [blame] | 82 | AddOptionalFlag("--pseudo-localize-gender-values", |
| 83 | "Sets the gender values to pick up for generating grammatical gender strings, " |
| 84 | "gender values should be f, m, or n, which are shortcuts for feminine, " |
| 85 | "masculine and neuter, and split with comma.", |
| 86 | &options_.pseudo_localize_gender_values); |
| 87 | AddOptionalFlag("--pseudo-localize-gender-ratio", |
| 88 | "Sets the ratio of resources to generate grammatical gender strings for. The " |
| 89 | "ratio has to be a float number between 0 and 1.", |
| 90 | &options_.pseudo_localize_gender_ratio); |
Inseob Kim | 5fe521e | 2023-09-15 16:38:50 +0900 | [diff] [blame] | 91 | AddOptionalFlag("--filter-product", |
| 92 | "Leave only resources specific to the given product. All " |
| 93 | "other resources (including defaults) are removed.", |
| 94 | &options_.product_); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | int Action(const std::vector<std::string>& args) override; |
| 98 | |
| 99 | private: |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 100 | android::IDiagnostics* diagnostic_; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 101 | CompileOptions options_; |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 102 | std::optional<std::string> visibility_; |
| 103 | std::optional<std::string> trace_folder_; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 104 | }; |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 105 | |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame] | 106 | int Compile(IAaptContext* context, io::IFileCollection* inputs, IArchiveWriter* output_writer, |
| 107 | CompileOptions& options); |
| 108 | |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 109 | }// namespace aapt |
| 110 | |
| 111 | #endif //AAPT2_COMPILE_H |