blob: 73d33bb98b915c147e701ab2b5ffb4fe132d8d53 [file] [log] [blame]
Christopher Wiley4427d862015-09-14 11:07:39 -07001/*
Christopher Wileyb1bbdf82016-04-21 11:43:45 -07002 * Copyright (C) 2015, The Android Open Source Project *
Christopher Wiley4427d862015-09-14 11:07:39 -07003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
Steven Moreland9fccf582018-08-27 20:36:27 -070016#pragma once
Adam Lesinskiffa16862014-01-23 18:17:42 -080017
Jiyong Park8c380532018-08-30 14:55:26 +090018#include <set>
Jiyong Park74595c12018-07-23 15:22:50 +090019#include <sstream>
Adam Lesinskiffa16862014-01-23 18:17:42 -080020#include <string>
21#include <vector>
22
Christopher Wiley4427d862015-09-14 11:07:39 -070023namespace android {
24namespace aidl {
Adam Lesinskiffa16862014-01-23 18:17:42 -080025
Jiyong Park8c380532018-08-30 14:55:26 +090026using std::set;
Jiyong Park1d2df7d2018-07-23 15:22:50 +090027using std::string;
28using std::vector;
29
Jiyong Park6f77e0c2018-07-28 16:55:44 +090030// A simple wrapper around ostringstream. This is just to make Options class
31// copiable by the implicit copy constructor. If ostingstream is not wrapped,
32// the implcit copy constructor is not generated because ostringstream isn't
33// copiable. This class makes the field copiable by having a copy constructor
34// that does not copy the underlying stream.
35class ErrorMessage {
36 public:
37 ErrorMessage() = default;
38 ErrorMessage(const ErrorMessage&) {}
39 std::ostringstream stream_;
Jiyong Parke1d02682018-08-01 12:18:02 +090040
41 template <typename T>
42 ErrorMessage& operator<<(T& t) {
43 stream_ << t;
Jiyong Park6f77e0c2018-07-28 16:55:44 +090044 return *this;
45 }
Jiyong Parke1d02682018-08-01 12:18:02 +090046
47 template <typename T>
48 ErrorMessage& operator<<(const T& t) {
49 stream_ << t;
Jiyong Park6f77e0c2018-07-28 16:55:44 +090050 return *this;
51 }
Jiyong Parke1d02682018-08-01 12:18:02 +090052
53 // for "<< endl"
Jiyong Park6f77e0c2018-07-28 16:55:44 +090054 ErrorMessage& operator<<(std::ostream& (*f)(std::ostream&)) {
55 f(stream_);
56 return *this;
57 }
58};
59
Jiyong Park74595c12018-07-23 15:22:50 +090060class Options final {
Steven Morelandda0654f2018-07-17 12:24:38 -070061 public:
Steven Morelandc26d8142018-09-17 14:25:33 -070062 enum class Language { UNSPECIFIED, JAVA, CPP, NDK };
Steven Morelandda0654f2018-07-17 12:24:38 -070063
Andrei Onea8714b022019-02-01 18:55:54 +000064 enum class Task { UNSPECIFIED, COMPILE, PREPROCESS, DUMP_API, CHECK_API, DUMP_MAPPINGS };
Steven Morelandda0654f2018-07-17 12:24:38 -070065
Steven Morelanda57d0a62019-07-30 09:41:14 -070066 enum class Stability { UNSPECIFIED, VINTF };
67 bool StabilityFromString(const std::string& stability, Stability* out_stability);
68
Jiyong Park74595c12018-07-23 15:22:50 +090069 Options(int argc, const char* const argv[], Language default_lang = Language::UNSPECIFIED);
Steven Morelandda0654f2018-07-17 12:24:38 -070070
Jiyong Park6f77e0c2018-07-28 16:55:44 +090071 static Options From(const string& cmdline);
72
73 static Options From(const vector<string>& args);
74
Steven Moreland6cee3482018-07-18 14:39:58 -070075 // Contain no references to unstructured data types (such as a parcelable that is
76 // implemented in Java). These interfaces aren't inherently stable but they have the
77 // capacity to be stabilized.
78 bool IsStructured() const { return structured_; }
79
Steven Morelanda57d0a62019-07-30 09:41:14 -070080 Stability GetStability() const { return stability_; }
81
Jiyong Park74595c12018-07-23 15:22:50 +090082 Language TargetLanguage() const { return language_; }
Steven Morelandc26d8142018-09-17 14:25:33 -070083 bool IsCppOutput() const { return language_ == Language::CPP || language_ == Language::NDK; }
Steven Morelandda0654f2018-07-17 12:24:38 -070084
Jiyong Park74595c12018-07-23 15:22:50 +090085 Task GetTask() const { return task_; }
Steven Morelandda0654f2018-07-17 12:24:38 -070086
Jiyong Park8c380532018-08-30 14:55:26 +090087 const set<string>& ImportDirs() const { return import_dirs_; }
Jiyong Park3c35e392018-08-30 13:10:30 +090088
Jiyong Park8c380532018-08-30 14:55:26 +090089 const set<string>& ImportFiles() const { return import_files_; }
Steven Morelandda0654f2018-07-17 12:24:38 -070090
Jiyong Park74595c12018-07-23 15:22:50 +090091 const vector<string>& PreprocessedFiles() const { return preprocessed_files_; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080092
Jiyong Park74595c12018-07-23 15:22:50 +090093 string DependencyFile() const {
Jiyong Park74595c12018-07-23 15:22:50 +090094 return dependency_file_;
95 }
Christopher Wiley4427d862015-09-14 11:07:39 -070096
Jiyong Park74595c12018-07-23 15:22:50 +090097 bool AutoDepFile() const { return auto_dep_file_; }
Christopher Wileyef4132c2015-11-05 15:47:40 -080098
Jiyong Park74595c12018-07-23 15:22:50 +090099 bool GenTraces() const { return gen_traces_; }
Steven Morelandda0654f2018-07-17 12:24:38 -0700100
Jiyong Park74595c12018-07-23 15:22:50 +0900101 bool GenTransactionNames() const { return gen_transaction_names_; }
Christopher Wiley4427d862015-09-14 11:07:39 -0700102
Jiyong Park74595c12018-07-23 15:22:50 +0900103 bool DependencyFileNinja() const { return dependency_file_ninja_; }
104
105 const vector<string>& InputFiles() const { return input_files_; }
106
107 // Path to the output file. This is used only when there is only one
108 // output file for the invocation. When there are multiple outputs
109 // (e.g. compile multiple AIDL files), output files are created under
110 // OutputDir().
111 const string& OutputFile() const { return output_file_; }
112
113 // Path to the directory where output file(s) will be generated under.
114 const string& OutputDir() const { return output_dir_; }
115
116 // Path to the directory where header file(s) will be generated under.
117 // Only used when TargetLanguage() == Language::CPP
118 const string& OutputHeaderDir() const { return output_header_dir_; }
119
120 bool FailOnParcelable() const { return fail_on_parcelable_; }
121
Jiyong Park309668e2018-07-28 16:55:44 +0900122 int Version() const { return version_; }
123
Paul Trautrim66f00962020-01-21 16:39:32 +0900124 string Hash() const { return hash_; }
125
Jiyong Parkce50e262018-10-29 09:54:20 +0900126 bool GenLog() const { return gen_log_; }
127
Nikita Ioffe8954a0e2019-06-25 23:36:13 +0100128 bool GenParcelableToString() const { return gen_parcelable_to_string_; }
129
Jiyong Park6f77e0c2018-07-28 16:55:44 +0900130 bool Ok() const { return error_message_.stream_.str().empty(); }
Jiyong Park74595c12018-07-23 15:22:50 +0900131
Jiyong Park6f77e0c2018-07-28 16:55:44 +0900132 string GetErrorMessage() const { return error_message_.stream_.str(); }
Jiyong Park74595c12018-07-23 15:22:50 +0900133
134 string GetUsage() const;
Andreas Gampee9c816e2018-03-14 09:05:48 -0700135
Andrei Onea8714b022019-02-01 18:55:54 +0000136 bool GenApiMapping() const { return task_ == Task::DUMP_MAPPINGS; }
137
Steven Morelandda0654f2018-07-17 12:24:38 -0700138 // The following are for testability, but cannot be influenced on the command line.
Andreas Gampee9c816e2018-03-14 09:05:48 -0700139 // Threshold of interface methods to enable outlining of onTransact cases.
140 size_t onTransact_outline_threshold_{275u};
141 // Number of cases to _not_ outline, if outlining is enabled.
142 size_t onTransact_non_outline_count_{275u};
143
Christopher Wiley4427d862015-09-14 11:07:39 -0700144 private:
Jiyong Park74595c12018-07-23 15:22:50 +0900145 Options() = default;
Christopher Wiley4427d862015-09-14 11:07:39 -0700146
Jiyong Park74595c12018-07-23 15:22:50 +0900147 const string myname_;
148 Language language_ = Language::UNSPECIFIED;
149 Task task_ = Task::COMPILE;
Jiyong Park8c380532018-08-30 14:55:26 +0900150 set<string> import_dirs_;
151 set<string> import_files_;
Jiyong Park74595c12018-07-23 15:22:50 +0900152 vector<string> preprocessed_files_;
153 string dependency_file_;
154 bool gen_traces_ = false;
155 bool gen_transaction_names_ = false;
156 bool dependency_file_ninja_ = false;
Steven Morelanda57d0a62019-07-30 09:41:14 -0700157 bool structured_ = false;
158 Stability stability_ = Stability::UNSPECIFIED;
Jiyong Park74595c12018-07-23 15:22:50 +0900159 string output_dir_;
160 string output_header_dir_;
161 bool fail_on_parcelable_ = false;
162 bool auto_dep_file_ = false;
163 vector<string> input_files_;
164 string output_file_;
Jiyong Park309668e2018-07-28 16:55:44 +0900165 int version_ = 0;
Paul Trautrim66f00962020-01-21 16:39:32 +0900166 string hash_ = "";
Jiyong Parkce50e262018-10-29 09:54:20 +0900167 bool gen_log_ = false;
Nikita Ioffe8954a0e2019-06-25 23:36:13 +0100168 bool gen_parcelable_to_string_ = false;
Jiyong Park6f77e0c2018-07-28 16:55:44 +0900169 ErrorMessage error_message_;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800170};
171
Christopher Wiley4427d862015-09-14 11:07:39 -0700172} // namespace aidl
Steven Morelandf4c64df2019-07-29 19:54:04 -0700173} // namespace android