blob: 0bcc4f2d8c8ccf2bd97d7e5e977e8900ff9e91ed [file] [log] [blame]
Christopher Wiley4427d862015-09-14 11:07:39 -07001/*
2 * Copyright (C) 2015, 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 */
Adam Lesinskiffa16862014-01-23 18:17:42 -080016
17#include "options.h"
Jiyong Park05463732018-08-09 16:03:02 +090018#include "logging.h"
Jiyong Park6f77e0c2018-07-28 16:55:44 +090019#include "os.h"
Adam Lesinskiffa16862014-01-23 18:17:42 -080020
Jiyong Park74595c12018-07-23 15:22:50 +090021#include <getopt.h>
22#include <stdlib.h>
23#include <unistd.h>
Jiyong Park8c380532018-08-30 14:55:26 +090024#include <algorithm>
Christopher Wileya590de82015-09-15 15:46:28 -070025#include <iostream>
Jiyong Park74595c12018-07-23 15:22:50 +090026#include <sstream>
27#include <string>
Adam Lesinskiffa16862014-01-23 18:17:42 -080028
Jiyong Park74595c12018-07-23 15:22:50 +090029#include <android-base/strings.h>
Devin Moore7b8d5c92020-03-17 14:14:08 -070030#include "aidl_language.h"
Christopher Wiley4432ccf2015-09-18 18:32:08 -070031
Jiyong Park6f77e0c2018-07-28 16:55:44 +090032using android::base::Split;
Jiyong Park74595c12018-07-23 15:22:50 +090033using android::base::Trim;
Christopher Wileya590de82015-09-15 15:46:28 -070034using std::endl;
Christopher Wiley4427d862015-09-14 11:07:39 -070035using std::string;
Christopher Wiley4427d862015-09-14 11:07:39 -070036
Steven Moreland1c894432020-02-14 11:32:44 -080037#ifndef PLATFORM_SDK_VERSION
38#define PLATFORM_SDK_VERSION "<UNKNOWN>"
39#endif
40
Christopher Wiley4427d862015-09-14 11:07:39 -070041namespace android {
42namespace aidl {
Christopher Wiley4427d862015-09-14 11:07:39 -070043
Jiyong Park74595c12018-07-23 15:22:50 +090044string Options::GetUsage() const {
45 std::ostringstream sstr;
Steven Moreland1c894432020-02-14 11:32:44 -080046 sstr << "AIDL Compiler: built for platform SDK version " << PLATFORM_SDK_VERSION << endl;
Jiyong Park74595c12018-07-23 15:22:50 +090047 sstr << "usage:" << endl
Steven Morelandbaa70642019-10-25 16:33:10 -070048 << myname_ << " --lang={java|cpp|ndk} [OPTION]... INPUT..." << endl
Jiyong Park74595c12018-07-23 15:22:50 +090049 << " Generate Java or C++ files for AIDL file(s)." << endl
Steven Morelandda0654f2018-07-17 12:24:38 -070050 << endl
Jiyong Park74595c12018-07-23 15:22:50 +090051 << myname_ << " --preprocess OUTPUT INPUT..." << endl
52 << " Create an AIDL file having declarations of AIDL file(s)." << endl
Steven Morelandda0654f2018-07-17 12:24:38 -070053 << endl
Jiyong Parke59c3682018-09-11 23:10:25 +090054#ifndef _WIN32
55 << myname_ << " --dumpapi --out=DIR INPUT..." << endl
56 << " Dump API signature of AIDL file(s) to DIR." << endl
Jiyong Park3656c3c2018-08-01 20:02:01 +090057 << endl
Jiyong Parke59c3682018-09-11 23:10:25 +090058 << myname_ << " --checkapi OLD_DIR NEW_DIR" << endl
59 << " Checkes whether API dump NEW_DIR is backwards compatible extension " << endl
60 << " of the API dump OLD_DIR." << endl
61#endif
Steven Morelandda0654f2018-07-17 12:24:38 -070062 << endl;
Adam Lesinskiffa16862014-01-23 18:17:42 -080063
Jiyong Park74595c12018-07-23 15:22:50 +090064 // Legacy option formats
65 if (language_ == Options::Language::JAVA) {
66 sstr << myname_ << " [OPTION]... INPUT [OUTPUT]" << endl
67 << " Generate a Java file for an AIDL file." << endl
68 << endl;
69 } else if (language_ == Options::Language::CPP) {
70 sstr << myname_ << " [OPTION]... INPUT HEADER_DIR OUTPUT" << endl
71 << " Generate C++ headers and source for an AIDL file." << endl
72 << endl;
Christopher Wiley4427d862015-09-14 11:07:39 -070073 }
74
Jiyong Park74595c12018-07-23 15:22:50 +090075 sstr << "OPTION:" << endl
76 << " -I DIR, --include=DIR" << endl
77 << " Use DIR as a search path for import statements." << endl
Jiyong Park3c35e392018-08-30 13:10:30 +090078 << " -m FILE, --import=FILE" << endl
79 << " Import FILE directly without searching in the search paths." << endl
Jiyong Park74595c12018-07-23 15:22:50 +090080 << " -p FILE, --preprocessed=FILE" << endl
81 << " Include FILE which is created by --preprocess." << endl
82 << " -d FILE, --dep=FILE" << endl
83 << " Generate dependency file as FILE. Don't use this when" << endl
84 << " there are multiple input files. Use -a then." << endl
85 << " -o DIR, --out=DIR" << endl
86 << " Use DIR as the base output directory for generated files." << endl
87 << " -h DIR, --header_out=DIR" << endl
88 << " Generate C++ headers under DIR." << endl
89 << " -a" << endl
90 << " Generate dependency file next to the output file with the" << endl
91 << " name based on the input file." << endl
92 << " -b" << endl
93 << " Trigger fail when trying to compile a parcelable." << endl
94 << " --ninja" << endl
95 << " Generate dependency file in a format ninja understands." << endl
Steven Moreland6cee3482018-07-18 14:39:58 -070096 << " --structured" << endl
97 << " Whether this interface is defined exclusively in AIDL." << endl
98 << " It is therefore a candidate for stabilization." << endl
Steven Morelanda57d0a62019-07-30 09:41:14 -070099 << " --stability=<level>" << endl
100 << " The stability requirement of this interface." << endl
Jiyong Park74595c12018-07-23 15:22:50 +0900101 << " -t, --trace" << endl
102 << " Include tracing code for systrace. Note that if either" << endl
103 << " the client or service code is not auto-generated by this" << endl
104 << " tool, that part will not be traced." << endl
105 << " --transaction_names" << endl
106 << " Generate transaction names." << endl
Andrei Onea8714b022019-02-01 18:55:54 +0000107 << " --apimapping" << endl
108 << " Generates a mapping of declared aidl method signatures to" << endl
109 << " the original line number. e.g.: " << endl
110 << " If line 39 of foo/bar/IFoo.aidl contains:"
111 << " void doFoo(int bar, String baz);" << endl
112 << " Then the result would be:" << endl
113 << " foo.bar.Baz|doFoo|int,String,|void" << endl
114 << " foo/bar/IFoo.aidl:39" << endl
Jiyong Park309668e2018-07-28 16:55:44 +0900115 << " -v VER, --version=VER" << endl
116 << " Set the version of the interface and parcelable to VER." << endl
117 << " VER must be an interger greater than 0." << endl
Paul Trautrimb77048c2020-01-21 16:39:32 +0900118 << " --hash=HASH" << endl
119 << " Set the interface hash to HASH." << endl
Jiyong Parkce50e262018-10-29 09:54:20 +0900120 << " --log" << endl
121 << " Information about the transaction, e.g., method name, argument" << endl
122 << " values, execution time, etc., is provided via callback." << endl
Nikita Ioffe8954a0e2019-06-25 23:36:13 +0100123 << " --parcelable-to-string" << endl
124 << " Generates an implementation of toString() for Java parcelables," << endl
125 << " and ostream& operator << for C++ parcelables." << endl
Jiyong Park74595c12018-07-23 15:22:50 +0900126 << " --help" << endl
127 << " Show this help." << endl
128 << endl
129 << "INPUT:" << endl
130 << " An AIDL file." << endl
131 << endl
132 << "OUTPUT:" << endl
133 << " Path to the generated Java or C++ source file. This is ignored when" << endl
134 << " -o or --out is specified or the number of the input files are" << endl
135 << " more than one." << endl
136 << " For Java, if omitted, Java source file is generated at the same" << endl
137 << " place as the input AIDL file," << endl
138 << endl
Christopher Wiley054afbd2015-10-16 17:08:43 -0700139 << "HEADER_DIR:" << endl
Jiyong Park74595c12018-07-23 15:22:50 +0900140 << " Path to where C++ headers are generated." << endl;
141 return sstr.str();
Christopher Wileya590de82015-09-15 15:46:28 -0700142}
143
Devin Moore7b8d5c92020-03-17 14:14:08 -0700144const string Options::LanguageToString(Language language) {
145 switch (language) {
146 case Options::Language::CPP:
147 return "cpp";
148 case Options::Language::JAVA:
149 return "java";
150 case Options::Language::NDK:
151 return "ndk";
152 case Options::Language::UNSPECIFIED:
153 return "unspecified";
154 default:
155 AIDL_FATAL(AIDL_LOCATION_HERE)
156 << "Unexpected Options::Language enumerator: " << static_cast<size_t>(language);
157 }
158}
159
Steven Morelanda57d0a62019-07-30 09:41:14 -0700160bool Options::StabilityFromString(const std::string& stability, Stability* out_stability) {
161 if (stability == "vintf") {
162 *out_stability = Stability::VINTF;
163 return true;
164 }
165 return false;
166}
167
Jiyong Park6f77e0c2018-07-28 16:55:44 +0900168Options Options::From(const string& cmdline) {
169 vector<string> args = Split(cmdline, " ");
170 return From(args);
171}
172
173Options Options::From(const vector<string>& args) {
174 Options::Language lang = Options::Language::JAVA;
175 int argc = args.size();
176 if (argc >= 1 && args.at(0) == "aidl-cpp") {
177 lang = Options::Language::CPP;
178 }
179 const char* argv[argc + 1];
180 for (int i = 0; i < argc; i++) {
181 argv[i] = args.at(i).c_str();
182 }
183 argv[argc] = nullptr;
184
185 return Options(argc, argv, lang);
186}
187
Jiyong Park74595c12018-07-23 15:22:50 +0900188Options::Options(int argc, const char* const argv[], Options::Language default_lang)
189 : myname_(argv[0]), language_(default_lang) {
190 bool lang_option_found = false;
Jiyong Park6f77e0c2018-07-28 16:55:44 +0900191 optind = 0;
Jiyong Park74595c12018-07-23 15:22:50 +0900192 while (true) {
193 static struct option long_options[] = {
194 {"lang", required_argument, 0, 'l'},
195 {"preprocess", no_argument, 0, 's'},
Jiyong Parke59c3682018-09-11 23:10:25 +0900196#ifndef _WIN32
Jiyong Park74595c12018-07-23 15:22:50 +0900197 {"dumpapi", no_argument, 0, 'u'},
Jiyong Park3656c3c2018-08-01 20:02:01 +0900198 {"checkapi", no_argument, 0, 'A'},
Jiyong Parke59c3682018-09-11 23:10:25 +0900199#endif
Andrei Onea8714b022019-02-01 18:55:54 +0000200 {"apimapping", required_argument, 0, 'i'},
Jiyong Park74595c12018-07-23 15:22:50 +0900201 {"include", required_argument, 0, 'I'},
Jiyong Park3c35e392018-08-30 13:10:30 +0900202 {"import", required_argument, 0, 'm'},
Jiyong Park74595c12018-07-23 15:22:50 +0900203 {"preprocessed", required_argument, 0, 'p'},
204 {"dep", required_argument, 0, 'd'},
205 {"out", required_argument, 0, 'o'},
206 {"header_out", required_argument, 0, 'h'},
207 {"ninja", no_argument, 0, 'n'},
Steven Morelanda57d0a62019-07-30 09:41:14 -0700208 {"stability", required_argument, 0, 'Y'},
Steven Moreland6cee3482018-07-18 14:39:58 -0700209 {"structured", no_argument, 0, 'S'},
Jiyong Park74595c12018-07-23 15:22:50 +0900210 {"trace", no_argument, 0, 't'},
211 {"transaction_names", no_argument, 0, 'c'},
Jiyong Park309668e2018-07-28 16:55:44 +0900212 {"version", required_argument, 0, 'v'},
Jiyong Parkce50e262018-10-29 09:54:20 +0900213 {"log", no_argument, 0, 'L'},
Nikita Ioffe8954a0e2019-06-25 23:36:13 +0100214 {"parcelable-to-string", no_argument, 0, 'P'},
Paul Trautrimb77048c2020-01-21 16:39:32 +0900215 {"hash", required_argument, 0, 'H'},
Jiyong Park74595c12018-07-23 15:22:50 +0900216 {"help", no_argument, 0, 'e'},
217 {0, 0, 0, 0},
218 };
Jiyong Park3c35e392018-08-30 13:10:30 +0900219 const int c = getopt_long(argc, const_cast<char* const*>(argv),
220 "I:m:p:d:o:h:abtv:", long_options, nullptr);
Jiyong Park74595c12018-07-23 15:22:50 +0900221 if (c == -1) {
222 // no more options
223 break;
Christopher Wileya590de82015-09-15 15:46:28 -0700224 }
Jiyong Park74595c12018-07-23 15:22:50 +0900225 switch (c) {
226 case 'l':
227 if (language_ == Options::Language::CPP) {
228 // aidl-cpp can't set language. aidl-cpp exists only for backwards
229 // compatibility.
230 error_message_ << "aidl-cpp does not support --lang." << endl;
231 return;
232 } else {
233 lang_option_found = true;
Jiyong Park309668e2018-07-28 16:55:44 +0900234 string lang = Trim(optarg);
Jiyong Park74595c12018-07-23 15:22:50 +0900235 if (lang == "java") {
236 language_ = Options::Language::JAVA;
237 task_ = Options::Task::COMPILE;
238 } else if (lang == "cpp") {
239 language_ = Options::Language::CPP;
240 task_ = Options::Task::COMPILE;
Steven Morelandc26d8142018-09-17 14:25:33 -0700241 } else if (lang == "ndk") {
242 language_ = Options::Language::NDK;
243 task_ = Options::Task::COMPILE;
Jiyong Park74595c12018-07-23 15:22:50 +0900244 } else {
245 error_message_ << "Unsupported language: '" << lang << "'" << endl;
246 return;
247 }
248 }
249 break;
250 case 's':
251 if (task_ != Options::Task::UNSPECIFIED) {
252 task_ = Options::Task::PREPROCESS;
253 }
254 break;
Jiyong Parke59c3682018-09-11 23:10:25 +0900255#ifndef _WIN32
Jiyong Park74595c12018-07-23 15:22:50 +0900256 case 'u':
257 if (task_ != Options::Task::UNSPECIFIED) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900258 task_ = Options::Task::DUMP_API;
259 }
260 break;
261 case 'A':
262 if (task_ != Options::Task::UNSPECIFIED) {
263 task_ = Options::Task::CHECK_API;
264 // to ensure that all parcelables in the api dumpes are structured
265 structured_ = true;
Jiyong Park74595c12018-07-23 15:22:50 +0900266 }
267 break;
Jiyong Parke59c3682018-09-11 23:10:25 +0900268#endif
Jiyong Park8c380532018-08-30 14:55:26 +0900269 case 'I': {
270 import_dirs_.emplace(Trim(optarg));
Jiyong Park3c35e392018-08-30 13:10:30 +0900271 break;
Jiyong Park8c380532018-08-30 14:55:26 +0900272 }
273 case 'm': {
274 import_files_.emplace(Trim(optarg));
Jiyong Park74595c12018-07-23 15:22:50 +0900275 break;
Jiyong Park8c380532018-08-30 14:55:26 +0900276 }
Jiyong Park74595c12018-07-23 15:22:50 +0900277 case 'p':
Jiyong Park309668e2018-07-28 16:55:44 +0900278 preprocessed_files_.emplace_back(Trim(optarg));
Jiyong Park74595c12018-07-23 15:22:50 +0900279 break;
280 case 'd':
Jiyong Park309668e2018-07-28 16:55:44 +0900281 dependency_file_ = Trim(optarg);
Jiyong Park74595c12018-07-23 15:22:50 +0900282 break;
283 case 'o':
Jiyong Park309668e2018-07-28 16:55:44 +0900284 output_dir_ = Trim(optarg);
Jiyong Park05463732018-08-09 16:03:02 +0900285 if (output_dir_.back() != OS_PATH_SEPARATOR) {
286 output_dir_.push_back(OS_PATH_SEPARATOR);
287 }
Jiyong Park74595c12018-07-23 15:22:50 +0900288 break;
289 case 'h':
Jiyong Park309668e2018-07-28 16:55:44 +0900290 output_header_dir_ = Trim(optarg);
Jiyong Park05463732018-08-09 16:03:02 +0900291 if (output_header_dir_.back() != OS_PATH_SEPARATOR) {
292 output_header_dir_.push_back(OS_PATH_SEPARATOR);
293 }
Jiyong Park74595c12018-07-23 15:22:50 +0900294 break;
295 case 'n':
296 dependency_file_ninja_ = true;
297 break;
Steven Moreland6cee3482018-07-18 14:39:58 -0700298 case 'S':
299 structured_ = true;
300 break;
Steven Morelanda57d0a62019-07-30 09:41:14 -0700301 case 'Y': {
302 const string stability_str = Trim(optarg);
303 if (!StabilityFromString(stability_str, &stability_)) {
304 error_message_ << "Unrecognized stability level: '" << stability_str
305 << "'. Must be vintf." << endl;
306 return;
307 }
308 break;
309 }
Jiyong Park74595c12018-07-23 15:22:50 +0900310 case 't':
311 gen_traces_ = true;
312 break;
313 case 'a':
314 auto_dep_file_ = true;
315 break;
316 case 'b':
317 fail_on_parcelable_ = true;
318 break;
319 case 'c':
320 gen_transaction_names_ = true;
321 break;
Jiyong Park309668e2018-07-28 16:55:44 +0900322 case 'v': {
323 const string ver_str = Trim(optarg);
324 int ver = atoi(ver_str.c_str());
325 if (ver > 0) {
326 version_ = ver;
327 } else {
328 error_message_ << "Invalid version number: '" << ver_str << "'. "
329 << "Version must be a positive natural number." << endl;
330 return;
331 }
332 break;
333 }
Paul Trautrimb77048c2020-01-21 16:39:32 +0900334 case 'H':
335 hash_ = Trim(optarg);
336 break;
Jiyong Parkce50e262018-10-29 09:54:20 +0900337 case 'L':
338 gen_log_ = true;
339 break;
Jiyong Park74595c12018-07-23 15:22:50 +0900340 case 'e':
341 std::cerr << GetUsage();
342 exit(0);
Andrei Onea8714b022019-02-01 18:55:54 +0000343 case 'i':
344 output_file_ = Trim(optarg);
345 task_ = Task::DUMP_MAPPINGS;
346 break;
Nikita Ioffe8954a0e2019-06-25 23:36:13 +0100347 case 'P':
348 gen_parcelable_to_string_ = true;
349 break;
Jiyong Park74595c12018-07-23 15:22:50 +0900350 default:
Steven Moreland4dbadf52018-08-08 17:46:10 -0700351 std::cerr << GetUsage();
352 exit(1);
Jiyong Park74595c12018-07-23 15:22:50 +0900353 }
354 } // while
355
356 // Positional arguments
357 if (!lang_option_found && task_ == Options::Task::COMPILE) {
358 // the legacy arguments format
359 if (argc - optind <= 0) {
360 error_message_ << "No input file" << endl;
361 return;
362 }
363 if (language_ == Options::Language::JAVA) {
364 input_files_.emplace_back(argv[optind++]);
365 if (argc - optind >= 1) {
366 output_file_ = argv[optind++];
Jiyong Park56f73d72019-06-11 12:20:28 +0900367 } else if (output_dir_.empty()) {
368 // when output is omitted and -o option isn't set, the output is by
369 // default set to the input file path with .aidl is replaced to .java.
370 // If -o option is set, the output path is calculated by
371 // generate_outputFileName which returns "<output_dir>/<package/name>/
372 // <typename>.java"
Jiyong Park74595c12018-07-23 15:22:50 +0900373 output_file_ = input_files_.front();
Steven Moreland4dbadf52018-08-08 17:46:10 -0700374 if (android::base::EndsWith(output_file_, ".aidl")) {
375 output_file_ = output_file_.substr(0, output_file_.length() - strlen(".aidl"));
376 }
377 output_file_ += ".java";
Jiyong Park74595c12018-07-23 15:22:50 +0900378 }
Steven Morelandc26d8142018-09-17 14:25:33 -0700379 } else if (IsCppOutput()) {
Jiyong Park74595c12018-07-23 15:22:50 +0900380 input_files_.emplace_back(argv[optind++]);
381 if (argc - optind < 2) {
382 error_message_ << "No HEADER_DIR or OUTPUT." << endl;
383 return;
384 }
385 output_header_dir_ = argv[optind++];
Jiyong Park05463732018-08-09 16:03:02 +0900386 if (output_header_dir_.back() != OS_PATH_SEPARATOR) {
387 output_header_dir_.push_back(OS_PATH_SEPARATOR);
388 }
Jiyong Park74595c12018-07-23 15:22:50 +0900389 output_file_ = argv[optind++];
390 }
391 if (argc - optind > 0) {
392 error_message_ << "Too many arguments: ";
393 for (int i = optind; i < argc; i++) {
394 error_message_ << " " << argv[i];
395 }
396 error_message_ << endl;
397 }
Jiyong Park74595c12018-07-23 15:22:50 +0900398 } else {
399 // the new arguments format
Jiyong Parke59c3682018-09-11 23:10:25 +0900400 if (task_ == Options::Task::COMPILE || task_ == Options::Task::DUMP_API) {
Jiyong Park74595c12018-07-23 15:22:50 +0900401 if (argc - optind < 1) {
402 error_message_ << "No input file." << endl;
403 return;
404 }
405 } else {
406 if (argc - optind < 2) {
407 error_message_ << "Insufficient arguments. At least 2 required, but "
408 << "got " << (argc - optind) << "." << endl;
409 return;
410 }
Andrei Onea8714b022019-02-01 18:55:54 +0000411 if (task_ != Options::Task::CHECK_API && task_ != Options::Task::DUMP_MAPPINGS) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900412 output_file_ = argv[optind++];
413 }
Jiyong Park74595c12018-07-23 15:22:50 +0900414 }
415 while (optind < argc) {
416 input_files_.emplace_back(argv[optind++]);
417 }
Christopher Wileya590de82015-09-15 15:46:28 -0700418 }
419
Jiyong Park74595c12018-07-23 15:22:50 +0900420 // filter out invalid combinations
Steven Moreland4dbadf52018-08-08 17:46:10 -0700421 if (lang_option_found) {
Steven Morelandc26d8142018-09-17 14:25:33 -0700422 if (IsCppOutput() && task_ == Options::Task::COMPILE) {
Steven Moreland4dbadf52018-08-08 17:46:10 -0700423 if (output_dir_.empty()) {
424 error_message_ << "Output directory is not set. Set with --out." << endl;
425 return;
426 }
427 if (output_header_dir_.empty()) {
428 error_message_ << "Header output directory is not set. Set with "
429 << "--header_out." << endl;
430 return;
431 }
Jiyong Park74595c12018-07-23 15:22:50 +0900432 }
Steven Moreland4dbadf52018-08-08 17:46:10 -0700433 if (language_ == Options::Language::JAVA && task_ == Options::Task::COMPILE) {
434 if (output_dir_.empty()) {
435 error_message_ << "Output directory is not set. Set with --out." << endl;
436 return;
437 }
438 if (!output_header_dir_.empty()) {
439 error_message_ << "Header output directory is set, which does not make "
440 << "sense for Java." << endl;
441 return;
442 }
Jiyong Park74595c12018-07-23 15:22:50 +0900443 }
444 }
445 if (task_ == Options::Task::COMPILE) {
Jiyong Parke59c3682018-09-11 23:10:25 +0900446 for (const string& input : input_files_) {
447 if (!android::base::EndsWith(input, ".aidl")) {
448 error_message_ << "Expected .aidl file for input but got '" << input << "'" << endl;
449 return;
450 }
451 }
Jiyong Park74595c12018-07-23 15:22:50 +0900452 if (!output_file_.empty() && input_files_.size() > 1) {
453 error_message_ << "Multiple AIDL files can't be compiled to a single "
454 << "output file '" << output_file_ << "'. "
455 << "Use --out=DIR instead for output files." << endl;
456 return;
457 }
458 if (!dependency_file_.empty() && input_files_.size() > 1) {
459 error_message_ << "-d or --dep doesn't work when compiling multiple AIDL "
460 << "files. Use '-a' to generate dependency file next to "
461 << "the output file with the name based on the input "
462 << "file." << endl;
463 return;
464 }
Jeongik Cha37e2ad52019-04-18 13:44:26 +0900465 if (gen_log_ && (language_ != Options::Language::CPP && language_ != Options::Language::NDK)) {
466 error_message_ << "--log is currently supported for either --lang=cpp or --lang=ndk" << endl;
Jiyong Parkce50e262018-10-29 09:54:20 +0900467 return;
468 }
Christopher Wileya590de82015-09-15 15:46:28 -0700469 }
Jiyong Park309668e2018-07-28 16:55:44 +0900470 if (task_ == Options::Task::PREPROCESS) {
471 if (version_ > 0) {
472 error_message_ << "--version should not be used with '--preprocess'." << endl;
473 return;
474 }
475 }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900476 if (task_ == Options::Task::CHECK_API) {
477 if (input_files_.size() != 2) {
478 error_message_ << "--checkapi requires two inputs for comparing, "
479 << "but got " << input_files_.size() << "." << endl;
480 return;
481 }
482 }
Jiyong Parke59c3682018-09-11 23:10:25 +0900483 if (task_ == Options::Task::DUMP_API) {
484 if (output_dir_.empty()) {
485 error_message_ << "--dump_api requires output directory. Use --out." << endl;
486 return;
487 }
488 }
Jiyong Park05463732018-08-09 16:03:02 +0900489
490 CHECK(output_dir_.empty() || output_dir_.back() == OS_PATH_SEPARATOR);
491 CHECK(output_header_dir_.empty() || output_header_dir_.back() == OS_PATH_SEPARATOR);
Christopher Wileya590de82015-09-15 15:46:28 -0700492}
493
Christopher Wiley4427d862015-09-14 11:07:39 -0700494} // namespace aidl
Steven Morelandf4c64df2019-07-29 19:54:04 -0700495} // namespace android