Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 1 | /* |
| 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 Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 16 | |
| 17 | #include "options.h" |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 18 | #include "logging.h" |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 19 | #include "os.h" |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 20 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 21 | #include <getopt.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 24 | #include <algorithm> |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 25 | #include <iostream> |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 26 | #include <sstream> |
| 27 | #include <string> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 28 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 29 | #include <android-base/strings.h> |
Christopher Wiley | 4432ccf | 2015-09-18 18:32:08 -0700 | [diff] [blame] | 30 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 31 | using android::base::Split; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 32 | using android::base::Trim; |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 33 | using std::endl; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 34 | using std::string; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 35 | |
| 36 | namespace android { |
| 37 | namespace aidl { |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 38 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 39 | string Options::GetUsage() const { |
| 40 | std::ostringstream sstr; |
| 41 | sstr << "usage:" << endl |
| 42 | << myname_ << " --lang={java|cpp} [OPTION]... INPUT..." << endl |
| 43 | << " Generate Java or C++ files for AIDL file(s)." << endl |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 44 | << endl |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 45 | << myname_ << " --preprocess OUTPUT INPUT..." << endl |
| 46 | << " Create an AIDL file having declarations of AIDL file(s)." << endl |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 47 | << endl |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 48 | #ifndef _WIN32 |
| 49 | << myname_ << " --dumpapi --out=DIR INPUT..." << endl |
| 50 | << " Dump API signature of AIDL file(s) to DIR." << endl |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 51 | << endl |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 52 | << myname_ << " --checkapi OLD_DIR NEW_DIR" << endl |
| 53 | << " Checkes whether API dump NEW_DIR is backwards compatible extension " << endl |
| 54 | << " of the API dump OLD_DIR." << endl |
| 55 | #endif |
Steven Moreland | da0654f | 2018-07-17 12:24:38 -0700 | [diff] [blame] | 56 | << endl; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 57 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 58 | // Legacy option formats |
| 59 | if (language_ == Options::Language::JAVA) { |
| 60 | sstr << myname_ << " [OPTION]... INPUT [OUTPUT]" << endl |
| 61 | << " Generate a Java file for an AIDL file." << endl |
| 62 | << endl; |
| 63 | } else if (language_ == Options::Language::CPP) { |
| 64 | sstr << myname_ << " [OPTION]... INPUT HEADER_DIR OUTPUT" << endl |
| 65 | << " Generate C++ headers and source for an AIDL file." << endl |
| 66 | << endl; |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 69 | sstr << "OPTION:" << endl |
| 70 | << " -I DIR, --include=DIR" << endl |
| 71 | << " Use DIR as a search path for import statements." << endl |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 72 | << " -m FILE, --import=FILE" << endl |
| 73 | << " Import FILE directly without searching in the search paths." << endl |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 74 | << " -p FILE, --preprocessed=FILE" << endl |
| 75 | << " Include FILE which is created by --preprocess." << endl |
| 76 | << " -d FILE, --dep=FILE" << endl |
| 77 | << " Generate dependency file as FILE. Don't use this when" << endl |
| 78 | << " there are multiple input files. Use -a then." << endl |
| 79 | << " -o DIR, --out=DIR" << endl |
| 80 | << " Use DIR as the base output directory for generated files." << endl |
| 81 | << " -h DIR, --header_out=DIR" << endl |
| 82 | << " Generate C++ headers under DIR." << endl |
| 83 | << " -a" << endl |
| 84 | << " Generate dependency file next to the output file with the" << endl |
| 85 | << " name based on the input file." << endl |
| 86 | << " -b" << endl |
| 87 | << " Trigger fail when trying to compile a parcelable." << endl |
| 88 | << " --ninja" << endl |
| 89 | << " Generate dependency file in a format ninja understands." << endl |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 90 | << " --structured" << endl |
| 91 | << " Whether this interface is defined exclusively in AIDL." << endl |
| 92 | << " It is therefore a candidate for stabilization." << endl |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 93 | << " -t, --trace" << endl |
| 94 | << " Include tracing code for systrace. Note that if either" << endl |
| 95 | << " the client or service code is not auto-generated by this" << endl |
| 96 | << " tool, that part will not be traced." << endl |
| 97 | << " --transaction_names" << endl |
| 98 | << " Generate transaction names." << endl |
Andrei Onea | 390cb8b | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 99 | << " --apimapping" << endl |
| 100 | << " Generates a mapping of declared aidl method signatures to" << endl |
| 101 | << " the original line number. e.g.: " << endl |
| 102 | << " If line 39 of foo/bar/IFoo.aidl contains:" |
| 103 | << " void doFoo(int bar, String baz);" << endl |
| 104 | << " Then the result would be:" << endl |
| 105 | << " foo.bar.Baz|doFoo|int,String,|void" << endl |
| 106 | << " foo/bar/IFoo.aidl:39" << endl |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 107 | << " -v VER, --version=VER" << endl |
| 108 | << " Set the version of the interface and parcelable to VER." << endl |
| 109 | << " VER must be an interger greater than 0." << endl |
Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 110 | << " --log" << endl |
| 111 | << " Information about the transaction, e.g., method name, argument" << endl |
| 112 | << " values, execution time, etc., is provided via callback." << endl |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 113 | << " --help" << endl |
| 114 | << " Show this help." << endl |
| 115 | << endl |
| 116 | << "INPUT:" << endl |
| 117 | << " An AIDL file." << endl |
| 118 | << endl |
| 119 | << "OUTPUT:" << endl |
| 120 | << " Path to the generated Java or C++ source file. This is ignored when" << endl |
| 121 | << " -o or --out is specified or the number of the input files are" << endl |
| 122 | << " more than one." << endl |
| 123 | << " For Java, if omitted, Java source file is generated at the same" << endl |
| 124 | << " place as the input AIDL file," << endl |
| 125 | << endl |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 126 | << "HEADER_DIR:" << endl |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 127 | << " Path to where C++ headers are generated." << endl; |
| 128 | return sstr.str(); |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 131 | Options Options::From(const string& cmdline) { |
| 132 | vector<string> args = Split(cmdline, " "); |
| 133 | return From(args); |
| 134 | } |
| 135 | |
| 136 | Options Options::From(const vector<string>& args) { |
| 137 | Options::Language lang = Options::Language::JAVA; |
| 138 | int argc = args.size(); |
| 139 | if (argc >= 1 && args.at(0) == "aidl-cpp") { |
| 140 | lang = Options::Language::CPP; |
| 141 | } |
| 142 | const char* argv[argc + 1]; |
| 143 | for (int i = 0; i < argc; i++) { |
| 144 | argv[i] = args.at(i).c_str(); |
| 145 | } |
| 146 | argv[argc] = nullptr; |
| 147 | |
| 148 | return Options(argc, argv, lang); |
| 149 | } |
| 150 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 151 | Options::Options(int argc, const char* const argv[], Options::Language default_lang) |
| 152 | : myname_(argv[0]), language_(default_lang) { |
| 153 | bool lang_option_found = false; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 154 | optind = 0; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 155 | while (true) { |
| 156 | static struct option long_options[] = { |
| 157 | {"lang", required_argument, 0, 'l'}, |
| 158 | {"preprocess", no_argument, 0, 's'}, |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 159 | #ifndef _WIN32 |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 160 | {"dumpapi", no_argument, 0, 'u'}, |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 161 | {"checkapi", no_argument, 0, 'A'}, |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 162 | #endif |
Andrei Onea | 390cb8b | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 163 | {"apimapping", required_argument, 0, 'i'}, |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 164 | {"include", required_argument, 0, 'I'}, |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 165 | {"import", required_argument, 0, 'm'}, |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 166 | {"preprocessed", required_argument, 0, 'p'}, |
| 167 | {"dep", required_argument, 0, 'd'}, |
| 168 | {"out", required_argument, 0, 'o'}, |
| 169 | {"header_out", required_argument, 0, 'h'}, |
| 170 | {"ninja", no_argument, 0, 'n'}, |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 171 | {"structured", no_argument, 0, 'S'}, |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 172 | {"trace", no_argument, 0, 't'}, |
| 173 | {"transaction_names", no_argument, 0, 'c'}, |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 174 | {"version", required_argument, 0, 'v'}, |
Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 175 | {"log", no_argument, 0, 'L'}, |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 176 | {"help", no_argument, 0, 'e'}, |
| 177 | {0, 0, 0, 0}, |
| 178 | }; |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 179 | const int c = getopt_long(argc, const_cast<char* const*>(argv), |
| 180 | "I:m:p:d:o:h:abtv:", long_options, nullptr); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 181 | if (c == -1) { |
| 182 | // no more options |
| 183 | break; |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 184 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 185 | switch (c) { |
| 186 | case 'l': |
| 187 | if (language_ == Options::Language::CPP) { |
| 188 | // aidl-cpp can't set language. aidl-cpp exists only for backwards |
| 189 | // compatibility. |
| 190 | error_message_ << "aidl-cpp does not support --lang." << endl; |
| 191 | return; |
| 192 | } else { |
| 193 | lang_option_found = true; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 194 | string lang = Trim(optarg); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 195 | if (lang == "java") { |
| 196 | language_ = Options::Language::JAVA; |
| 197 | task_ = Options::Task::COMPILE; |
| 198 | } else if (lang == "cpp") { |
| 199 | language_ = Options::Language::CPP; |
| 200 | task_ = Options::Task::COMPILE; |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 201 | } else if (lang == "ndk") { |
| 202 | language_ = Options::Language::NDK; |
| 203 | task_ = Options::Task::COMPILE; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 204 | } else { |
| 205 | error_message_ << "Unsupported language: '" << lang << "'" << endl; |
| 206 | return; |
| 207 | } |
| 208 | } |
| 209 | break; |
| 210 | case 's': |
| 211 | if (task_ != Options::Task::UNSPECIFIED) { |
| 212 | task_ = Options::Task::PREPROCESS; |
| 213 | } |
| 214 | break; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 215 | #ifndef _WIN32 |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 216 | case 'u': |
| 217 | if (task_ != Options::Task::UNSPECIFIED) { |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 218 | task_ = Options::Task::DUMP_API; |
| 219 | } |
| 220 | break; |
| 221 | case 'A': |
| 222 | if (task_ != Options::Task::UNSPECIFIED) { |
| 223 | task_ = Options::Task::CHECK_API; |
| 224 | // to ensure that all parcelables in the api dumpes are structured |
| 225 | structured_ = true; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 226 | } |
| 227 | break; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 228 | #endif |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 229 | case 'I': { |
| 230 | import_dirs_.emplace(Trim(optarg)); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 231 | break; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 232 | } |
| 233 | case 'm': { |
| 234 | import_files_.emplace(Trim(optarg)); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 235 | break; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 236 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 237 | case 'p': |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 238 | preprocessed_files_.emplace_back(Trim(optarg)); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 239 | break; |
| 240 | case 'd': |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 241 | dependency_file_ = Trim(optarg); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 242 | break; |
| 243 | case 'o': |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 244 | output_dir_ = Trim(optarg); |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 245 | if (output_dir_.back() != OS_PATH_SEPARATOR) { |
| 246 | output_dir_.push_back(OS_PATH_SEPARATOR); |
| 247 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 248 | break; |
| 249 | case 'h': |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 250 | output_header_dir_ = Trim(optarg); |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 251 | if (output_header_dir_.back() != OS_PATH_SEPARATOR) { |
| 252 | output_header_dir_.push_back(OS_PATH_SEPARATOR); |
| 253 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 254 | break; |
| 255 | case 'n': |
| 256 | dependency_file_ninja_ = true; |
| 257 | break; |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 258 | case 'S': |
| 259 | structured_ = true; |
| 260 | break; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 261 | case 't': |
| 262 | gen_traces_ = true; |
| 263 | break; |
| 264 | case 'a': |
| 265 | auto_dep_file_ = true; |
| 266 | break; |
| 267 | case 'b': |
| 268 | fail_on_parcelable_ = true; |
| 269 | break; |
| 270 | case 'c': |
| 271 | gen_transaction_names_ = true; |
| 272 | break; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 273 | case 'v': { |
| 274 | const string ver_str = Trim(optarg); |
| 275 | int ver = atoi(ver_str.c_str()); |
| 276 | if (ver > 0) { |
| 277 | version_ = ver; |
| 278 | } else { |
| 279 | error_message_ << "Invalid version number: '" << ver_str << "'. " |
| 280 | << "Version must be a positive natural number." << endl; |
| 281 | return; |
| 282 | } |
| 283 | break; |
| 284 | } |
Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 285 | case 'L': |
| 286 | gen_log_ = true; |
| 287 | break; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 288 | case 'e': |
| 289 | std::cerr << GetUsage(); |
| 290 | exit(0); |
Andrei Onea | 390cb8b | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 291 | case 'i': |
| 292 | output_file_ = Trim(optarg); |
| 293 | task_ = Task::DUMP_MAPPINGS; |
| 294 | break; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 295 | default: |
Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 296 | std::cerr << GetUsage(); |
| 297 | exit(1); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 298 | } |
| 299 | } // while |
| 300 | |
| 301 | // Positional arguments |
| 302 | if (!lang_option_found && task_ == Options::Task::COMPILE) { |
| 303 | // the legacy arguments format |
| 304 | if (argc - optind <= 0) { |
| 305 | error_message_ << "No input file" << endl; |
| 306 | return; |
| 307 | } |
| 308 | if (language_ == Options::Language::JAVA) { |
| 309 | input_files_.emplace_back(argv[optind++]); |
| 310 | if (argc - optind >= 1) { |
| 311 | output_file_ = argv[optind++]; |
| 312 | } else { |
| 313 | // when output is omitted, output is by default set to the input |
| 314 | // file path with .aidl is replaced to .java. |
| 315 | output_file_ = input_files_.front(); |
Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 316 | if (android::base::EndsWith(output_file_, ".aidl")) { |
| 317 | output_file_ = output_file_.substr(0, output_file_.length() - strlen(".aidl")); |
| 318 | } |
| 319 | output_file_ += ".java"; |
| 320 | |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 321 | if (!output_dir_.empty()) { |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 322 | output_file_ = output_dir_ + output_file_; |
Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 323 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 324 | } |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 325 | } else if (IsCppOutput()) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 326 | input_files_.emplace_back(argv[optind++]); |
| 327 | if (argc - optind < 2) { |
| 328 | error_message_ << "No HEADER_DIR or OUTPUT." << endl; |
| 329 | return; |
| 330 | } |
| 331 | output_header_dir_ = argv[optind++]; |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 332 | if (output_header_dir_.back() != OS_PATH_SEPARATOR) { |
| 333 | output_header_dir_.push_back(OS_PATH_SEPARATOR); |
| 334 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 335 | output_file_ = argv[optind++]; |
| 336 | } |
| 337 | if (argc - optind > 0) { |
| 338 | error_message_ << "Too many arguments: "; |
| 339 | for (int i = optind; i < argc; i++) { |
| 340 | error_message_ << " " << argv[i]; |
| 341 | } |
| 342 | error_message_ << endl; |
| 343 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 344 | } else { |
| 345 | // the new arguments format |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 346 | if (task_ == Options::Task::COMPILE || task_ == Options::Task::DUMP_API) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 347 | if (argc - optind < 1) { |
| 348 | error_message_ << "No input file." << endl; |
| 349 | return; |
| 350 | } |
| 351 | } else { |
| 352 | if (argc - optind < 2) { |
| 353 | error_message_ << "Insufficient arguments. At least 2 required, but " |
| 354 | << "got " << (argc - optind) << "." << endl; |
| 355 | return; |
| 356 | } |
Andrei Onea | 390cb8b | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 357 | if (task_ != Options::Task::CHECK_API && task_ != Options::Task::DUMP_MAPPINGS) { |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 358 | output_file_ = argv[optind++]; |
| 359 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 360 | } |
| 361 | while (optind < argc) { |
| 362 | input_files_.emplace_back(argv[optind++]); |
| 363 | } |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 366 | // filter out invalid combinations |
Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 367 | if (lang_option_found) { |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 368 | if (IsCppOutput() && task_ == Options::Task::COMPILE) { |
Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 369 | if (output_dir_.empty()) { |
| 370 | error_message_ << "Output directory is not set. Set with --out." << endl; |
| 371 | return; |
| 372 | } |
| 373 | if (output_header_dir_.empty()) { |
| 374 | error_message_ << "Header output directory is not set. Set with " |
| 375 | << "--header_out." << endl; |
| 376 | return; |
| 377 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 378 | } |
Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 379 | if (language_ == Options::Language::JAVA && task_ == Options::Task::COMPILE) { |
| 380 | if (output_dir_.empty()) { |
| 381 | error_message_ << "Output directory is not set. Set with --out." << endl; |
| 382 | return; |
| 383 | } |
| 384 | if (!output_header_dir_.empty()) { |
| 385 | error_message_ << "Header output directory is set, which does not make " |
| 386 | << "sense for Java." << endl; |
| 387 | return; |
| 388 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | if (task_ == Options::Task::COMPILE) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 392 | for (const string& input : input_files_) { |
| 393 | if (!android::base::EndsWith(input, ".aidl")) { |
| 394 | error_message_ << "Expected .aidl file for input but got '" << input << "'" << endl; |
| 395 | return; |
| 396 | } |
| 397 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 398 | if (!output_file_.empty() && input_files_.size() > 1) { |
| 399 | error_message_ << "Multiple AIDL files can't be compiled to a single " |
| 400 | << "output file '" << output_file_ << "'. " |
| 401 | << "Use --out=DIR instead for output files." << endl; |
| 402 | return; |
| 403 | } |
| 404 | if (!dependency_file_.empty() && input_files_.size() > 1) { |
| 405 | error_message_ << "-d or --dep doesn't work when compiling multiple AIDL " |
| 406 | << "files. Use '-a' to generate dependency file next to " |
| 407 | << "the output file with the name based on the input " |
| 408 | << "file." << endl; |
| 409 | return; |
| 410 | } |
Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 411 | if (gen_log_ && language_ != Options::Language::CPP) { |
| 412 | error_message_ << "--log is currently supported only for --lang=cpp" << endl; |
| 413 | return; |
| 414 | } |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 415 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 416 | if (task_ == Options::Task::PREPROCESS) { |
| 417 | if (version_ > 0) { |
| 418 | error_message_ << "--version should not be used with '--preprocess'." << endl; |
| 419 | return; |
| 420 | } |
| 421 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 422 | if (task_ == Options::Task::CHECK_API) { |
| 423 | if (input_files_.size() != 2) { |
| 424 | error_message_ << "--checkapi requires two inputs for comparing, " |
| 425 | << "but got " << input_files_.size() << "." << endl; |
| 426 | return; |
| 427 | } |
| 428 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 429 | if (task_ == Options::Task::DUMP_API) { |
| 430 | if (output_dir_.empty()) { |
| 431 | error_message_ << "--dump_api requires output directory. Use --out." << endl; |
| 432 | return; |
| 433 | } |
| 434 | } |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 435 | |
| 436 | CHECK(output_dir_.empty() || output_dir_.back() == OS_PATH_SEPARATOR); |
| 437 | CHECK(output_header_dir_.empty() || output_header_dir_.back() == OS_PATH_SEPARATOR); |
Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 440 | } // namespace android |
| 441 | } // namespace aidl |