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 | |
| 20 | #include "androidfw/StringPiece.h" |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 21 | #include "format/Archive.h" |
| 22 | #include "process/IResourceTableConsumer.h" |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 23 | #include "Command.h" |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 24 | #include "Diagnostics.h" |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 25 | #include "ResourceTable.h" |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 26 | |
| 27 | namespace aapt { |
| 28 | |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 29 | struct CompileOptions { |
| 30 | std::string output_path; |
| 31 | Maybe<std::string> res_dir; |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 32 | Maybe<std::string> res_zip; |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 33 | Maybe<std::string> generate_text_symbols_path; |
| 34 | Maybe<Visibility::Level> visibility; |
| 35 | bool pseudolocalize = false; |
| 36 | bool no_png_crunch = false; |
| 37 | bool legacy_mode = false; |
| 38 | bool verbose = false; |
| 39 | }; |
| 40 | |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 41 | /** Parses flags and compiles resources to be used in linking. */ |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 42 | class CompileCommand : public Command { |
| 43 | public: |
| 44 | explicit CompileCommand(IDiagnostics* diagnostic) : Command("compile", "c"), |
| 45 | diagnostic_(diagnostic) { |
| 46 | SetDescription("Compiles resources to be linked into an apk."); |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame^] | 47 | AddRequiredFlag("-o", "Output path", &options_.output_path, Command::kPath); |
| 48 | AddOptionalFlag("--dir", "Directory to scan for resources", &options_.res_dir, Command::kPath); |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 49 | AddOptionalFlag("--zip", "Zip file containing the res directory to scan for resources", |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame^] | 50 | &options_.res_zip, Command::kPath); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 51 | AddOptionalFlag("--output-text-symbols", |
| 52 | "Generates a text file containing the resource symbols in the\n" |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame^] | 53 | "specified file", &options_.generate_text_symbols_path, Command::kPath); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 54 | AddOptionalSwitch("--pseudo-localize", "Generate resources for pseudo-locales " |
| 55 | "(en-XA and ar-XB)", &options_.pseudolocalize); |
| 56 | AddOptionalSwitch("--no-crunch", "Disables PNG processing", &options_.no_png_crunch); |
| 57 | AddOptionalSwitch("--legacy", "Treat errors that used to be valid in AAPT as warnings", |
| 58 | &options_.legacy_mode); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 59 | AddOptionalFlag("--visibility", |
| 60 | "Sets the visibility of the compiled resources to the specified\n" |
| 61 | "level. Accepted levels: public, private, default", &visibility_); |
Ryan Mitchell | f3649d6 | 2018-08-02 16:16:45 -0700 | [diff] [blame] | 62 | AddOptionalSwitch("-v", "Enables verbose logging", &options_.verbose); |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | int Action(const std::vector<std::string>& args) override; |
| 66 | |
| 67 | private: |
| 68 | IDiagnostics* diagnostic_; |
| 69 | CompileOptions options_; |
| 70 | Maybe<std::string> visibility_; |
| 71 | }; |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 72 | |
Ryan Mitchell | 2c8fc86 | 2018-12-13 16:56:07 -0800 | [diff] [blame^] | 73 | int Compile(IAaptContext* context, io::IFileCollection* inputs, IArchiveWriter* output_writer, |
| 74 | CompileOptions& options); |
| 75 | |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 76 | }// namespace aapt |
| 77 | |
| 78 | #endif //AAPT2_COMPILE_H |