Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -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 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 17 | #include "aidl.h" |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 18 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 19 | #include <fcntl.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 23 | #include <sys/param.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <unistd.h> |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 26 | #include <algorithm> |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 27 | #include <iostream> |
| 28 | #include <map> |
| 29 | #include <memory> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 30 | |
Elliott Hughes | 549b6e2 | 2015-08-17 12:41:46 -0700 | [diff] [blame] | 31 | #ifdef _WIN32 |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 32 | #include <io.h> |
Andrew Hsieh | 15ce994 | 2014-05-07 20:14:30 +0800 | [diff] [blame] | 33 | #include <direct.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 34 | #include <sys/stat.h> |
| 35 | #endif |
| 36 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 37 | #include <android-base/strings.h> |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 38 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 39 | #include "aidl_language.h" |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 40 | #include "aidl_typenames.h" |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 41 | #include "generate_aidl_mappings.h" |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 42 | #include "generate_cpp.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 43 | #include "generate_java.h" |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 44 | #include "generate_ndk.h" |
Christopher Wiley | 72877ac | 2015-10-06 14:41:42 -0700 | [diff] [blame] | 45 | #include "import_resolver.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 46 | #include "logging.h" |
| 47 | #include "options.h" |
| 48 | #include "os.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 49 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 50 | #ifndef O_BINARY |
| 51 | # define O_BINARY 0 |
| 52 | #endif |
| 53 | |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 54 | using android::base::Join; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 55 | using android::base::Split; |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 56 | using std::cerr; |
| 57 | using std::endl; |
Christopher Wiley | 9f4c7ae | 2015-08-24 14:07:32 -0700 | [diff] [blame] | 58 | using std::set; |
| 59 | using std::string; |
Christopher Wiley | 84c1eac | 2015-09-23 13:29:28 -0700 | [diff] [blame] | 60 | using std::unique_ptr; |
Christopher Wiley | 9f4c7ae | 2015-08-24 14:07:32 -0700 | [diff] [blame] | 61 | using std::vector; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 62 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 63 | namespace android { |
| 64 | namespace aidl { |
| 65 | namespace { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 66 | |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 67 | // Copied from android.is.IBinder.[FIRST|LAST]_CALL_TRANSACTION |
| 68 | const int kFirstCallTransaction = 1; |
| 69 | const int kLastCallTransaction = 0x00ffffff; |
| 70 | |
| 71 | // Following IDs are all offsets from kFirstCallTransaction |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 72 | |
| 73 | // IDs for meta transactions. Most of the meta transactions are implemented in |
| 74 | // the framework side (Binder.java or Binder.cpp). But these are the ones that |
| 75 | // are auto-implemented by the AIDL compiler. |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 76 | const int kFirstMetaMethodId = kLastCallTransaction - kFirstCallTransaction; |
| 77 | const int kGetInterfaceVersionId = kFirstMetaMethodId; |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 78 | const int kGetInterfaceHashId = kFirstMetaMethodId - 1; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 79 | // Additional meta transactions implemented by AIDL should use |
| 80 | // kFirstMetaMethodId -1, -2, ...and so on. |
| 81 | |
| 82 | // Reserve 100 IDs for meta methods, which is more than enough. If we don't reserve, |
| 83 | // in the future, a newly added meta transaction ID will have a chance to |
| 84 | // collide with the user-defined methods that were added in the past. So, |
| 85 | // let's prevent users from using IDs in this range from the beginning. |
| 86 | const int kLastMetaMethodId = kFirstMetaMethodId - 99; |
| 87 | |
| 88 | // Range of IDs that is allowed for user-defined methods. |
| 89 | const int kMinUserSetMethodId = 0; |
| 90 | const int kMaxUserSetMethodId = kLastMetaMethodId - 1; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 91 | |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 92 | bool check_filename(const std::string& filename, const AidlDefinedType& defined_type) { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 93 | const char* p; |
| 94 | string expected; |
| 95 | string fn; |
| 96 | size_t len; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 97 | bool valid = false; |
| 98 | |
Christopher Wiley | bc2df69 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 99 | if (!IoDelegate::GetAbsolutePath(filename, &fn)) { |
| 100 | return false; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 103 | const std::string package = defined_type.GetPackage(); |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 104 | if (!package.empty()) { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 105 | expected = package; |
| 106 | expected += '.'; |
| 107 | } |
| 108 | |
| 109 | len = expected.length(); |
| 110 | for (size_t i=0; i<len; i++) { |
| 111 | if (expected[i] == '.') { |
| 112 | expected[i] = OS_PATH_SEPARATOR; |
| 113 | } |
| 114 | } |
| 115 | |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 116 | const std::string name = defined_type.GetName(); |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 117 | expected.append(name, 0, name.find('.')); |
Christopher Wiley | 8f8cc9b | 2015-09-14 13:47:40 -0700 | [diff] [blame] | 118 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 119 | expected += ".aidl"; |
| 120 | |
| 121 | len = fn.length(); |
| 122 | valid = (len >= expected.length()); |
| 123 | |
| 124 | if (valid) { |
| 125 | p = fn.c_str() + (len - expected.length()); |
| 126 | |
Elliott Hughes | ce310da | 2015-07-29 08:44:17 -0700 | [diff] [blame] | 127 | #ifdef _WIN32 |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 128 | if (OS_PATH_SEPARATOR != '/') { |
| 129 | // Input filename under cygwin most likely has / separators |
| 130 | // whereas the expected string uses \\ separators. Adjust |
| 131 | // them accordingly. |
| 132 | for (char *c = const_cast<char *>(p); *c; ++c) { |
| 133 | if (*c == '/') *c = OS_PATH_SEPARATOR; |
| 134 | } |
| 135 | } |
| 136 | #endif |
| 137 | |
Yabin Cui | 482eefb | 2014-11-10 15:01:43 -0800 | [diff] [blame] | 138 | // aidl assumes case-insensitivity on Mac Os and Windows. |
| 139 | #if defined(__linux__) |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 140 | valid = (expected == p); |
| 141 | #else |
| 142 | valid = !strcasecmp(expected.c_str(), p); |
| 143 | #endif |
| 144 | } |
| 145 | |
| 146 | if (!valid) { |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 147 | AIDL_ERROR(defined_type) << name << " should be declared in a file called " << expected; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Casey Dahlin | 42727f8 | 2015-10-12 19:23:40 -0700 | [diff] [blame] | 150 | return valid; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 153 | bool write_dep_file(const Options& options, const AidlDefinedType& defined_type, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 154 | const vector<string>& imports, const IoDelegate& io_delegate, |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 155 | const string& input_file, const string& output_file) { |
| 156 | string dep_file_name = options.DependencyFile(); |
| 157 | if (dep_file_name.empty() && options.AutoDepFile()) { |
| 158 | dep_file_name = output_file + ".d"; |
| 159 | } |
| 160 | |
| 161 | if (dep_file_name.empty()) { |
| 162 | return true; // nothing to do |
| 163 | } |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 164 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 165 | CodeWriterPtr writer = io_delegate.GetCodeWriter(dep_file_name); |
| 166 | if (!writer) { |
| 167 | LOG(ERROR) << "Could not open dependency file: " << dep_file_name; |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | vector<string> source_aidl = {input_file}; |
| 172 | for (const auto& import : imports) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 173 | source_aidl.push_back(import); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 174 | } |
| 175 | |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 176 | // Encode that the output file depends on aidl input files. |
Jiyong Park | df20212 | 2019-09-30 20:48:35 +0900 | [diff] [blame] | 177 | if (defined_type.AsUnstructuredParcelable() != nullptr && |
| 178 | options.TargetLanguage() == Options::Language::JAVA) { |
| 179 | // Legacy behavior. For parcelable declarations in Java, don't emit output file as |
| 180 | // the dependency target. b/141372861 |
| 181 | writer->Write(" : \\\n"); |
| 182 | } else { |
| 183 | writer->Write("%s : \\\n", output_file.c_str()); |
| 184 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 185 | writer->Write(" %s", Join(source_aidl, " \\\n ").c_str()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 186 | writer->Write("\n"); |
Christopher Wiley | a30a45e | 2015-10-17 10:56:59 -0700 | [diff] [blame] | 187 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 188 | if (!options.DependencyFileNinja()) { |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 189 | writer->Write("\n"); |
| 190 | // Output "<input_aidl_file>: " so make won't fail if the input .aidl file |
| 191 | // has been deleted, moved or renamed in incremental build. |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 192 | for (const auto& src : source_aidl) { |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 193 | writer->Write("%s :\n", src.c_str()); |
| 194 | } |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 195 | } |
Christopher Wiley | a30a45e | 2015-10-17 10:56:59 -0700 | [diff] [blame] | 196 | |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 197 | if (options.IsCppOutput()) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 198 | if (!options.DependencyFileNinja()) { |
| 199 | using ::android::aidl::cpp::ClassNames; |
| 200 | using ::android::aidl::cpp::HeaderFile; |
| 201 | vector<string> headers; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 202 | for (ClassNames c : {ClassNames::CLIENT, ClassNames::SERVER, ClassNames::RAW}) { |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 203 | headers.push_back(options.OutputHeaderDir() + |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 204 | HeaderFile(defined_type, c, false /* use_os_sep */)); |
| 205 | } |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 206 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 207 | writer->Write("\n"); |
| 208 | |
| 209 | // Generated headers also depend on the source aidl files. |
| 210 | writer->Write("%s : \\\n %s\n", Join(headers, " \\\n ").c_str(), |
| 211 | Join(source_aidl, " \\\n ").c_str()); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 212 | } |
Christopher Wiley | a30a45e | 2015-10-17 10:56:59 -0700 | [diff] [blame] | 213 | } |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 214 | |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 215 | return true; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 218 | string generate_outputFileName(const Options& options, const AidlDefinedType& defined_type) { |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 219 | // create the path to the destination folder based on the |
| 220 | // defined_type package name |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 221 | string result = options.OutputDir(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 222 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 223 | string package = defined_type.GetPackage(); |
| 224 | size_t len = package.length(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 225 | for (size_t i = 0; i < len; i++) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 226 | if (package[i] == '.') { |
| 227 | package[i] = OS_PATH_SEPARATOR; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 228 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 229 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 230 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 231 | result += package; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 232 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 233 | // add the filename by replacing the .aidl extension to .java |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 234 | const string& name = defined_type.GetName(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 235 | result += OS_PATH_SEPARATOR; |
| 236 | result.append(name, 0, name.find('.')); |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 237 | if (options.TargetLanguage() == Options::Language::JAVA) { |
| 238 | result += ".java"; |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 239 | } else if (options.IsCppOutput()) { |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 240 | result += ".cpp"; |
| 241 | } else { |
| 242 | LOG(FATAL) << "Should not reach here" << endl; |
| 243 | return ""; |
| 244 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 245 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 246 | return result; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 249 | bool check_and_assign_method_ids(const std::vector<std::unique_ptr<AidlMethod>>& items) { |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 250 | // Check whether there are any methods with manually assigned id's and any |
| 251 | // that are not. Either all method id's must be manually assigned or all of |
| 252 | // them must not. Also, check for uplicates of user set ID's and that the |
| 253 | // ID's are within the proper bounds. |
| 254 | set<int> usedIds; |
| 255 | bool hasUnassignedIds = false; |
| 256 | bool hasAssignedIds = false; |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame] | 257 | int newId = kMinUserSetMethodId; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 258 | for (const auto& item : items) { |
| 259 | // However, meta transactions that are added by the AIDL compiler are |
| 260 | // exceptions. They have fixed IDs but allowed to be with user-defined |
| 261 | // methods having auto-assigned IDs. This is because the Ids of the meta |
| 262 | // transactions must be stable during the entire lifetime of an interface. |
| 263 | // In other words, their IDs must be the same even when new user-defined |
| 264 | // methods are added. |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 265 | if (!item->IsUserDefined()) { |
| 266 | continue; |
| 267 | } |
| 268 | if (item->HasId()) { |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 269 | hasAssignedIds = true; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 270 | } else { |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame] | 271 | item->SetId(newId++); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 272 | hasUnassignedIds = true; |
| 273 | } |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame] | 274 | |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 275 | if (hasAssignedIds && hasUnassignedIds) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 276 | AIDL_ERROR(item) << "You must either assign id's to all methods or to none of them."; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 277 | return false; |
| 278 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 279 | |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame] | 280 | // Ensure that the user set id is not duplicated. |
| 281 | if (usedIds.find(item->GetId()) != usedIds.end()) { |
| 282 | // We found a duplicate id, so throw an error. |
| 283 | AIDL_ERROR(item) << "Found duplicate method id (" << item->GetId() << ") for method " |
| 284 | << item->GetName(); |
| 285 | return false; |
| 286 | } |
| 287 | usedIds.insert(item->GetId()); |
| 288 | |
| 289 | // Ensure that the user set id is within the appropriate limits |
| 290 | if (item->GetId() < kMinUserSetMethodId || item->GetId() > kMaxUserSetMethodId) { |
| 291 | AIDL_ERROR(item) << "Found out of bounds id (" << item->GetId() << ") for method " |
| 292 | << item->GetName() << ". Value for id must be between " |
| 293 | << kMinUserSetMethodId << " and " << kMaxUserSetMethodId << " inclusive."; |
| 294 | return false; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 295 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 296 | } |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame] | 297 | |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 298 | return true; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 301 | // TODO: Remove this in favor of using the YACC parser b/25479378 |
| 302 | bool ParsePreprocessedLine(const string& line, string* decl, |
| 303 | vector<string>* package, string* class_name) { |
| 304 | // erase all trailing whitespace and semicolons |
| 305 | const size_t end = line.find_last_not_of(" ;\t"); |
| 306 | if (end == string::npos) { |
| 307 | return false; |
| 308 | } |
| 309 | if (line.rfind(';', end) != string::npos) { |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | decl->clear(); |
| 314 | string type; |
| 315 | vector<string> pieces = Split(line.substr(0, end + 1), " \t"); |
| 316 | for (const string& piece : pieces) { |
| 317 | if (piece.empty()) { |
| 318 | continue; |
| 319 | } |
| 320 | if (decl->empty()) { |
| 321 | *decl = std::move(piece); |
| 322 | } else if (type.empty()) { |
| 323 | type = std::move(piece); |
| 324 | } else { |
| 325 | return false; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Note that this logic is absolutely wrong. Given a parcelable |
| 330 | // org.some.Foo.Bar, the class name is Foo.Bar, but this code will claim that |
| 331 | // the class is just Bar. However, this was the way it was done in the past. |
| 332 | // |
| 333 | // See b/17415692 |
| 334 | size_t dot_pos = type.rfind('.'); |
| 335 | if (dot_pos != string::npos) { |
| 336 | *class_name = type.substr(dot_pos + 1); |
| 337 | *package = Split(type.substr(0, dot_pos), "."); |
| 338 | } else { |
| 339 | *class_name = type; |
| 340 | package->clear(); |
| 341 | } |
| 342 | |
| 343 | return true; |
| 344 | } |
| 345 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 346 | } // namespace |
| 347 | |
| 348 | namespace internals { |
| 349 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 350 | bool parse_preprocessed_file(const IoDelegate& io_delegate, const string& filename, |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 351 | AidlTypenames* typenames) { |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 352 | bool success = true; |
| 353 | unique_ptr<LineReader> line_reader = io_delegate.GetLineReader(filename); |
| 354 | if (!line_reader) { |
| 355 | LOG(ERROR) << "cannot open preprocessed file: " << filename; |
| 356 | success = false; |
| 357 | return success; |
| 358 | } |
| 359 | |
| 360 | string line; |
Dan Willemsen | 609ba6d | 2019-12-30 10:44:00 -0800 | [diff] [blame] | 361 | int lineno = 1; |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 362 | for ( ; line_reader->ReadLine(&line); ++lineno) { |
| 363 | if (line.empty() || line.compare(0, 2, "//") == 0) { |
| 364 | // skip comments and empty lines |
| 365 | continue; |
| 366 | } |
| 367 | |
| 368 | string decl; |
| 369 | vector<string> package; |
| 370 | string class_name; |
| 371 | if (!ParsePreprocessedLine(line, &decl, &package, &class_name)) { |
| 372 | success = false; |
| 373 | break; |
| 374 | } |
| 375 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 376 | AidlLocation::Point point = {.line = lineno, .column = 0 /*column*/}; |
| 377 | AidlLocation location = AidlLocation(filename, point, point); |
| 378 | |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 379 | if (decl == "parcelable") { |
Jeongik Cha | ce58bc6 | 2019-04-22 13:30:39 +0900 | [diff] [blame] | 380 | // ParcelFileDescriptor is treated as a built-in type, but it's also in the framework.aidl. |
| 381 | // So aidl should ignore built-in types in framework.aidl to prevent duplication. |
| 382 | // (b/130899491) |
| 383 | if (AidlTypenames::IsBuiltinTypename(class_name)) { |
| 384 | continue; |
| 385 | } |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 386 | AidlParcelable* doc = new AidlParcelable( |
| 387 | location, new AidlQualifiedName(location, class_name, ""), package, "" /* comments */); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 388 | typenames->AddPreprocessedType(unique_ptr<AidlParcelable>(doc)); |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 389 | } else if (decl == "structured_parcelable") { |
| 390 | auto temp = new std::vector<std::unique_ptr<AidlVariableDeclaration>>(); |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 391 | AidlStructuredParcelable* doc = |
| 392 | new AidlStructuredParcelable(location, new AidlQualifiedName(location, class_name, ""), |
| 393 | package, "" /* comments */, temp); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 394 | typenames->AddPreprocessedType(unique_ptr<AidlStructuredParcelable>(doc)); |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 395 | } else if (decl == "interface") { |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 396 | auto temp = new std::vector<std::unique_ptr<AidlMember>>(); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 397 | AidlInterface* doc = new AidlInterface(location, class_name, "", false, temp, package); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 398 | typenames->AddPreprocessedType(unique_ptr<AidlInterface>(doc)); |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 399 | } else { |
| 400 | success = false; |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | if (!success) { |
| 405 | LOG(ERROR) << filename << ':' << lineno |
| 406 | << " malformed preprocessed file line: '" << line << "'"; |
| 407 | } |
| 408 | |
| 409 | return success; |
| 410 | } |
| 411 | |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 412 | AidlError load_and_validate_aidl(const std::string& input_file_name, const Options& options, |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 413 | const IoDelegate& io_delegate, AidlTypenames* typenames, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 414 | vector<AidlDefinedType*>* defined_types, |
| 415 | vector<string>* imported_files) { |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 416 | AidlError err = AidlError::OK; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 417 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 418 | ////////////////////////////////////////////////////////////////////////// |
| 419 | // Loading phase |
| 420 | ////////////////////////////////////////////////////////////////////////// |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 421 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 422 | // Parse the main input file |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 423 | std::unique_ptr<Parser> main_parser = Parser::Parse(input_file_name, io_delegate, *typenames); |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 424 | if (main_parser == nullptr) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 425 | return AidlError::PARSE_ERROR; |
| 426 | } |
Jiyong Park | da8c693 | 2019-08-12 19:56:08 +0900 | [diff] [blame] | 427 | int num_interfaces_or_structured_parcelables = 0; |
| 428 | for (AidlDefinedType* type : main_parser->GetDefinedTypes()) { |
| 429 | if (type->AsInterface() != nullptr || type->AsStructuredParcelable() != nullptr) { |
| 430 | num_interfaces_or_structured_parcelables++; |
| 431 | } |
| 432 | } |
| 433 | if (num_interfaces_or_structured_parcelables > 1) { |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 434 | AIDL_ERROR(input_file_name) << "You must declare only one type per a file."; |
| 435 | return AidlError::BAD_TYPE; |
| 436 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 437 | |
| 438 | // Import the preprocessed file |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 439 | for (const string& s : options.PreprocessedFiles()) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 440 | if (!parse_preprocessed_file(io_delegate, s, typenames)) { |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 441 | err = AidlError::BAD_PRE_PROCESSED_FILE; |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 442 | } |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 443 | } |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 444 | if (err != AidlError::OK) { |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 445 | return err; |
| 446 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 447 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 448 | // Find files to import and parse them |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 449 | vector<string> import_paths; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 450 | ImportResolver import_resolver{io_delegate, input_file_name, options.ImportDirs(), |
| 451 | options.InputFiles()}; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 452 | |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 453 | vector<string> type_from_import_statements; |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 454 | for (const auto& import : main_parser->GetImports()) { |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 455 | if (!AidlTypenames::IsBuiltinTypename(import->GetNeededClass())) { |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 456 | type_from_import_statements.emplace_back(import->GetNeededClass()); |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 457 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // When referencing a type using fully qualified name it should be imported |
| 461 | // without the import statement. To support that, add all unresolved |
| 462 | // typespecs encountered during the parsing to the import_candidates list. |
| 463 | // Note that there is no guarantee that the typespecs are all fully qualified. |
| 464 | // It will be determined by calling FindImportFile(). |
| 465 | set<string> unresolved_types; |
| 466 | for (const auto type : main_parser->GetUnresolvedTypespecs()) { |
| 467 | if (!AidlTypenames::IsBuiltinTypename(type->GetName())) { |
| 468 | unresolved_types.emplace(type->GetName()); |
| 469 | } |
| 470 | } |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 471 | vector<string> import_candidates(type_from_import_statements); |
| 472 | import_candidates.insert(import_candidates.end(), unresolved_types.begin(), |
| 473 | unresolved_types.end()); |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 474 | for (const auto& import : import_candidates) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 475 | if (typenames->IsIgnorableImport(import)) { |
Christopher Wiley | fb4b22d | 2015-09-25 15:16:13 -0700 | [diff] [blame] | 476 | // There are places in the Android tree where an import doesn't resolve, |
| 477 | // but we'll pick the type up through the preprocessed types. |
| 478 | // This seems like an error, but legacy support demands we support it... |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 479 | continue; |
| 480 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 481 | string import_path = import_resolver.FindImportFile(import); |
Christopher Wiley | 72877ac | 2015-10-06 14:41:42 -0700 | [diff] [blame] | 482 | if (import_path.empty()) { |
Jiyong Park | 8f6ec46 | 2020-01-19 20:52:47 +0900 | [diff] [blame] | 483 | if (typenames->ResolveTypename(import).second) { |
| 484 | // Couldn't find the *.aidl file for the type from the include paths, but we |
| 485 | // have the type already resolved. This could happen when the type is |
| 486 | // from the preprocessed aidl file. In that case, use the type from the |
| 487 | // preprocessed aidl file as a last resort. |
| 488 | continue; |
| 489 | } |
| 490 | |
| 491 | if (std::find(type_from_import_statements.begin(), type_from_import_statements.end(), |
| 492 | import) != type_from_import_statements.end()) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 493 | // Complain only when the import from the import statement has failed. |
| 494 | AIDL_ERROR(import) << "couldn't find import for class " << import; |
| 495 | err = AidlError::BAD_IMPORT; |
| 496 | } |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 497 | continue; |
| 498 | } |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 499 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 500 | import_paths.emplace_back(import_path); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 501 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 502 | std::unique_ptr<Parser> import_parser = Parser::Parse(import_path, io_delegate, *typenames); |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 503 | if (import_parser == nullptr) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 504 | cerr << "error while importing " << import_path << " for " << import << endl; |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 505 | err = AidlError::BAD_IMPORT; |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 506 | continue; |
| 507 | } |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 508 | } |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 509 | if (err != AidlError::OK) { |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 510 | return err; |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 511 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 512 | |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 513 | for (const auto& imported_file : options.ImportFiles()) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 514 | import_paths.emplace_back(imported_file); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 515 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 516 | std::unique_ptr<Parser> import_parser = Parser::Parse(imported_file, io_delegate, *typenames); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 517 | if (import_parser == nullptr) { |
| 518 | AIDL_ERROR(imported_file) << "error while importing " << imported_file; |
| 519 | err = AidlError::BAD_IMPORT; |
| 520 | continue; |
| 521 | } |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 522 | } |
| 523 | if (err != AidlError::OK) { |
| 524 | return err; |
| 525 | } |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 526 | const bool is_check_api = options.GetTask() == Options::Task::CHECK_API; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 527 | |
| 528 | // Resolve the unresolved type references found from the input file |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 529 | if (!is_check_api && !main_parser->Resolve()) { |
| 530 | // Resolution is not need for check api because all typespecs are |
| 531 | // using fully qualified names. |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 532 | return AidlError::BAD_TYPE; |
| 533 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 534 | |
| 535 | typenames->IterateTypes([&](const AidlDefinedType& type) { |
| 536 | AidlEnumDeclaration* enum_decl = const_cast<AidlEnumDeclaration*>(type.AsEnumDeclaration()); |
| 537 | if (enum_decl != nullptr) { |
| 538 | // BackingType is filled in for all known enums, including imported enums, |
| 539 | // because other types that may use enums, such as Interface or |
| 540 | // StructuredParcelable, need to know the enum BackingType when |
| 541 | // generating code. |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 542 | if (auto backing_type = enum_decl->BackingType(*typenames); backing_type != nullptr) { |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 543 | enum_decl->SetBackingType(std::unique_ptr<const AidlTypeSpecifier>(backing_type)); |
| 544 | } else { |
| 545 | // Default to byte type for enums. |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 546 | auto byte_type = |
| 547 | std::make_unique<AidlTypeSpecifier>(AIDL_LOCATION_HERE, "byte", false, nullptr, ""); |
| 548 | byte_type->Resolve(*typenames); |
| 549 | enum_decl->SetBackingType(std::move(byte_type)); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Steven Moreland | 59e53e4 | 2019-11-26 20:38:08 -0800 | [diff] [blame] | 552 | if (!enum_decl->Autofill()) { |
| 553 | err = AidlError::BAD_TYPE; |
| 554 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 555 | } |
| 556 | }); |
Steven Moreland | 59e53e4 | 2019-11-26 20:38:08 -0800 | [diff] [blame] | 557 | if (err != AidlError::OK) { |
| 558 | return err; |
| 559 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 560 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 561 | ////////////////////////////////////////////////////////////////////////// |
| 562 | // Validation phase |
| 563 | ////////////////////////////////////////////////////////////////////////// |
| 564 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 565 | // For legacy reasons, by default, compiling an unstructured parcelable (which contains no output) |
| 566 | // is allowed. This must not be returned as an error until the very end of this procedure since |
| 567 | // this may be considered a success, and we should first check that there are not other, more |
| 568 | // serious failures. |
| 569 | bool contains_unstructured_parcelable = false; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 570 | |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 571 | const int num_defined_types = main_parser->GetDefinedTypes().size(); |
| 572 | for (const auto defined_type : main_parser->GetDefinedTypes()) { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 573 | CHECK(defined_type != nullptr); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 574 | |
| 575 | // Language specific validation |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 576 | if (!defined_type->LanguageSpecificCheckValid(options.TargetLanguage())) { |
| 577 | return AidlError::BAD_TYPE; |
| 578 | } |
| 579 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 580 | AidlParcelable* unstructuredParcelable = defined_type->AsUnstructuredParcelable(); |
| 581 | if (unstructuredParcelable != nullptr) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 582 | if (!unstructuredParcelable->CheckValid(*typenames)) { |
Jeongik Cha | 82317dd | 2019-02-27 20:26:11 +0900 | [diff] [blame] | 583 | return AidlError::BAD_TYPE; |
| 584 | } |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 585 | bool isStable = unstructuredParcelable->IsStableApiParcelable(options.TargetLanguage()); |
Jeongik Cha | 82317dd | 2019-02-27 20:26:11 +0900 | [diff] [blame] | 586 | if (options.IsStructured() && !isStable) { |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 587 | AIDL_ERROR(unstructuredParcelable) |
| 588 | << "Cannot declared parcelable in a --structured interface. Parcelable must be defined " |
| 589 | "in AIDL directly."; |
| 590 | return AidlError::NOT_STRUCTURED; |
| 591 | } |
| 592 | if (options.FailOnParcelable()) { |
| 593 | AIDL_ERROR(unstructuredParcelable) |
| 594 | << "Refusing to generate code with unstructured parcelables. Declared parcelables " |
| 595 | "should be in their own file and/or cannot be used with --structured interfaces."; |
| 596 | // Continue parsing for more errors |
| 597 | } |
| 598 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 599 | contains_unstructured_parcelable = true; |
| 600 | continue; |
| 601 | } |
| 602 | |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 603 | if (defined_type->IsVintfStability() && |
| 604 | (options.GetStability() != Options::Stability::VINTF || !options.IsStructured())) { |
| 605 | AIDL_ERROR(defined_type) |
| 606 | << "Must compile @VintfStability type w/ aidl_interface 'stability: \"vintf\"'"; |
| 607 | return AidlError::NOT_STRUCTURED; |
| 608 | } |
| 609 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 610 | // Ensure that a type is either an interface, structured parcelable, or |
| 611 | // enum. |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 612 | AidlInterface* interface = defined_type->AsInterface(); |
| 613 | AidlStructuredParcelable* parcelable = defined_type->AsStructuredParcelable(); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 614 | AidlEnumDeclaration* enum_decl = defined_type->AsEnumDeclaration(); |
| 615 | CHECK(!!interface + !!parcelable + !!enum_decl == 1); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 616 | |
| 617 | // Ensure that foo.bar.IFoo is defined in <some_path>/foo/bar/IFoo.aidl |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 618 | if (num_defined_types == 1 && !check_filename(input_file_name, *defined_type)) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 619 | return AidlError::BAD_PACKAGE; |
| 620 | } |
| 621 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 622 | // Check the referenced types in parsed_doc to make sure we've imported them |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 623 | if (!is_check_api) { |
| 624 | // No need to do this for check api because all typespecs are already |
| 625 | // using fully qualified name and we don't import in AIDL files. |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 626 | if (!defined_type->CheckValid(*typenames)) { |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 627 | return AidlError::BAD_TYPE; |
| 628 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | if (interface != nullptr) { |
| 632 | // add the meta-method 'int getInterfaceVersion()' if version is specified. |
| 633 | if (options.Version() > 0) { |
| 634 | AidlTypeSpecifier* ret = |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 635 | new AidlTypeSpecifier(AIDL_LOCATION_HERE, "int", false, nullptr, ""); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 636 | ret->Resolve(*typenames); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 637 | vector<unique_ptr<AidlArgument>>* args = new vector<unique_ptr<AidlArgument>>(); |
| 638 | AidlMethod* method = |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 639 | new AidlMethod(AIDL_LOCATION_HERE, false, ret, "getInterfaceVersion", args, "", |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 640 | kGetInterfaceVersionId, false /* is_user_defined */); |
| 641 | interface->GetMutableMethods().emplace_back(method); |
| 642 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 643 | // add the meta-method 'string getInterfaceHash()' if hash is specified. |
| 644 | if (!options.Hash().empty()) { |
| 645 | AidlTypeSpecifier* ret = |
| 646 | new AidlTypeSpecifier(AIDL_LOCATION_HERE, "String", false, nullptr, ""); |
| 647 | ret->Resolve(*typenames); |
| 648 | vector<unique_ptr<AidlArgument>>* args = new vector<unique_ptr<AidlArgument>>(); |
| 649 | AidlMethod* method = new AidlMethod(AIDL_LOCATION_HERE, false, ret, kGetInterfaceHash, args, |
| 650 | "", kGetInterfaceHashId, false /* is_user_defined */); |
| 651 | interface->GetMutableMethods().emplace_back(method); |
| 652 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 653 | if (!check_and_assign_method_ids(interface->GetMethods())) { |
| 654 | return AidlError::BAD_METHOD_ID; |
| 655 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 656 | |
| 657 | // Verify and resolve the constant declarations |
| 658 | for (const auto& constant : interface->GetConstantDeclarations()) { |
| 659 | switch (constant->GetValue().GetType()) { |
| 660 | case AidlConstantValue::Type::STRING: // fall-through |
| 661 | case AidlConstantValue::Type::INT8: // fall-through |
| 662 | case AidlConstantValue::Type::INT32: // fall-through |
| 663 | case AidlConstantValue::Type::INT64: // fall-through |
| 664 | case AidlConstantValue::Type::FLOATING: // fall-through |
| 665 | case AidlConstantValue::Type::UNARY: // fall-through |
| 666 | case AidlConstantValue::Type::BINARY: { |
| 667 | bool success = constant->CheckValid(*typenames); |
| 668 | if (!success) { |
| 669 | return AidlError::BAD_TYPE; |
| 670 | } |
| 671 | if (constant->ValueString(cpp::ConstantValueDecorator).empty()) { |
| 672 | return AidlError::BAD_TYPE; |
| 673 | } |
| 674 | break; |
| 675 | } |
| 676 | default: |
| 677 | LOG(FATAL) << "Unrecognized constant type: " |
| 678 | << static_cast<int>(constant->GetValue().GetType()); |
| 679 | break; |
| 680 | } |
| 681 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 682 | } |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 683 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 684 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 685 | typenames->IterateTypes([&](const AidlDefinedType& type) { |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 686 | if (options.IsStructured() && type.AsUnstructuredParcelable() != nullptr && |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 687 | !type.AsUnstructuredParcelable()->IsStableApiParcelable(options.TargetLanguage())) { |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 688 | err = AidlError::NOT_STRUCTURED; |
| 689 | LOG(ERROR) << type.GetCanonicalName() |
| 690 | << " is not structured, but this is a structured interface."; |
| 691 | } |
| 692 | if (options.GetStability() == Options::Stability::VINTF && !type.IsVintfStability()) { |
| 693 | err = AidlError::NOT_STRUCTURED; |
| 694 | LOG(ERROR) << type.GetCanonicalName() |
| 695 | << " does not have VINTF level stability, but this interface requires it."; |
| 696 | } |
| 697 | }); |
| 698 | |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 699 | if (err != AidlError::OK) { |
| 700 | return err; |
| 701 | } |
| 702 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 703 | if (defined_types != nullptr) { |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 704 | *defined_types = main_parser->GetDefinedTypes(); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 705 | } |
| 706 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 707 | if (imported_files != nullptr) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 708 | *imported_files = import_paths; |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 709 | } |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 710 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 711 | if (contains_unstructured_parcelable) { |
| 712 | // Considered a success for the legacy case, so this must be returned last. |
| 713 | return AidlError::FOUND_PARCELABLE; |
| 714 | } |
| 715 | |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 716 | return AidlError::OK; |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 719 | } // namespace internals |
| 720 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 721 | int compile_aidl(const Options& options, const IoDelegate& io_delegate) { |
| 722 | const Options::Language lang = options.TargetLanguage(); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 723 | for (const string& input_file : options.InputFiles()) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 724 | AidlTypenames typenames; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 725 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 726 | vector<AidlDefinedType*> defined_types; |
| 727 | vector<string> imported_files; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 728 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 729 | AidlError aidl_err = internals::load_and_validate_aidl( |
| 730 | input_file, options, io_delegate, &typenames, &defined_types, &imported_files); |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 731 | bool allowError = aidl_err == AidlError::FOUND_PARCELABLE && !options.FailOnParcelable(); |
| 732 | if (aidl_err != AidlError::OK && !allowError) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 733 | return 1; |
| 734 | } |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 735 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 736 | for (const auto defined_type : defined_types) { |
| 737 | CHECK(defined_type != nullptr); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 738 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 739 | string output_file_name = options.OutputFile(); |
| 740 | // if needed, generate the output file name from the base folder |
| 741 | if (output_file_name.empty() && !options.OutputDir().empty()) { |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 742 | output_file_name = generate_outputFileName(options, *defined_type); |
| 743 | if (output_file_name.empty()) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 744 | return 1; |
| 745 | } |
| 746 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 747 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 748 | if (!write_dep_file(options, *defined_type, imported_files, io_delegate, input_file, |
| 749 | output_file_name)) { |
| 750 | return 1; |
| 751 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 752 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 753 | bool success = false; |
| 754 | if (lang == Options::Language::CPP) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 755 | success = |
| 756 | cpp::GenerateCpp(output_file_name, options, typenames, *defined_type, io_delegate); |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 757 | } else if (lang == Options::Language::NDK) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 758 | ndk::GenerateNdk(output_file_name, options, typenames, *defined_type, io_delegate); |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 759 | success = true; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 760 | } else if (lang == Options::Language::JAVA) { |
Jiyong Park | 9ca5c7e | 2019-10-17 15:01:14 +0900 | [diff] [blame] | 761 | if (defined_type->AsUnstructuredParcelable() != nullptr) { |
| 762 | // Legacy behavior. For parcelable declarations in Java, don't generate output file. |
| 763 | success = true; |
| 764 | } else { |
| 765 | success = |
| 766 | java::generate_java(output_file_name, defined_type, typenames, io_delegate, options); |
| 767 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 768 | } else { |
| 769 | LOG(FATAL) << "Should not reach here" << endl; |
| 770 | return 1; |
| 771 | } |
| 772 | if (!success) { |
| 773 | return 1; |
| 774 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 775 | } |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 776 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 777 | return 0; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 778 | } |
| 779 | |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 780 | bool dump_mappings(const Options& options, const IoDelegate& io_delegate) { |
| 781 | android::aidl::mappings::SignatureMap all_mappings; |
| 782 | for (const string& input_file : options.InputFiles()) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 783 | AidlTypenames typenames; |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 784 | vector<AidlDefinedType*> defined_types; |
| 785 | vector<string> imported_files; |
| 786 | |
| 787 | AidlError aidl_err = internals::load_and_validate_aidl( |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 788 | input_file, options, io_delegate, &typenames, &defined_types, &imported_files); |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 789 | if (aidl_err != AidlError::OK) { |
| 790 | LOG(WARNING) << "AIDL file is invalid.\n"; |
| 791 | continue; |
| 792 | } |
| 793 | for (const auto defined_type : defined_types) { |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 794 | auto mappings = mappings::generate_mappings(defined_type, typenames); |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 795 | all_mappings.insert(mappings.begin(), mappings.end()); |
| 796 | } |
| 797 | } |
| 798 | std::stringstream mappings_str; |
| 799 | for (const auto& mapping : all_mappings) { |
| 800 | mappings_str << mapping.first << "\n" << mapping.second << "\n"; |
| 801 | } |
| 802 | auto code_writer = io_delegate.GetCodeWriter(options.OutputFile()); |
| 803 | code_writer->Write("%s", mappings_str.str().c_str()); |
| 804 | return true; |
| 805 | } |
| 806 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 807 | bool preprocess_aidl(const Options& options, const IoDelegate& io_delegate) { |
| 808 | unique_ptr<CodeWriter> writer = io_delegate.GetCodeWriter(options.OutputFile()); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 809 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 810 | for (const auto& file : options.InputFiles()) { |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 811 | AidlTypenames typenames; |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 812 | std::unique_ptr<Parser> p = Parser::Parse(file, io_delegate, typenames); |
| 813 | if (p == nullptr) return false; |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 814 | |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 815 | for (const auto& defined_type : p->GetDefinedTypes()) { |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 816 | if (!writer->Write("%s %s;\n", defined_type->GetPreprocessDeclarationName().c_str(), |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 817 | defined_type->GetCanonicalName().c_str())) { |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 818 | return false; |
| 819 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 820 | } |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 821 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 822 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 823 | return writer->Close(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 824 | } |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 825 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 826 | static string GetApiDumpPathFor(const AidlDefinedType& defined_type, const Options& options) { |
| 827 | string package_as_path = Join(Split(defined_type.GetPackage(), "."), OS_PATH_SEPARATOR); |
| 828 | CHECK(!options.OutputDir().empty() && options.OutputDir().back() == '/'); |
| 829 | return options.OutputDir() + package_as_path + OS_PATH_SEPARATOR + defined_type.GetName() + |
| 830 | ".aidl"; |
| 831 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 832 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 833 | bool dump_api(const Options& options, const IoDelegate& io_delegate) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 834 | for (const auto& file : options.InputFiles()) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 835 | AidlTypenames typenames; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 836 | vector<AidlDefinedType*> defined_types; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 837 | if (internals::load_and_validate_aidl(file, options, io_delegate, &typenames, &defined_types, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 838 | nullptr) == AidlError::OK) { |
| 839 | for (const auto type : defined_types) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 840 | unique_ptr<CodeWriter> writer = |
| 841 | io_delegate.GetCodeWriter(GetApiDumpPathFor(*type, options)); |
Steven Moreland | ec0531d | 2018-09-20 11:11:20 -0700 | [diff] [blame] | 842 | if (!type->GetPackage().empty()) { |
Paul Trautrim | b5ff1a2 | 2020-02-27 13:10:16 +0900 | [diff] [blame] | 843 | (*writer) << kPreamble << "package " << type->GetPackage() << ";\n"; |
Steven Moreland | ec0531d | 2018-09-20 11:11:20 -0700 | [diff] [blame] | 844 | } |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 845 | type->Dump(writer.get()); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 846 | } |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 847 | } else { |
| 848 | return false; |
| 849 | } |
| 850 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 851 | return true; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 852 | } |
| 853 | |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 854 | } // namespace aidl |
Steven Moreland | f4c64df | 2019-07-29 19:54:04 -0700 | [diff] [blame] | 855 | } // namespace android |