Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | */ |
| 16 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 17 | #include <getopt.h> |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include <fstream> |
| 22 | #include <iostream> |
| 23 | #include <unordered_map> |
| 24 | #include <sstream> |
| 25 | #include <string> |
| 26 | |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 27 | #include <vintf/KernelConfigParser.h> |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 28 | #include <vintf/parse_string.h> |
| 29 | #include <vintf/parse_xml.h> |
| 30 | |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 31 | #define BUFFER_SIZE sysconf(_SC_PAGESIZE) |
| 32 | |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 33 | namespace android { |
| 34 | namespace vintf { |
| 35 | |
| 36 | /** |
| 37 | * Slurps the device manifest file and add build time flag to it. |
| 38 | */ |
| 39 | class AssembleVintf { |
| 40 | public: |
| 41 | template<typename T> |
| 42 | static bool getFlag(const std::string& key, T* value) { |
| 43 | const char *envValue = getenv(key.c_str()); |
| 44 | if (envValue == NULL) { |
| 45 | std::cerr << "Required " << key << " flag." << std::endl; |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | if (!parse(envValue, value)) { |
| 50 | std::cerr << "Cannot parse " << envValue << "." << std::endl; |
| 51 | return false; |
| 52 | } |
| 53 | return true; |
| 54 | } |
| 55 | |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 56 | static std::string read(std::basic_istream<char>& is) { |
| 57 | std::stringstream ss; |
| 58 | ss << is.rdbuf(); |
| 59 | return ss.str(); |
| 60 | } |
| 61 | |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 62 | static bool parseFileForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) { |
| 63 | std::ifstream ifs{path}; |
| 64 | if (!ifs.is_open()) { |
| 65 | std::cerr << "File '" << path << "' does not exist or cannot be read." << std::endl; |
| 66 | return false; |
| 67 | } |
Yifan Hong | 02e9400 | 2017-07-10 15:41:56 -0700 | [diff] [blame] | 68 | KernelConfigParser parser(true /* processComments */, true /* relaxedFormat */); |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 69 | std::string content = read(ifs); |
| 70 | status_t err = parser.process(content.c_str(), content.size()); |
| 71 | if (err != OK) { |
Yifan Hong | ae53a0e | 2017-07-07 15:19:06 -0700 | [diff] [blame] | 72 | std::cerr << parser.error(); |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | err = parser.finish(); |
| 76 | if (err != OK) { |
Yifan Hong | ae53a0e | 2017-07-07 15:19:06 -0700 | [diff] [blame] | 77 | std::cerr << parser.error(); |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 78 | return false; |
| 79 | } |
| 80 | |
| 81 | for (auto& configPair : parser.configs()) { |
| 82 | out->push_back({}); |
| 83 | KernelConfig& config = out->back(); |
| 84 | config.first = std::move(configPair.first); |
| 85 | if (!parseKernelConfigTypedValue(configPair.second, &config.second)) { |
| 86 | std::cerr << "Unknown value type for key = '" << config.first << "', value = '" |
| 87 | << configPair.second << "'\n"; |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | return true; |
| 92 | } |
| 93 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 94 | std::basic_ostream<char>& out() const { |
| 95 | return mOutFileRef == nullptr ? std::cout : *mOutFileRef; |
| 96 | } |
| 97 | |
| 98 | bool assembleHalManifest(HalManifest* halManifest) { |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 99 | std::string error; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 100 | |
| 101 | if (halManifest->mType == SchemaType::DEVICE) { |
| 102 | if (!getFlag("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion)) { |
| 103 | return false; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (mOutputMatrix) { |
| 108 | CompatibilityMatrix generatedMatrix = halManifest->generateCompatibleMatrix(); |
| 109 | if (!halManifest->checkCompatibility(generatedMatrix, &error)) { |
| 110 | std::cerr << "FATAL ERROR: cannot generate a compatible matrix: " << error |
| 111 | << std::endl; |
| 112 | } |
| 113 | out() << "<!-- \n" |
| 114 | " Autogenerated skeleton compatibility matrix. \n" |
| 115 | " Use with caution. Modify it to suit your needs.\n" |
| 116 | " All HALs are set to optional.\n" |
| 117 | " Many entries other than HALs are zero-filled and\n" |
| 118 | " require human attention. \n" |
| 119 | "-->\n" |
| 120 | << gCompatibilityMatrixConverter(generatedMatrix); |
| 121 | } else { |
| 122 | out() << gHalManifestConverter(*halManifest); |
| 123 | } |
| 124 | out().flush(); |
| 125 | |
| 126 | if (mCheckFile.is_open()) { |
| 127 | CompatibilityMatrix checkMatrix; |
| 128 | if (!gCompatibilityMatrixConverter(&checkMatrix, read(mCheckFile))) { |
| 129 | std::cerr << "Cannot parse check file as a compatibility matrix: " |
| 130 | << gCompatibilityMatrixConverter.lastError() << std::endl; |
| 131 | return false; |
| 132 | } |
| 133 | if (!halManifest->checkCompatibility(checkMatrix, &error)) { |
| 134 | std::cerr << "Not compatible: " << error << std::endl; |
| 135 | return false; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | bool assembleCompatibilityMatrix(CompatibilityMatrix* matrix) { |
| 143 | std::string error; |
| 144 | |
| 145 | KernelSepolicyVersion kernelSepolicyVers; |
| 146 | Version sepolicyVers; |
| 147 | if (matrix->mType == SchemaType::FRAMEWORK) { |
| 148 | if (!getFlag("BOARD_SEPOLICY_VERS", &sepolicyVers)) { |
| 149 | return false; |
| 150 | } |
| 151 | if (!getFlag("POLICYVERS", &kernelSepolicyVers)) { |
| 152 | return false; |
| 153 | } |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 154 | for (const auto& pair : mKernels) { |
| 155 | std::vector<KernelConfig> configs; |
| 156 | if (!parseFileForKernelConfigs(pair.second, &configs)) { |
| 157 | return false; |
| 158 | } |
| 159 | bool added = false; |
| 160 | for (auto& e : matrix->framework.mKernels) { |
| 161 | if (e.minLts() == pair.first) { |
| 162 | e.mConfigs.insert(e.mConfigs.end(), configs.begin(), configs.end()); |
| 163 | added = true; |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | if (!added) { |
| 168 | matrix->framework.mKernels.push_back( |
| 169 | MatrixKernel{KernelVersion{pair.first}, std::move(configs)}); |
| 170 | } |
| 171 | } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 172 | matrix->framework.mSepolicy = |
| 173 | Sepolicy(kernelSepolicyVers, {{sepolicyVers.majorVer, sepolicyVers.minorVer}}); |
Yifan Hong | 7f6c00c | 2017-07-06 19:50:29 +0000 | [diff] [blame^] | 174 | |
| 175 | Version avbMetaVersion; |
| 176 | if (!getFlag("FRAMEWORK_VBMETA_VERSION", &avbMetaVersion)) { |
| 177 | return false; |
| 178 | } |
| 179 | matrix->framework.mAvbMetaVersion = avbMetaVersion; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 180 | } |
| 181 | out() << gCompatibilityMatrixConverter(*matrix); |
| 182 | out().flush(); |
| 183 | |
| 184 | if (mCheckFile.is_open()) { |
| 185 | HalManifest checkManifest; |
| 186 | if (!gHalManifestConverter(&checkManifest, read(mCheckFile))) { |
| 187 | std::cerr << "Cannot parse check file as a HAL manifest: " |
| 188 | << gHalManifestConverter.lastError() << std::endl; |
| 189 | return false; |
| 190 | } |
| 191 | if (!checkManifest.checkCompatibility(*matrix, &error)) { |
| 192 | std::cerr << "Not compatible: " << error << std::endl; |
| 193 | return false; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 200 | enum AssembleStatus { SUCCESS, FAIL_AND_EXIT, TRY_NEXT }; |
| 201 | template <typename Schema, typename AssembleFunc> |
| 202 | AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName, |
| 203 | AssembleFunc assemble) { |
| 204 | Schema schema; |
| 205 | if (!converter(&schema, read(mInFiles.front()))) { |
| 206 | return TRY_NEXT; |
| 207 | } |
| 208 | auto firstType = schema.type(); |
| 209 | for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) { |
| 210 | Schema additionalSchema; |
| 211 | if (!converter(&additionalSchema, read(*it))) { |
| 212 | std::cerr << "File \"" << mInFilePaths[std::distance(mInFiles.begin(), it)] |
| 213 | << "\" is not a valid " << firstType << " " << schemaName |
| 214 | << " (but the first file is a valid " << firstType << " " << schemaName |
| 215 | << "). Error: " << converter.lastError() << std::endl; |
| 216 | return FAIL_AND_EXIT; |
| 217 | } |
| 218 | if (additionalSchema.type() != firstType) { |
| 219 | std::cerr << "File \"" << mInFilePaths[std::distance(mInFiles.begin(), it)] |
| 220 | << "\" is a " << additionalSchema.type() << " " << schemaName |
| 221 | << " (but a " << firstType << " " << schemaName << " is expected)." |
| 222 | << std::endl; |
| 223 | return FAIL_AND_EXIT; |
| 224 | } |
| 225 | schema.addAll(std::move(additionalSchema)); |
| 226 | } |
| 227 | return assemble(&schema) ? SUCCESS : FAIL_AND_EXIT; |
| 228 | } |
| 229 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 230 | bool assemble() { |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 231 | using std::placeholders::_1; |
| 232 | if (mInFiles.empty()) { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 233 | std::cerr << "Missing input file." << std::endl; |
| 234 | return false; |
| 235 | } |
| 236 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 237 | auto status = tryAssemble(gHalManifestConverter, "manifest", |
| 238 | std::bind(&AssembleVintf::assembleHalManifest, this, _1)); |
| 239 | if (status == SUCCESS) return true; |
| 240 | if (status == FAIL_AND_EXIT) return false; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 241 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 242 | resetInFiles(); |
Yifan Hong | a59d256 | 2017-04-18 18:01:16 -0700 | [diff] [blame] | 243 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 244 | status = tryAssemble(gCompatibilityMatrixConverter, "compatibility matrix", |
| 245 | std::bind(&AssembleVintf::assembleCompatibilityMatrix, this, _1)); |
| 246 | if (status == SUCCESS) return true; |
| 247 | if (status == FAIL_AND_EXIT) return false; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 248 | |
Yifan Hong | 959ee1b | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 249 | std::cerr << "Input file has unknown format." << std::endl |
| 250 | << "Error when attempting to convert to manifest: " |
| 251 | << gHalManifestConverter.lastError() << std::endl |
| 252 | << "Error when attempting to convert to compatibility matrix: " |
| 253 | << gCompatibilityMatrixConverter.lastError() << std::endl; |
| 254 | return false; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 255 | } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 256 | |
| 257 | bool openOutFile(const char* path) { |
| 258 | mOutFileRef = std::make_unique<std::ofstream>(); |
| 259 | mOutFileRef->open(path); |
| 260 | return mOutFileRef->is_open(); |
| 261 | } |
| 262 | |
| 263 | bool openInFile(const char* path) { |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 264 | mInFilePaths.push_back(path); |
| 265 | mInFiles.push_back({}); |
| 266 | mInFiles.back().open(path); |
| 267 | return mInFiles.back().is_open(); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | bool openCheckFile(const char* path) { |
| 271 | mCheckFile.open(path); |
| 272 | return mCheckFile.is_open(); |
| 273 | } |
| 274 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 275 | void resetInFiles() { |
| 276 | for (auto& inFile : mInFiles) { |
| 277 | inFile.clear(); |
| 278 | inFile.seekg(0); |
| 279 | } |
| 280 | } |
| 281 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 282 | void setOutputMatrix() { mOutputMatrix = true; } |
| 283 | |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 284 | bool addKernel(const std::string& kernelArg) { |
| 285 | auto ind = kernelArg.find(':'); |
| 286 | if (ind == std::string::npos) { |
| 287 | std::cerr << "Unrecognized --kernel option '" << kernelArg << "'" << std::endl; |
| 288 | return false; |
| 289 | } |
| 290 | std::string kernelVerStr{kernelArg.begin(), kernelArg.begin() + ind}; |
| 291 | std::string kernelConfigPath{kernelArg.begin() + ind + 1, kernelArg.end()}; |
| 292 | Version kernelVer; |
| 293 | if (!parse(kernelVerStr, &kernelVer)) { |
| 294 | std::cerr << "Unrecognized kernel version '" << kernelVerStr << "'" << std::endl; |
| 295 | return false; |
| 296 | } |
| 297 | mKernels.push_back({{kernelVer.majorVer, kernelVer.minorVer, 0u}, kernelConfigPath}); |
| 298 | return true; |
| 299 | } |
| 300 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 301 | private: |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 302 | std::vector<std::string> mInFilePaths; |
| 303 | std::vector<std::ifstream> mInFiles; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 304 | std::unique_ptr<std::ofstream> mOutFileRef; |
| 305 | std::ifstream mCheckFile; |
| 306 | bool mOutputMatrix = false; |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 307 | std::vector<std::pair<KernelVersion, std::string>> mKernels; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | } // namespace vintf |
| 311 | } // namespace android |
| 312 | |
| 313 | void help() { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 314 | std::cerr << "assemble_vintf: Checks if a given manifest / matrix file is valid and \n" |
| 315 | " fill in build-time flags into the given file.\n" |
| 316 | "assemble_vintf -h\n" |
| 317 | " Display this help text.\n" |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 318 | "assemble_vintf -i <input file>[:<input file>[...]] [-o <output file>] [-m]\n" |
| 319 | " [-c [<check file>]]\n" |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 320 | " Fill in build-time flags into the given file.\n" |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 321 | " -i <input file>[:<input file>[...]]\n" |
| 322 | " A list of input files. Format is automatically detected for the\n" |
| 323 | " first file, and the remaining files must have the same format.\n" |
| 324 | " Files other than the first file should only have <hal> defined;\n" |
| 325 | " other entries are ignored.\n" |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 326 | " -o <output file>\n" |
| 327 | " Optional output file. If not specified, write to stdout.\n" |
| 328 | " -m\n" |
| 329 | " a compatible compatibility matrix is\n" |
| 330 | " generated instead; for example, given a device manifest,\n" |
| 331 | " a framework compatibility matrix is generated. This flag\n" |
| 332 | " is ignored when input is a compatibility matrix.\n" |
| 333 | " -c [<check file>]\n" |
| 334 | " After writing the output file, check compatibility between\n" |
| 335 | " output file and check file.\n" |
| 336 | " If -c is set but the check file is not specified, a warning\n" |
| 337 | " message is written to stderr. Return 0.\n" |
| 338 | " If the check file is specified but is not compatible, an error\n" |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 339 | " message is written to stderr. Return 1.\n" |
| 340 | " --kernel=<version>:<android-base.cfg>\n" |
| 341 | " Add a kernel entry to framework compatibility matrix.\n" |
| 342 | " Ignored for other input format.\n" |
| 343 | " <version> has format: 3.18\n" |
| 344 | " <android-base.cfg> is the location of android-base.cfg\n"; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | int main(int argc, char **argv) { |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 348 | const struct option longopts[] = {{"kernel", required_argument, NULL, 'k'}, {0, 0, 0, 0}}; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 349 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 350 | std::string outFilePath; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 351 | ::android::vintf::AssembleVintf assembleVintf; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 352 | int res; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 353 | int optind; |
| 354 | while ((res = getopt_long(argc, argv, "hi:o:mc:", longopts, &optind)) >= 0) { |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 355 | switch (res) { |
| 356 | case 'i': { |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 357 | char* inFilePath = strtok(optarg, ":"); |
| 358 | while (inFilePath != NULL) { |
| 359 | if (!assembleVintf.openInFile(inFilePath)) { |
| 360 | std::cerr << "Failed to open " << optarg << std::endl; |
| 361 | return 1; |
| 362 | } |
| 363 | inFilePath = strtok(NULL, ":"); |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 364 | } |
| 365 | } break; |
| 366 | |
| 367 | case 'o': { |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 368 | outFilePath = optarg; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 369 | if (!assembleVintf.openOutFile(optarg)) { |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 370 | std::cerr << "Failed to open " << optarg << std::endl; |
| 371 | return 1; |
| 372 | } |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 373 | } break; |
| 374 | |
Yifan Hong | a59d256 | 2017-04-18 18:01:16 -0700 | [diff] [blame] | 375 | case 'm': { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 376 | assembleVintf.setOutputMatrix(); |
Yifan Hong | a59d256 | 2017-04-18 18:01:16 -0700 | [diff] [blame] | 377 | } break; |
| 378 | |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 379 | case 'c': { |
| 380 | if (strlen(optarg) != 0) { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 381 | if (!assembleVintf.openCheckFile(optarg)) { |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 382 | std::cerr << "Failed to open " << optarg << std::endl; |
| 383 | return 1; |
| 384 | } |
| 385 | } else { |
| 386 | std::cerr << "WARNING: no compatibility check is done on " |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 387 | << (outFilePath.empty() ? "output" : outFilePath) << std::endl; |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 388 | } |
| 389 | } break; |
| 390 | |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 391 | case 'k': { |
| 392 | if (!assembleVintf.addKernel(optarg)) { |
| 393 | std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl; |
| 394 | return 1; |
| 395 | } |
| 396 | } break; |
| 397 | |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 398 | case 'h': |
| 399 | default: { |
| 400 | help(); |
| 401 | return 1; |
| 402 | } break; |
| 403 | } |
| 404 | } |
| 405 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 406 | bool success = assembleVintf.assemble(); |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 407 | |
| 408 | return success ? 0 : 1; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 409 | } |
| 410 | |