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 17 #include <getopt.h> 18 19 #include <iostream> 20 21 #include <android-base/strings.h> 22 #include <vintf/AssembleVintf.h> 23 #include "utils.h" 24 25 void help() { 26 std::cerr << "assemble_vintf: Checks if a given manifest / matrix file is valid and \n" 27 " fill in build-time flags into the given file.\n" 28 "assemble_vintf -h\n" 29 " Display this help text.\n" 30 "assemble_vintf -i <input file>[:<input file>[...]] [-o <output file>] [-m]\n" 31 " [-c [<check file>]]\n" 32 " Fill in build-time flags into the given file.\n" 33 " -i <input file>[:<input file>[...]]\n" 34 " A list of input files. Format is automatically detected for the\n" 35 " first file, and the remaining files must have the same format.\n" 36 " Files other than the first file should only have <hal> defined;\n" 37 " other entries are ignored.\n" 38 " -o <output file>\n" 39 " Optional output file. If not specified, write to stdout.\n" 40 " -m\n" 41 " a compatible compatibility matrix is\n" 42 " generated instead; for example, given a device manifest,\n" 43 " a framework compatibility matrix is generated. This flag\n" 44 " is ignored when input is a compatibility matrix.\n" 45 " -c [<check file>]\n" 46 " After writing the output file, check compatibility between\n" 47 " output file and check file.\n" 48 " If -c is set but the check file is not specified, a warning\n" 49 " message is written to stderr. Return 0.\n" 50 " If the check file is specified but is not compatible, an error\n" 51 " message is written to stderr. Return 1.\n" 52 " --kernel=<version>:<android-base.cfg>[:<android-base-arch.cfg>[...]]\n" 53 " Add a kernel entry to framework compatibility matrix.\n" 54 " Ignored for other input format.\n" 55 " <version> has format: 3.18\n" 56 " <android-base.cfg> is the location of android-base.cfg\n" 57 " <android-base-arch.cfg> is the location of an optional\n" 58 " arch-specific config fragment, more than one may be specified\n" 59 " -l, --hals-only\n" 60 " Output has only <hal> entries. Cannot be used with -n.\n" 61 " -n, --no-hals\n" 62 " Output has no <hal> entries (but all other entries).\n" 63 " Cannot be used with -l.\n"; 64 } 65 66 int main(int argc, char** argv) { 67 using namespace ::android::vintf; 68 const struct option longopts[] = {{"kernel", required_argument, NULL, 'k'}, 69 {"hals-only", no_argument, NULL, 'l'}, 70 {"no-hals", no_argument, NULL, 'n'}, 71 {0, 0, 0, 0}}; 72 73 std::string outFilePath; 74 auto assembleVintf = AssembleVintf::newInstance(); 75 int res; 76 int optind; 77 while ((res = getopt_long(argc, argv, "hi:o:mc:nl", longopts, &optind)) >= 0) { 78 switch (res) { 79 case 'i': { 80 for (const auto& inFilePath : ::android::base::Split(optarg, ":")) { 81 if (!assembleVintf->openInFile(inFilePath.c_str())) { 82 std::cerr << "Failed to open " << inFilePath << std::endl; 83 return 1; 84 } 85 } 86 } break; 87 88 case 'o': { 89 outFilePath = optarg; 90 if (!assembleVintf->openOutFile(optarg)) { 91 std::cerr << "Failed to open " << optarg << std::endl; 92 return 1; 93 } 94 } break; 95 96 case 'm': { 97 assembleVintf->setOutputMatrix(); 98 } break; 99 100 case 'c': { 101 if (!assembleVintf->openCheckFile(optarg)) { 102 std::cerr << "Failed to open " << optarg << std::endl; 103 return 1; 104 } 105 } break; 106 107 case 'k': { 108 if (!assembleVintf->addKernel(optarg)) { 109 std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl; 110 return 1; 111 } 112 } break; 113 114 case 'l': { 115 if (!assembleVintf->setHalsOnly()) { 116 return 1; 117 } 118 } break; 119 120 case 'n': { 121 if (!assembleVintf->setNoHals()) { 122 return 1; 123 } 124 } break; 125 126 case 'h': 127 default: { 128 help(); 129 return 1; 130 } break; 131 } 132 } 133 134 bool success = assembleVintf->assemble(); 135 136 return success ? 0 : 1; 137 } 138