blob: 1752a1adac24645c8a1985ff4fb9ed4bd6fd1627 [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
20#include "androidfw/StringPiece.h"
Ryan Mitchellf3649d62018-08-02 16:16:45 -070021#include "format/Archive.h"
22#include "process/IResourceTableConsumer.h"
Ryan Mitchell833a1a62018-07-10 13:51:36 -070023#include "Command.h"
yd6b83292018-04-11 09:54:56 -070024#include "Diagnostics.h"
Ryan Mitchell833a1a62018-07-10 13:51:36 -070025#include "ResourceTable.h"
yd6b83292018-04-11 09:54:56 -070026
27namespace aapt {
28
Ryan Mitchell833a1a62018-07-10 13:51:36 -070029struct CompileOptions {
30 std::string output_path;
31 Maybe<std::string> res_dir;
Ryan Mitchellf3649d62018-08-02 16:16:45 -070032 Maybe<std::string> res_zip;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070033 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;
Donald Chai94e4a012020-01-06 13:52:41 -080038 // See comments on aapt::ResourceParserOptions.
39 bool preserve_visibility_of_styleables = false;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070040 bool verbose = false;
41};
42
Ryan Mitchellf3649d62018-08-02 16:16:45 -070043/** Parses flags and compiles resources to be used in linking. */
Ryan Mitchell833a1a62018-07-10 13:51:36 -070044class CompileCommand : public Command {
45 public:
46 explicit CompileCommand(IDiagnostics* diagnostic) : Command("compile", "c"),
47 diagnostic_(diagnostic) {
48 SetDescription("Compiles resources to be linked into an apk.");
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080049 AddRequiredFlag("-o", "Output path", &options_.output_path, Command::kPath);
50 AddOptionalFlag("--dir", "Directory to scan for resources", &options_.res_dir, Command::kPath);
Ryan Mitchellf3649d62018-08-02 16:16:45 -070051 AddOptionalFlag("--zip", "Zip file containing the res directory to scan for resources",
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080052 &options_.res_zip, Command::kPath);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070053 AddOptionalFlag("--output-text-symbols",
54 "Generates a text file containing the resource symbols in the\n"
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080055 "specified file", &options_.generate_text_symbols_path, Command::kPath);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070056 AddOptionalSwitch("--pseudo-localize", "Generate resources for pseudo-locales "
57 "(en-XA and ar-XB)", &options_.pseudolocalize);
58 AddOptionalSwitch("--no-crunch", "Disables PNG processing", &options_.no_png_crunch);
59 AddOptionalSwitch("--legacy", "Treat errors that used to be valid in AAPT as warnings",
60 &options_.legacy_mode);
Donald Chai94e4a012020-01-06 13:52:41 -080061 AddOptionalSwitch("--preserve-visibility-of-styleables",
62 "If specified, apply the same visibility rules for\n"
63 "styleables as are used for all other resources.\n"
64 "Otherwise, all stylesables will be made public.",
65 &options_.preserve_visibility_of_styleables);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070066 AddOptionalFlag("--visibility",
67 "Sets the visibility of the compiled resources to the specified\n"
68 "level. Accepted levels: public, private, default", &visibility_);
Ryan Mitchellf3649d62018-08-02 16:16:45 -070069 AddOptionalSwitch("-v", "Enables verbose logging", &options_.verbose);
Fabien Sanglard2d34e762019-02-21 15:13:29 -080070 AddOptionalFlag("--trace-folder", "Generate systrace json trace fragment to specified folder.",
71 &trace_folder_);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070072 }
73
74 int Action(const std::vector<std::string>& args) override;
75
76 private:
77 IDiagnostics* diagnostic_;
78 CompileOptions options_;
79 Maybe<std::string> visibility_;
Fabien Sanglard2d34e762019-02-21 15:13:29 -080080 Maybe<std::string> trace_folder_;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070081};
yd6b83292018-04-11 09:54:56 -070082
Ryan Mitchell2c8fc862018-12-13 16:56:07 -080083int Compile(IAaptContext* context, io::IFileCollection* inputs, IArchiveWriter* output_writer,
84 CompileOptions& options);
85
yd6b83292018-04-11 09:54:56 -070086}// namespace aapt
87
88#endif //AAPT2_COMPILE_H