| 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 |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 99 | << " -v VER, --version=VER" << endl |
| 100 | << " Set the version of the interface and parcelable to VER." << endl |
| 101 | << " VER must be an interger greater than 0." << endl |
| Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 102 | << " --log" << endl |
| 103 | << " Information about the transaction, e.g., method name, argument" << endl |
| 104 | << " values, execution time, etc., is provided via callback." << endl |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 105 | << " --help" << endl |
| 106 | << " Show this help." << endl |
| 107 | << endl |
| 108 | << "INPUT:" << endl |
| 109 | << " An AIDL file." << endl |
| 110 | << endl |
| 111 | << "OUTPUT:" << endl |
| 112 | << " Path to the generated Java or C++ source file. This is ignored when" << endl |
| 113 | << " -o or --out is specified or the number of the input files are" << endl |
| 114 | << " more than one." << endl |
| 115 | << " For Java, if omitted, Java source file is generated at the same" << endl |
| 116 | << " place as the input AIDL file," << endl |
| 117 | << endl |
| Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 118 | << "HEADER_DIR:" << endl |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 119 | << " Path to where C++ headers are generated." << endl; |
| 120 | return sstr.str(); |
| Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 123 | Options Options::From(const string& cmdline) { |
| 124 | vector<string> args = Split(cmdline, " "); |
| 125 | return From(args); |
| 126 | } |
| 127 | |
| 128 | Options Options::From(const vector<string>& args) { |
| 129 | Options::Language lang = Options::Language::JAVA; |
| 130 | int argc = args.size(); |
| 131 | if (argc >= 1 && args.at(0) == "aidl-cpp") { |
| 132 | lang = Options::Language::CPP; |
| 133 | } |
| 134 | const char* argv[argc + 1]; |
| 135 | for (int i = 0; i < argc; i++) { |
| 136 | argv[i] = args.at(i).c_str(); |
| 137 | } |
| 138 | argv[argc] = nullptr; |
| 139 | |
| 140 | return Options(argc, argv, lang); |
| 141 | } |
| 142 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 143 | Options::Options(int argc, const char* const argv[], Options::Language default_lang) |
| 144 | : myname_(argv[0]), language_(default_lang) { |
| 145 | bool lang_option_found = false; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 146 | optind = 0; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 147 | while (true) { |
| 148 | static struct option long_options[] = { |
| 149 | {"lang", required_argument, 0, 'l'}, |
| 150 | {"preprocess", no_argument, 0, 's'}, |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 151 | #ifndef _WIN32 |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 152 | {"dumpapi", no_argument, 0, 'u'}, |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 153 | {"checkapi", no_argument, 0, 'A'}, |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 154 | #endif |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 155 | {"include", required_argument, 0, 'I'}, |
| Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 156 | {"import", required_argument, 0, 'm'}, |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 157 | {"preprocessed", required_argument, 0, 'p'}, |
| 158 | {"dep", required_argument, 0, 'd'}, |
| 159 | {"out", required_argument, 0, 'o'}, |
| 160 | {"header_out", required_argument, 0, 'h'}, |
| 161 | {"ninja", no_argument, 0, 'n'}, |
| Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 162 | {"structured", no_argument, 0, 'S'}, |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 163 | {"trace", no_argument, 0, 't'}, |
| 164 | {"transaction_names", no_argument, 0, 'c'}, |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 165 | {"version", required_argument, 0, 'v'}, |
| Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 166 | {"log", no_argument, 0, 'L'}, |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 167 | {"help", no_argument, 0, 'e'}, |
| 168 | {0, 0, 0, 0}, |
| 169 | }; |
| Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 170 | const int c = getopt_long(argc, const_cast<char* const*>(argv), |
| 171 | "I:m:p:d:o:h:abtv:", long_options, nullptr); |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 172 | if (c == -1) { |
| 173 | // no more options |
| 174 | break; |
| Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 175 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 176 | switch (c) { |
| 177 | case 'l': |
| 178 | if (language_ == Options::Language::CPP) { |
| 179 | // aidl-cpp can't set language. aidl-cpp exists only for backwards |
| 180 | // compatibility. |
| 181 | error_message_ << "aidl-cpp does not support --lang." << endl; |
| 182 | return; |
| 183 | } else { |
| 184 | lang_option_found = true; |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 185 | string lang = Trim(optarg); |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 186 | if (lang == "java") { |
| 187 | language_ = Options::Language::JAVA; |
| 188 | task_ = Options::Task::COMPILE; |
| 189 | } else if (lang == "cpp") { |
| 190 | language_ = Options::Language::CPP; |
| 191 | task_ = Options::Task::COMPILE; |
| Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 192 | } else if (lang == "ndk") { |
| 193 | language_ = Options::Language::NDK; |
| 194 | task_ = Options::Task::COMPILE; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 195 | } else { |
| 196 | error_message_ << "Unsupported language: '" << lang << "'" << endl; |
| 197 | return; |
| 198 | } |
| 199 | } |
| 200 | break; |
| 201 | case 's': |
| 202 | if (task_ != Options::Task::UNSPECIFIED) { |
| 203 | task_ = Options::Task::PREPROCESS; |
| 204 | } |
| 205 | break; |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 206 | #ifndef _WIN32 |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 207 | case 'u': |
| 208 | if (task_ != Options::Task::UNSPECIFIED) { |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 209 | task_ = Options::Task::DUMP_API; |
| 210 | } |
| 211 | break; |
| 212 | case 'A': |
| 213 | if (task_ != Options::Task::UNSPECIFIED) { |
| 214 | task_ = Options::Task::CHECK_API; |
| 215 | // to ensure that all parcelables in the api dumpes are structured |
| 216 | structured_ = true; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 217 | } |
| 218 | break; |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 219 | #endif |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 220 | case 'I': { |
| 221 | import_dirs_.emplace(Trim(optarg)); |
| Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 222 | break; |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 223 | } |
| 224 | case 'm': { |
| 225 | import_files_.emplace(Trim(optarg)); |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 226 | break; |
| Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 227 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 228 | case 'p': |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 229 | preprocessed_files_.emplace_back(Trim(optarg)); |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 230 | break; |
| 231 | case 'd': |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 232 | dependency_file_ = Trim(optarg); |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 233 | break; |
| 234 | case 'o': |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 235 | output_dir_ = Trim(optarg); |
| Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 236 | if (output_dir_.back() != OS_PATH_SEPARATOR) { |
| 237 | output_dir_.push_back(OS_PATH_SEPARATOR); |
| 238 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 239 | break; |
| 240 | case 'h': |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 241 | output_header_dir_ = Trim(optarg); |
| Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 242 | if (output_header_dir_.back() != OS_PATH_SEPARATOR) { |
| 243 | output_header_dir_.push_back(OS_PATH_SEPARATOR); |
| 244 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 245 | break; |
| 246 | case 'n': |
| 247 | dependency_file_ninja_ = true; |
| 248 | break; |
| Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 249 | case 'S': |
| 250 | structured_ = true; |
| 251 | break; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 252 | case 't': |
| 253 | gen_traces_ = true; |
| 254 | break; |
| 255 | case 'a': |
| 256 | auto_dep_file_ = true; |
| 257 | break; |
| 258 | case 'b': |
| 259 | fail_on_parcelable_ = true; |
| 260 | break; |
| 261 | case 'c': |
| 262 | gen_transaction_names_ = true; |
| 263 | break; |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 264 | case 'v': { |
| 265 | const string ver_str = Trim(optarg); |
| 266 | int ver = atoi(ver_str.c_str()); |
| 267 | if (ver > 0) { |
| 268 | version_ = ver; |
| 269 | } else { |
| 270 | error_message_ << "Invalid version number: '" << ver_str << "'. " |
| 271 | << "Version must be a positive natural number." << endl; |
| 272 | return; |
| 273 | } |
| 274 | break; |
| 275 | } |
| Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 276 | case 'L': |
| 277 | gen_log_ = true; |
| 278 | break; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 279 | case 'e': |
| 280 | std::cerr << GetUsage(); |
| 281 | exit(0); |
| 282 | default: |
| Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 283 | std::cerr << GetUsage(); |
| 284 | exit(1); |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 285 | } |
| 286 | } // while |
| 287 | |
| 288 | // Positional arguments |
| 289 | if (!lang_option_found && task_ == Options::Task::COMPILE) { |
| 290 | // the legacy arguments format |
| 291 | if (argc - optind <= 0) { |
| 292 | error_message_ << "No input file" << endl; |
| 293 | return; |
| 294 | } |
| 295 | if (language_ == Options::Language::JAVA) { |
| 296 | input_files_.emplace_back(argv[optind++]); |
| 297 | if (argc - optind >= 1) { |
| 298 | output_file_ = argv[optind++]; |
| 299 | } else { |
| 300 | // when output is omitted, output is by default set to the input |
| 301 | // file path with .aidl is replaced to .java. |
| 302 | output_file_ = input_files_.front(); |
| Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 303 | if (android::base::EndsWith(output_file_, ".aidl")) { |
| 304 | output_file_ = output_file_.substr(0, output_file_.length() - strlen(".aidl")); |
| 305 | } |
| 306 | output_file_ += ".java"; |
| 307 | |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 308 | if (!output_dir_.empty()) { |
| Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 309 | output_file_ = output_dir_ + output_file_; |
| Jiyong Park | 6f77e0c | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 310 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 311 | } |
| Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 312 | } else if (IsCppOutput()) { |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 313 | input_files_.emplace_back(argv[optind++]); |
| 314 | if (argc - optind < 2) { |
| 315 | error_message_ << "No HEADER_DIR or OUTPUT." << endl; |
| 316 | return; |
| 317 | } |
| 318 | output_header_dir_ = argv[optind++]; |
| Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 319 | if (output_header_dir_.back() != OS_PATH_SEPARATOR) { |
| 320 | output_header_dir_.push_back(OS_PATH_SEPARATOR); |
| 321 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 322 | output_file_ = argv[optind++]; |
| 323 | } |
| 324 | if (argc - optind > 0) { |
| 325 | error_message_ << "Too many arguments: "; |
| 326 | for (int i = optind; i < argc; i++) { |
| 327 | error_message_ << " " << argv[i]; |
| 328 | } |
| 329 | error_message_ << endl; |
| 330 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 331 | } else { |
| 332 | // the new arguments format |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 333 | if (task_ == Options::Task::COMPILE || task_ == Options::Task::DUMP_API) { |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 334 | if (argc - optind < 1) { |
| 335 | error_message_ << "No input file." << endl; |
| 336 | return; |
| 337 | } |
| 338 | } else { |
| 339 | if (argc - optind < 2) { |
| 340 | error_message_ << "Insufficient arguments. At least 2 required, but " |
| 341 | << "got " << (argc - optind) << "." << endl; |
| 342 | return; |
| 343 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 344 | if (task_ != Options::Task::CHECK_API) { |
| 345 | output_file_ = argv[optind++]; |
| 346 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 347 | } |
| 348 | while (optind < argc) { |
| 349 | input_files_.emplace_back(argv[optind++]); |
| 350 | } |
| Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 353 | // filter out invalid combinations |
| Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 354 | if (lang_option_found) { |
| Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 355 | if (IsCppOutput() && task_ == Options::Task::COMPILE) { |
| Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 356 | if (output_dir_.empty()) { |
| 357 | error_message_ << "Output directory is not set. Set with --out." << endl; |
| 358 | return; |
| 359 | } |
| 360 | if (output_header_dir_.empty()) { |
| 361 | error_message_ << "Header output directory is not set. Set with " |
| 362 | << "--header_out." << endl; |
| 363 | return; |
| 364 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 365 | } |
| Steven Moreland | 4dbadf5 | 2018-08-08 17:46:10 -0700 | [diff] [blame] | 366 | if (language_ == Options::Language::JAVA && task_ == Options::Task::COMPILE) { |
| 367 | if (output_dir_.empty()) { |
| 368 | error_message_ << "Output directory is not set. Set with --out." << endl; |
| 369 | return; |
| 370 | } |
| 371 | if (!output_header_dir_.empty()) { |
| 372 | error_message_ << "Header output directory is set, which does not make " |
| 373 | << "sense for Java." << endl; |
| 374 | return; |
| 375 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | if (task_ == Options::Task::COMPILE) { |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 379 | for (const string& input : input_files_) { |
| 380 | if (!android::base::EndsWith(input, ".aidl")) { |
| 381 | error_message_ << "Expected .aidl file for input but got '" << input << "'" << endl; |
| 382 | return; |
| 383 | } |
| 384 | } |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 385 | if (!output_file_.empty() && input_files_.size() > 1) { |
| 386 | error_message_ << "Multiple AIDL files can't be compiled to a single " |
| 387 | << "output file '" << output_file_ << "'. " |
| 388 | << "Use --out=DIR instead for output files." << endl; |
| 389 | return; |
| 390 | } |
| 391 | if (!dependency_file_.empty() && input_files_.size() > 1) { |
| 392 | error_message_ << "-d or --dep doesn't work when compiling multiple AIDL " |
| 393 | << "files. Use '-a' to generate dependency file next to " |
| 394 | << "the output file with the name based on the input " |
| 395 | << "file." << endl; |
| 396 | return; |
| 397 | } |
| Jiyong Park | ce50e26 | 2018-10-29 09:54:20 +0900 | [diff] [blame] | 398 | if (gen_log_ && language_ != Options::Language::CPP) { |
| 399 | error_message_ << "--log is currently supported only for --lang=cpp" << endl; |
| 400 | return; |
| 401 | } |
| Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 402 | } |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 403 | if (task_ == Options::Task::PREPROCESS) { |
| 404 | if (version_ > 0) { |
| 405 | error_message_ << "--version should not be used with '--preprocess'." << endl; |
| 406 | return; |
| 407 | } |
| 408 | } |
| Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 409 | if (task_ == Options::Task::CHECK_API) { |
| 410 | if (input_files_.size() != 2) { |
| 411 | error_message_ << "--checkapi requires two inputs for comparing, " |
| 412 | << "but got " << input_files_.size() << "." << endl; |
| 413 | return; |
| 414 | } |
| 415 | } |
| Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 416 | if (task_ == Options::Task::DUMP_API) { |
| 417 | if (output_dir_.empty()) { |
| 418 | error_message_ << "--dump_api requires output directory. Use --out." << endl; |
| 419 | return; |
| 420 | } |
| 421 | } |
| Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 422 | |
| 423 | CHECK(output_dir_.empty() || output_dir_.back() == OS_PATH_SEPARATOR); |
| 424 | CHECK(output_header_dir_.empty() || output_header_dir_.back() == OS_PATH_SEPARATOR); |
| Christopher Wiley | a590de8 | 2015-09-15 15:46:28 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| Christopher Wiley | 4427d86 | 2015-09-14 11:07:39 -0700 | [diff] [blame] | 427 | } // namespace android |
| 428 | } // namespace aidl |