blob: 974c7fcf86eb802ff90fdf90ff40710442f98ea2 [file] [log] [blame]
Yifan Hong4d18bcc2017-04-07 21:47:16 +00001/*
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 Hong9aa63702017-05-16 16:37:50 -070017#include <getopt.h>
Yifan Hong4d18bcc2017-04-07 21:47:16 +000018#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 Hong9a8b1a72017-08-25 17:55:33 -070027#include <android-base/file.h>
28
Yifan Hong79efa8a2017-07-06 14:10:28 -070029#include <vintf/KernelConfigParser.h>
Yifan Hong4d18bcc2017-04-07 21:47:16 +000030#include <vintf/parse_string.h>
31#include <vintf/parse_xml.h>
32
Yifan Hong79efa8a2017-07-06 14:10:28 -070033#define BUFFER_SIZE sysconf(_SC_PAGESIZE)
34
Yifan Hong4d18bcc2017-04-07 21:47:16 +000035namespace android {
36namespace vintf {
37
Yifan Hong9a8b1a72017-08-25 17:55:33 -070038static const std::string gConfigPrefix = "android-base-";
39static const std::string gConfigSuffix = ".cfg";
40static const std::string gBaseConfig = "android-base.cfg";
41
Yifan Hong4d18bcc2017-04-07 21:47:16 +000042/**
43 * Slurps the device manifest file and add build time flag to it.
44 */
45class AssembleVintf {
Yifan Hong9a8b1a72017-08-25 17:55:33 -070046 using Condition = std::unique_ptr<KernelConfig>;
47 using ConditionedConfig = std::pair<Condition, std::vector<KernelConfig> /* configs */>;
48
49 public:
Yifan Hong4d18bcc2017-04-07 21:47:16 +000050 template<typename T>
51 static bool getFlag(const std::string& key, T* value) {
52 const char *envValue = getenv(key.c_str());
53 if (envValue == NULL) {
Yifan Hong488e16a2017-07-11 13:50:41 -070054 std::cerr << "Warning: " << key << " is missing, defaulted to " << (*value)
55 << std::endl;
56 return true;
Yifan Hong4d18bcc2017-04-07 21:47:16 +000057 }
58
59 if (!parse(envValue, value)) {
60 std::cerr << "Cannot parse " << envValue << "." << std::endl;
61 return false;
62 }
63 return true;
64 }
65
Yifan Hong4650ad82017-05-01 17:28:02 -070066 static std::string read(std::basic_istream<char>& is) {
67 std::stringstream ss;
68 ss << is.rdbuf();
69 return ss.str();
70 }
71
Yifan Hong9a8b1a72017-08-25 17:55:33 -070072 static bool isCommonConfig(const std::string& path) {
73 return ::android::base::Basename(path) == gBaseConfig;
74 }
75
Yifan Hong079ec242017-08-25 18:53:38 -070076 // nullptr on any error, otherwise the condition.
77 static Condition generateCondition(const std::string& path) {
78 std::string fname = ::android::base::Basename(path);
79 if (fname.size() <= gConfigPrefix.size() + gConfigSuffix.size() ||
80 !std::equal(gConfigPrefix.begin(), gConfigPrefix.end(), fname.begin()) ||
81 !std::equal(gConfigSuffix.rbegin(), gConfigSuffix.rend(), fname.rbegin())) {
82 return nullptr;
83 }
84
85 std::string sub = fname.substr(gConfigPrefix.size(),
86 fname.size() - gConfigPrefix.size() - gConfigSuffix.size());
87 if (sub.empty()) {
88 return nullptr; // should not happen
89 }
90 for (size_t i = 0; i < sub.size(); ++i) {
91 if (sub[i] == '-') {
92 sub[i] = '_';
93 continue;
94 }
95 if (isalnum(sub[i])) {
96 sub[i] = toupper(sub[i]);
97 continue;
98 }
99 std::cerr << "'" << fname << "' (in " << path
100 << ") is not a valid kernel config file name. Must match regex: "
101 << "android-base(-[0-9a-zA-Z-]+)?\\.cfg" << std::endl;
102 return nullptr;
103 }
104 sub.insert(0, "CONFIG_");
105 return std::make_unique<KernelConfig>(std::move(sub), Tristate::YES);
106 }
107
Yifan Hong79efa8a2017-07-06 14:10:28 -0700108 static bool parseFileForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) {
109 std::ifstream ifs{path};
110 if (!ifs.is_open()) {
111 std::cerr << "File '" << path << "' does not exist or cannot be read." << std::endl;
112 return false;
113 }
Yifan Hong02e94002017-07-10 15:41:56 -0700114 KernelConfigParser parser(true /* processComments */, true /* relaxedFormat */);
Yifan Hong79efa8a2017-07-06 14:10:28 -0700115 std::string content = read(ifs);
116 status_t err = parser.process(content.c_str(), content.size());
117 if (err != OK) {
Yifan Hongae53a0e2017-07-07 15:19:06 -0700118 std::cerr << parser.error();
Yifan Hong79efa8a2017-07-06 14:10:28 -0700119 return false;
120 }
121 err = parser.finish();
122 if (err != OK) {
Yifan Hongae53a0e2017-07-07 15:19:06 -0700123 std::cerr << parser.error();
Yifan Hong79efa8a2017-07-06 14:10:28 -0700124 return false;
125 }
126
127 for (auto& configPair : parser.configs()) {
128 out->push_back({});
129 KernelConfig& config = out->back();
130 config.first = std::move(configPair.first);
131 if (!parseKernelConfigTypedValue(configPair.second, &config.second)) {
132 std::cerr << "Unknown value type for key = '" << config.first << "', value = '"
133 << configPair.second << "'\n";
134 return false;
135 }
136 }
137 return true;
138 }
139
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700140 static bool parseFilesForKernelConfigs(const std::string& path,
141 std::vector<ConditionedConfig>* out) {
142 out->clear();
143 ConditionedConfig commonConfig;
144 bool foundCommonConfig = false;
Steve Muckle0bef8682017-07-31 15:47:15 -0700145 bool ret = true;
146 char *pathIter;
147 char *modPath = new char[path.length() + 1];
148 strcpy(modPath, path.c_str());
149 pathIter = strtok(modPath, ":");
150 while (ret && pathIter != NULL) {
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700151 if (isCommonConfig(pathIter)) {
152 ret &= parseFileForKernelConfigs(pathIter, &commonConfig.second);
153 foundCommonConfig = true;
154 } else {
Yifan Hong079ec242017-08-25 18:53:38 -0700155 Condition condition = generateCondition(pathIter);
156 ret &= (condition != nullptr);
157
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700158 std::vector<KernelConfig> kernelConfigs;
159 if ((ret &= parseFileForKernelConfigs(pathIter, &kernelConfigs)))
Yifan Hong079ec242017-08-25 18:53:38 -0700160 out->emplace_back(std::move(condition), std::move(kernelConfigs));
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700161 }
Steve Muckle0bef8682017-07-31 15:47:15 -0700162 pathIter = strtok(NULL, ":");
163 }
Luis A. Lozano82266ae2017-08-22 16:30:11 -0700164 delete[] modPath;
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700165
166 if (!foundCommonConfig) {
167 std::cerr << "No android-base.cfg is found in these paths: '" << path << "'"
168 << std::endl;
169 }
170 ret &= foundCommonConfig;
171 // first element is always common configs (no conditions).
172 out->insert(out->begin(), std::move(commonConfig));
Steve Muckle0bef8682017-07-31 15:47:15 -0700173 return ret;
174 }
175
Yifan Hong9aa63702017-05-16 16:37:50 -0700176 std::basic_ostream<char>& out() const {
177 return mOutFileRef == nullptr ? std::cout : *mOutFileRef;
178 }
179
180 bool assembleHalManifest(HalManifest* halManifest) {
Yifan Hong4650ad82017-05-01 17:28:02 -0700181 std::string error;
Yifan Hong9aa63702017-05-16 16:37:50 -0700182
183 if (halManifest->mType == SchemaType::DEVICE) {
184 if (!getFlag("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion)) {
185 return false;
186 }
187 }
188
189 if (mOutputMatrix) {
190 CompatibilityMatrix generatedMatrix = halManifest->generateCompatibleMatrix();
191 if (!halManifest->checkCompatibility(generatedMatrix, &error)) {
192 std::cerr << "FATAL ERROR: cannot generate a compatible matrix: " << error
193 << std::endl;
194 }
195 out() << "<!-- \n"
196 " Autogenerated skeleton compatibility matrix. \n"
197 " Use with caution. Modify it to suit your needs.\n"
198 " All HALs are set to optional.\n"
199 " Many entries other than HALs are zero-filled and\n"
200 " require human attention. \n"
201 "-->\n"
202 << gCompatibilityMatrixConverter(generatedMatrix);
203 } else {
204 out() << gHalManifestConverter(*halManifest);
205 }
206 out().flush();
207
208 if (mCheckFile.is_open()) {
209 CompatibilityMatrix checkMatrix;
210 if (!gCompatibilityMatrixConverter(&checkMatrix, read(mCheckFile))) {
211 std::cerr << "Cannot parse check file as a compatibility matrix: "
212 << gCompatibilityMatrixConverter.lastError() << std::endl;
213 return false;
214 }
215 if (!halManifest->checkCompatibility(checkMatrix, &error)) {
216 std::cerr << "Not compatible: " << error << std::endl;
217 return false;
218 }
219 }
220
221 return true;
222 }
223
Yifan Honge88e1672017-08-24 14:42:54 -0700224 bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) {
Yifan Hong4c34fee2017-08-24 16:03:34 -0700225 if (!matrix->framework.mKernels.empty()) {
226 // Remove hard-coded <kernel version="x.y.z" /> in legacy files.
227 std::cerr << "WARNING: framework compatibility matrix has hard-coded kernel"
228 << " requirements for version";
229 for (const auto& kernel : matrix->framework.mKernels) {
230 std::cerr << " " << kernel.minLts();
231 }
232 std::cerr << ". Hard-coded requirements are removed." << std::endl;
233 matrix->framework.mKernels.clear();
234 }
Yifan Honge88e1672017-08-24 14:42:54 -0700235 for (const auto& pair : mKernels) {
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700236 std::vector<ConditionedConfig> conditionedConfigs;
237 if (!parseFilesForKernelConfigs(pair.second, &conditionedConfigs)) {
Yifan Honge88e1672017-08-24 14:42:54 -0700238 return false;
239 }
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700240 for (ConditionedConfig& conditionedConfig : conditionedConfigs) {
Yifan Hong48602df2017-08-28 13:04:12 -0700241 MatrixKernel kernel(KernelVersion{pair.first.majorVer, pair.first.minorVer, 0u},
242 std::move(conditionedConfig.second));
Yifan Hong079ec242017-08-25 18:53:38 -0700243 if (conditionedConfig.first != nullptr)
244 kernel.mConditions.push_back(std::move(*conditionedConfig.first));
245 matrix->framework.mKernels.push_back(std::move(kernel));
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700246 }
Yifan Honge88e1672017-08-24 14:42:54 -0700247 }
248 return true;
249 }
250
Yifan Hong9aa63702017-05-16 16:37:50 -0700251 bool assembleCompatibilityMatrix(CompatibilityMatrix* matrix) {
252 std::string error;
253
254 KernelSepolicyVersion kernelSepolicyVers;
255 Version sepolicyVers;
256 if (matrix->mType == SchemaType::FRAMEWORK) {
257 if (!getFlag("BOARD_SEPOLICY_VERS", &sepolicyVers)) {
258 return false;
259 }
260 if (!getFlag("POLICYVERS", &kernelSepolicyVers)) {
261 return false;
262 }
Yifan Honge88e1672017-08-24 14:42:54 -0700263
264 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) {
265 return false;
Yifan Hong79efa8a2017-07-06 14:10:28 -0700266 }
Yifan Honge88e1672017-08-24 14:42:54 -0700267
Yifan Hong9aa63702017-05-16 16:37:50 -0700268 matrix->framework.mSepolicy =
269 Sepolicy(kernelSepolicyVers, {{sepolicyVers.majorVer, sepolicyVers.minorVer}});
Yifan Hong7f6c00c2017-07-06 19:50:29 +0000270
271 Version avbMetaVersion;
272 if (!getFlag("FRAMEWORK_VBMETA_VERSION", &avbMetaVersion)) {
273 return false;
274 }
275 matrix->framework.mAvbMetaVersion = avbMetaVersion;
Yifan Hong9aa63702017-05-16 16:37:50 -0700276 }
277 out() << gCompatibilityMatrixConverter(*matrix);
278 out().flush();
279
280 if (mCheckFile.is_open()) {
281 HalManifest checkManifest;
282 if (!gHalManifestConverter(&checkManifest, read(mCheckFile))) {
283 std::cerr << "Cannot parse check file as a HAL manifest: "
284 << gHalManifestConverter.lastError() << std::endl;
285 return false;
286 }
287 if (!checkManifest.checkCompatibility(*matrix, &error)) {
288 std::cerr << "Not compatible: " << error << std::endl;
289 return false;
290 }
291 }
292
293 return true;
294 }
295
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700296 enum AssembleStatus { SUCCESS, FAIL_AND_EXIT, TRY_NEXT };
297 template <typename Schema, typename AssembleFunc>
298 AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName,
299 AssembleFunc assemble) {
300 Schema schema;
301 if (!converter(&schema, read(mInFiles.front()))) {
302 return TRY_NEXT;
303 }
304 auto firstType = schema.type();
305 for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
306 Schema additionalSchema;
307 if (!converter(&additionalSchema, read(*it))) {
308 std::cerr << "File \"" << mInFilePaths[std::distance(mInFiles.begin(), it)]
309 << "\" is not a valid " << firstType << " " << schemaName
310 << " (but the first file is a valid " << firstType << " " << schemaName
311 << "). Error: " << converter.lastError() << std::endl;
312 return FAIL_AND_EXIT;
313 }
314 if (additionalSchema.type() != firstType) {
315 std::cerr << "File \"" << mInFilePaths[std::distance(mInFiles.begin(), it)]
316 << "\" is a " << additionalSchema.type() << " " << schemaName
317 << " (but a " << firstType << " " << schemaName << " is expected)."
318 << std::endl;
319 return FAIL_AND_EXIT;
320 }
321 schema.addAll(std::move(additionalSchema));
322 }
323 return assemble(&schema) ? SUCCESS : FAIL_AND_EXIT;
324 }
325
Yifan Hong9aa63702017-05-16 16:37:50 -0700326 bool assemble() {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700327 using std::placeholders::_1;
328 if (mInFiles.empty()) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700329 std::cerr << "Missing input file." << std::endl;
330 return false;
331 }
332
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700333 auto status = tryAssemble(gHalManifestConverter, "manifest",
334 std::bind(&AssembleVintf::assembleHalManifest, this, _1));
335 if (status == SUCCESS) return true;
336 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000337
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700338 resetInFiles();
Yifan Honga59d2562017-04-18 18:01:16 -0700339
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700340 status = tryAssemble(gCompatibilityMatrixConverter, "compatibility matrix",
341 std::bind(&AssembleVintf::assembleCompatibilityMatrix, this, _1));
342 if (status == SUCCESS) return true;
343 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000344
Yifan Hong959ee1b2017-04-28 14:37:56 -0700345 std::cerr << "Input file has unknown format." << std::endl
346 << "Error when attempting to convert to manifest: "
347 << gHalManifestConverter.lastError() << std::endl
348 << "Error when attempting to convert to compatibility matrix: "
349 << gCompatibilityMatrixConverter.lastError() << std::endl;
350 return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000351 }
Yifan Hong9aa63702017-05-16 16:37:50 -0700352
353 bool openOutFile(const char* path) {
354 mOutFileRef = std::make_unique<std::ofstream>();
355 mOutFileRef->open(path);
356 return mOutFileRef->is_open();
357 }
358
359 bool openInFile(const char* path) {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700360 mInFilePaths.push_back(path);
361 mInFiles.push_back({});
362 mInFiles.back().open(path);
363 return mInFiles.back().is_open();
Yifan Hong9aa63702017-05-16 16:37:50 -0700364 }
365
366 bool openCheckFile(const char* path) {
367 mCheckFile.open(path);
368 return mCheckFile.is_open();
369 }
370
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700371 void resetInFiles() {
372 for (auto& inFile : mInFiles) {
373 inFile.clear();
374 inFile.seekg(0);
375 }
376 }
377
Yifan Hong9aa63702017-05-16 16:37:50 -0700378 void setOutputMatrix() { mOutputMatrix = true; }
379
Yifan Hong79efa8a2017-07-06 14:10:28 -0700380 bool addKernel(const std::string& kernelArg) {
381 auto ind = kernelArg.find(':');
382 if (ind == std::string::npos) {
383 std::cerr << "Unrecognized --kernel option '" << kernelArg << "'" << std::endl;
384 return false;
385 }
386 std::string kernelVerStr{kernelArg.begin(), kernelArg.begin() + ind};
387 std::string kernelConfigPath{kernelArg.begin() + ind + 1, kernelArg.end()};
388 Version kernelVer;
389 if (!parse(kernelVerStr, &kernelVer)) {
390 std::cerr << "Unrecognized kernel version '" << kernelVerStr << "'" << std::endl;
391 return false;
392 }
Yifan Hong48602df2017-08-28 13:04:12 -0700393 if (mKernels.find(kernelVer) != mKernels.end()) {
394 std::cerr << "Multiple --kernel for " << kernelVer << " is specified." << std::endl;
395 return false;
396 }
397 mKernels[kernelVer] = kernelConfigPath;
Yifan Hong79efa8a2017-07-06 14:10:28 -0700398 return true;
399 }
400
Yifan Hong9aa63702017-05-16 16:37:50 -0700401 private:
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700402 std::vector<std::string> mInFilePaths;
403 std::vector<std::ifstream> mInFiles;
Yifan Hong9aa63702017-05-16 16:37:50 -0700404 std::unique_ptr<std::ofstream> mOutFileRef;
405 std::ifstream mCheckFile;
406 bool mOutputMatrix = false;
Yifan Hong48602df2017-08-28 13:04:12 -0700407 std::map<Version, std::string> mKernels;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000408};
409
410} // namespace vintf
411} // namespace android
412
413void help() {
Yifan Hong9aa63702017-05-16 16:37:50 -0700414 std::cerr << "assemble_vintf: Checks if a given manifest / matrix file is valid and \n"
415 " fill in build-time flags into the given file.\n"
416 "assemble_vintf -h\n"
417 " Display this help text.\n"
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700418 "assemble_vintf -i <input file>[:<input file>[...]] [-o <output file>] [-m]\n"
419 " [-c [<check file>]]\n"
Yifan Hong9aa63702017-05-16 16:37:50 -0700420 " Fill in build-time flags into the given file.\n"
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700421 " -i <input file>[:<input file>[...]]\n"
422 " A list of input files. Format is automatically detected for the\n"
423 " first file, and the remaining files must have the same format.\n"
424 " Files other than the first file should only have <hal> defined;\n"
425 " other entries are ignored.\n"
Yifan Hong9aa63702017-05-16 16:37:50 -0700426 " -o <output file>\n"
427 " Optional output file. If not specified, write to stdout.\n"
428 " -m\n"
429 " a compatible compatibility matrix is\n"
430 " generated instead; for example, given a device manifest,\n"
431 " a framework compatibility matrix is generated. This flag\n"
432 " is ignored when input is a compatibility matrix.\n"
433 " -c [<check file>]\n"
434 " After writing the output file, check compatibility between\n"
435 " output file and check file.\n"
436 " If -c is set but the check file is not specified, a warning\n"
437 " message is written to stderr. Return 0.\n"
438 " If the check file is specified but is not compatible, an error\n"
Yifan Hong79efa8a2017-07-06 14:10:28 -0700439 " message is written to stderr. Return 1.\n"
Steve Muckle0bef8682017-07-31 15:47:15 -0700440 " --kernel=<version>:<android-base.cfg>[:<android-base-arch.cfg>[...]]\n"
Yifan Hong79efa8a2017-07-06 14:10:28 -0700441 " Add a kernel entry to framework compatibility matrix.\n"
442 " Ignored for other input format.\n"
443 " <version> has format: 3.18\n"
Steve Muckle0bef8682017-07-31 15:47:15 -0700444 " <android-base.cfg> is the location of android-base.cfg\n"
445 " <android-base-arch.cfg> is the location of an optional\n"
446 " arch-specific config fragment, more than one may be specified\n";
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000447}
448
449int main(int argc, char **argv) {
Yifan Hong79efa8a2017-07-06 14:10:28 -0700450 const struct option longopts[] = {{"kernel", required_argument, NULL, 'k'}, {0, 0, 0, 0}};
Yifan Hong9aa63702017-05-16 16:37:50 -0700451
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700452 std::string outFilePath;
Yifan Hong9aa63702017-05-16 16:37:50 -0700453 ::android::vintf::AssembleVintf assembleVintf;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000454 int res;
Yifan Hong9aa63702017-05-16 16:37:50 -0700455 int optind;
456 while ((res = getopt_long(argc, argv, "hi:o:mc:", longopts, &optind)) >= 0) {
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000457 switch (res) {
458 case 'i': {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700459 char* inFilePath = strtok(optarg, ":");
460 while (inFilePath != NULL) {
461 if (!assembleVintf.openInFile(inFilePath)) {
462 std::cerr << "Failed to open " << optarg << std::endl;
463 return 1;
464 }
465 inFilePath = strtok(NULL, ":");
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000466 }
467 } break;
468
469 case 'o': {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700470 outFilePath = optarg;
Yifan Hong9aa63702017-05-16 16:37:50 -0700471 if (!assembleVintf.openOutFile(optarg)) {
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000472 std::cerr << "Failed to open " << optarg << std::endl;
473 return 1;
474 }
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000475 } break;
476
Yifan Honga59d2562017-04-18 18:01:16 -0700477 case 'm': {
Yifan Hong9aa63702017-05-16 16:37:50 -0700478 assembleVintf.setOutputMatrix();
Yifan Honga59d2562017-04-18 18:01:16 -0700479 } break;
480
Yifan Hong4650ad82017-05-01 17:28:02 -0700481 case 'c': {
482 if (strlen(optarg) != 0) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700483 if (!assembleVintf.openCheckFile(optarg)) {
Yifan Hong4650ad82017-05-01 17:28:02 -0700484 std::cerr << "Failed to open " << optarg << std::endl;
485 return 1;
486 }
487 } else {
488 std::cerr << "WARNING: no compatibility check is done on "
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700489 << (outFilePath.empty() ? "output" : outFilePath) << std::endl;
Yifan Hong4650ad82017-05-01 17:28:02 -0700490 }
491 } break;
492
Yifan Hong79efa8a2017-07-06 14:10:28 -0700493 case 'k': {
494 if (!assembleVintf.addKernel(optarg)) {
495 std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl;
496 return 1;
497 }
498 } break;
499
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000500 case 'h':
501 default: {
502 help();
503 return 1;
504 } break;
505 }
506 }
507
Yifan Hong9aa63702017-05-16 16:37:50 -0700508 bool success = assembleVintf.assemble();
Yifan Hong4650ad82017-05-01 17:28:02 -0700509
510 return success ? 0 : 1;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000511}