blob: bd2e3d72a551000762dbabe16923dbfb8c920388 [file] [log] [blame]
Ryan Mitchell833a1a62018-07-10 13:51:36 -07001/*
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
yd6b83292018-04-11 09:54:56 -070017#ifndef AAPT2_COMPILE_H
18#define AAPT2_COMPILE_H
19
Ryan Mitchell4382e442021-07-14 12:53:01 -070020#include <optional>
21
22#include <androidfw/StringPiece.h>
23
Ryan Mitchellf3649d62018-08-02 16:16:45 -070024#include "format/Archive.h"
25#include "process/IResourceTableConsumer.h"
Ryan Mitchell833a1a62018-07-10 13:51:36 -070026#include "Command.h"
yd6b83292018-04-11 09:54:56 -070027#include "Diagnostics.h"
Ryan Mitchell833a1a62018-07-10 13:51:36 -070028#include "ResourceTable.h"
yd6b83292018-04-11 09:54:56 -070029
30namespace aapt {
31
Ryan Mitchell833a1a62018-07-10 13:51:36 -070032struct CompileOptions {
33 std::string output_path;
Ryan Mitchell4382e442021-07-14 12:53:01 -070034 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;
38 std::optional<Visibility::Level> visibility;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070039 bool pseudolocalize = false;
40 bool no_png_crunch = false;
41 bool legacy_mode = false;
Donald Chai94e4a012020-01-06 13:52:41 -080042 // See comments on aapt::ResourceParserOptions.
43 bool preserve_visibility_of_styleables = false;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070044 bool verbose = false;
45};
46
Ryan Mitchellf3649d62018-08-02 16:16:45 -070047/** Parses flags and compiles resources to be used in linking. */
Ryan Mitchell833a1a62018-07-10 13:51:36 -070048class CompileCommand : public Command {
49 public:
50 explicit CompileCommand(IDiagnostics* diagnostic) : Command("compile", "c"),
51 diagnostic_(diagnostic) {
52 SetDescription("Compiles resources to be linked into an apk.");
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080053 AddRequiredFlag("-o", "Output path", &options_.output_path, Command::kPath);
54 AddOptionalFlag("--dir", "Directory to scan for resources", &options_.res_dir, Command::kPath);
Ryan Mitchellf3649d62018-08-02 16:16:45 -070055 AddOptionalFlag("--zip", "Zip file containing the res directory to scan for resources",
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080056 &options_.res_zip, Command::kPath);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070057 AddOptionalFlag("--output-text-symbols",
58 "Generates a text file containing the resource symbols in the\n"
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080059 "specified file", &options_.generate_text_symbols_path, Command::kPath);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070060 AddOptionalSwitch("--pseudo-localize", "Generate resources for pseudo-locales "
61 "(en-XA and ar-XB)", &options_.pseudolocalize);
62 AddOptionalSwitch("--no-crunch", "Disables PNG processing", &options_.no_png_crunch);
63 AddOptionalSwitch("--legacy", "Treat errors that used to be valid in AAPT as warnings",
64 &options_.legacy_mode);
Donald Chai94e4a012020-01-06 13:52:41 -080065 AddOptionalSwitch("--preserve-visibility-of-styleables",
66 "If specified, apply the same visibility rules for\n"
67 "styleables as are used for all other resources.\n"
68 "Otherwise, all stylesables will be made public.",
69 &options_.preserve_visibility_of_styleables);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070070 AddOptionalFlag("--visibility",
71 "Sets the visibility of the compiled resources to the specified\n"
72 "level. Accepted levels: public, private, default", &visibility_);
Ryan Mitchellf3649d62018-08-02 16:16:45 -070073 AddOptionalSwitch("-v", "Enables verbose logging", &options_.verbose);
Fabien Sanglard2d34e762019-02-21 15:13:29 -080074 AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.",
75 &trace_folder_);
lukeedgar19b8ebf2020-06-23 10:43:42 +010076 AddOptionalFlag("--source-path",
77 "Sets the compiled resource file source file path to the given string.",
78 &options_.source_path);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070079 }
80
81 int Action(const std::vector<std::string>& args) override;
82
83 private:
84 IDiagnostics* diagnostic_;
85 CompileOptions options_;
Ryan Mitchell4382e442021-07-14 12:53:01 -070086 std::optional<std::string> visibility_;
87 std::optional<std::string> trace_folder_;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070088};
yd6b83292018-04-11 09:54:56 -070089
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080090int Compile(IAaptContext* context, io::IFileCollection* inputs, IArchiveWriter* output_writer,
91 CompileOptions& options);
92
yd6b83292018-04-11 09:54:56 -070093}// namespace aapt
94
95#endif //AAPT2_COMPILE_H