blob: 3218d1d42cd995729389ad1a015d55dbb0729e25 [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 Hong079ec242017-08-25 18:53:38 -0700241 MatrixKernel kernel(KernelVersion{pair.first}, std::move(conditionedConfig.second));
242 if (conditionedConfig.first != nullptr)
243 kernel.mConditions.push_back(std::move(*conditionedConfig.first));
244 matrix->framework.mKernels.push_back(std::move(kernel));
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700245 }
Yifan Honge88e1672017-08-24 14:42:54 -0700246 }
247 return true;
248 }
249
Yifan Hong9aa63702017-05-16 16:37:50 -0700250 bool assembleCompatibilityMatrix(CompatibilityMatrix* matrix) {
251 std::string error;
252
253 KernelSepolicyVersion kernelSepolicyVers;
254 Version sepolicyVers;
255 if (matrix->mType == SchemaType::FRAMEWORK) {
256 if (!getFlag("BOARD_SEPOLICY_VERS", &sepolicyVers)) {
257 return false;
258 }
259 if (!getFlag("POLICYVERS", &kernelSepolicyVers)) {
260 return false;
261 }
Yifan Honge88e1672017-08-24 14:42:54 -0700262
263 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) {
264 return false;
Yifan Hong79efa8a2017-07-06 14:10:28 -0700265 }
Yifan Honge88e1672017-08-24 14:42:54 -0700266
Yifan Hong9aa63702017-05-16 16:37:50 -0700267 matrix->framework.mSepolicy =
268 Sepolicy(kernelSepolicyVers, {{sepolicyVers.majorVer, sepolicyVers.minorVer}});
Yifan Hong7f6c00c2017-07-06 19:50:29 +0000269
270 Version avbMetaVersion;
271 if (!getFlag("FRAMEWORK_VBMETA_VERSION", &avbMetaVersion)) {
272 return false;
273 }
274 matrix->framework.mAvbMetaVersion = avbMetaVersion;
Yifan Hong9aa63702017-05-16 16:37:50 -0700275 }
276 out() << gCompatibilityMatrixConverter(*matrix);
277 out().flush();
278
279 if (mCheckFile.is_open()) {
280 HalManifest checkManifest;
281 if (!gHalManifestConverter(&checkManifest, read(mCheckFile))) {
282 std::cerr << "Cannot parse check file as a HAL manifest: "
283 << gHalManifestConverter.lastError() << std::endl;
284 return false;
285 }
286 if (!checkManifest.checkCompatibility(*matrix, &error)) {
287 std::cerr << "Not compatible: " << error << std::endl;
288 return false;
289 }
290 }
291
292 return true;
293 }
294
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700295 enum AssembleStatus { SUCCESS, FAIL_AND_EXIT, TRY_NEXT };
296 template <typename Schema, typename AssembleFunc>
297 AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName,
298 AssembleFunc assemble) {
299 Schema schema;
300 if (!converter(&schema, read(mInFiles.front()))) {
301 return TRY_NEXT;
302 }
303 auto firstType = schema.type();
304 for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
305 Schema additionalSchema;
306 if (!converter(&additionalSchema, read(*it))) {
307 std::cerr << "File \"" << mInFilePaths[std::distance(mInFiles.begin(), it)]
308 << "\" is not a valid " << firstType << " " << schemaName
309 << " (but the first file is a valid " << firstType << " " << schemaName
310 << "). Error: " << converter.lastError() << std::endl;
311 return FAIL_AND_EXIT;
312 }
313 if (additionalSchema.type() != firstType) {
314 std::cerr << "File \"" << mInFilePaths[std::distance(mInFiles.begin(), it)]
315 << "\" is a " << additionalSchema.type() << " " << schemaName
316 << " (but a " << firstType << " " << schemaName << " is expected)."
317 << std::endl;
318 return FAIL_AND_EXIT;
319 }
320 schema.addAll(std::move(additionalSchema));
321 }
322 return assemble(&schema) ? SUCCESS : FAIL_AND_EXIT;
323 }
324
Yifan Hong9aa63702017-05-16 16:37:50 -0700325 bool assemble() {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700326 using std::placeholders::_1;
327 if (mInFiles.empty()) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700328 std::cerr << "Missing input file." << std::endl;
329 return false;
330 }
331
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700332 auto status = tryAssemble(gHalManifestConverter, "manifest",
333 std::bind(&AssembleVintf::assembleHalManifest, this, _1));
334 if (status == SUCCESS) return true;
335 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000336
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700337 resetInFiles();
Yifan Honga59d2562017-04-18 18:01:16 -0700338
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700339 status = tryAssemble(gCompatibilityMatrixConverter, "compatibility matrix",
340 std::bind(&AssembleVintf::assembleCompatibilityMatrix, this, _1));
341 if (status == SUCCESS) return true;
342 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000343
Yifan Hong959ee1b2017-04-28 14:37:56 -0700344 std::cerr << "Input file has unknown format." << std::endl
345 << "Error when attempting to convert to manifest: "
346 << gHalManifestConverter.lastError() << std::endl
347 << "Error when attempting to convert to compatibility matrix: "
348 << gCompatibilityMatrixConverter.lastError() << std::endl;
349 return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000350 }
Yifan Hong9aa63702017-05-16 16:37:50 -0700351
352 bool openOutFile(const char* path) {
353 mOutFileRef = std::make_unique<std::ofstream>();
354 mOutFileRef->open(path);
355 return mOutFileRef->is_open();
356 }
357
358 bool openInFile(const char* path) {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700359 mInFilePaths.push_back(path);
360 mInFiles.push_back({});
361 mInFiles.back().open(path);
362 return mInFiles.back().is_open();
Yifan Hong9aa63702017-05-16 16:37:50 -0700363 }
364
365 bool openCheckFile(const char* path) {
366 mCheckFile.open(path);
367 return mCheckFile.is_open();
368 }
369
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700370 void resetInFiles() {
371 for (auto& inFile : mInFiles) {
372 inFile.clear();
373 inFile.seekg(0);
374 }
375 }
376
Yifan Hong9aa63702017-05-16 16:37:50 -0700377 void setOutputMatrix() { mOutputMatrix = true; }
378
Yifan Hong79efa8a2017-07-06 14:10:28 -0700379 bool addKernel(const std::string& kernelArg) {
380 auto ind = kernelArg.find(':');
381 if (ind == std::string::npos) {
382 std::cerr << "Unrecognized --kernel option '" << kernelArg << "'" << std::endl;
383 return false;
384 }
385 std::string kernelVerStr{kernelArg.begin(), kernelArg.begin() + ind};
386 std::string kernelConfigPath{kernelArg.begin() + ind + 1, kernelArg.end()};
387 Version kernelVer;
388 if (!parse(kernelVerStr, &kernelVer)) {
389 std::cerr << "Unrecognized kernel version '" << kernelVerStr << "'" << std::endl;
390 return false;
391 }
392 mKernels.push_back({{kernelVer.majorVer, kernelVer.minorVer, 0u}, kernelConfigPath});
393 return true;
394 }
395
Yifan Hong9aa63702017-05-16 16:37:50 -0700396 private:
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700397 std::vector<std::string> mInFilePaths;
398 std::vector<std::ifstream> mInFiles;
Yifan Hong9aa63702017-05-16 16:37:50 -0700399 std::unique_ptr<std::ofstream> mOutFileRef;
400 std::ifstream mCheckFile;
401 bool mOutputMatrix = false;
Yifan Hong79efa8a2017-07-06 14:10:28 -0700402 std::vector<std::pair<KernelVersion, std::string>> mKernels;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000403};
404
405} // namespace vintf
406} // namespace android
407
408void help() {
Yifan Hong9aa63702017-05-16 16:37:50 -0700409 std::cerr << "assemble_vintf: Checks if a given manifest / matrix file is valid and \n"
410 " fill in build-time flags into the given file.\n"
411 "assemble_vintf -h\n"
412 " Display this help text.\n"
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700413 "assemble_vintf -i <input file>[:<input file>[...]] [-o <output file>] [-m]\n"
414 " [-c [<check file>]]\n"
Yifan Hong9aa63702017-05-16 16:37:50 -0700415 " Fill in build-time flags into the given file.\n"
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700416 " -i <input file>[:<input file>[...]]\n"
417 " A list of input files. Format is automatically detected for the\n"
418 " first file, and the remaining files must have the same format.\n"
419 " Files other than the first file should only have <hal> defined;\n"
420 " other entries are ignored.\n"
Yifan Hong9aa63702017-05-16 16:37:50 -0700421 " -o <output file>\n"
422 " Optional output file. If not specified, write to stdout.\n"
423 " -m\n"
424 " a compatible compatibility matrix is\n"
425 " generated instead; for example, given a device manifest,\n"
426 " a framework compatibility matrix is generated. This flag\n"
427 " is ignored when input is a compatibility matrix.\n"
428 " -c [<check file>]\n"
429 " After writing the output file, check compatibility between\n"
430 " output file and check file.\n"
431 " If -c is set but the check file is not specified, a warning\n"
432 " message is written to stderr. Return 0.\n"
433 " If the check file is specified but is not compatible, an error\n"
Yifan Hong79efa8a2017-07-06 14:10:28 -0700434 " message is written to stderr. Return 1.\n"
Steve Muckle0bef8682017-07-31 15:47:15 -0700435 " --kernel=<version>:<android-base.cfg>[:<android-base-arch.cfg>[...]]\n"
Yifan Hong79efa8a2017-07-06 14:10:28 -0700436 " Add a kernel entry to framework compatibility matrix.\n"
437 " Ignored for other input format.\n"
438 " <version> has format: 3.18\n"
Steve Muckle0bef8682017-07-31 15:47:15 -0700439 " <android-base.cfg> is the location of android-base.cfg\n"
440 " <android-base-arch.cfg> is the location of an optional\n"
441 " arch-specific config fragment, more than one may be specified\n";
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000442}
443
444int main(int argc, char **argv) {
Yifan Hong79efa8a2017-07-06 14:10:28 -0700445 const struct option longopts[] = {{"kernel", required_argument, NULL, 'k'}, {0, 0, 0, 0}};
Yifan Hong9aa63702017-05-16 16:37:50 -0700446
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700447 std::string outFilePath;
Yifan Hong9aa63702017-05-16 16:37:50 -0700448 ::android::vintf::AssembleVintf assembleVintf;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000449 int res;
Yifan Hong9aa63702017-05-16 16:37:50 -0700450 int optind;
451 while ((res = getopt_long(argc, argv, "hi:o:mc:", longopts, &optind)) >= 0) {
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000452 switch (res) {
453 case 'i': {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700454 char* inFilePath = strtok(optarg, ":");
455 while (inFilePath != NULL) {
456 if (!assembleVintf.openInFile(inFilePath)) {
457 std::cerr << "Failed to open " << optarg << std::endl;
458 return 1;
459 }
460 inFilePath = strtok(NULL, ":");
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000461 }
462 } break;
463
464 case 'o': {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700465 outFilePath = optarg;
Yifan Hong9aa63702017-05-16 16:37:50 -0700466 if (!assembleVintf.openOutFile(optarg)) {
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000467 std::cerr << "Failed to open " << optarg << std::endl;
468 return 1;
469 }
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000470 } break;
471
Yifan Honga59d2562017-04-18 18:01:16 -0700472 case 'm': {
Yifan Hong9aa63702017-05-16 16:37:50 -0700473 assembleVintf.setOutputMatrix();
Yifan Honga59d2562017-04-18 18:01:16 -0700474 } break;
475
Yifan Hong4650ad82017-05-01 17:28:02 -0700476 case 'c': {
477 if (strlen(optarg) != 0) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700478 if (!assembleVintf.openCheckFile(optarg)) {
Yifan Hong4650ad82017-05-01 17:28:02 -0700479 std::cerr << "Failed to open " << optarg << std::endl;
480 return 1;
481 }
482 } else {
483 std::cerr << "WARNING: no compatibility check is done on "
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700484 << (outFilePath.empty() ? "output" : outFilePath) << std::endl;
Yifan Hong4650ad82017-05-01 17:28:02 -0700485 }
486 } break;
487
Yifan Hong79efa8a2017-07-06 14:10:28 -0700488 case 'k': {
489 if (!assembleVintf.addKernel(optarg)) {
490 std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl;
491 return 1;
492 }
493 } break;
494
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000495 case 'h':
496 default: {
497 help();
498 return 1;
499 } break;
500 }
501 }
502
Yifan Hong9aa63702017-05-16 16:37:50 -0700503 bool success = assembleVintf.assemble();
Yifan Hong4650ad82017-05-01 17:28:02 -0700504
505 return success ? 0 : 1;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000506}