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
help()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. Argument may also be specified\n"
38 " multiple times.\n"
39 " -o <output file>\n"
40 " Optional output file. If not specified, write to stdout.\n"
41 " -m\n"
42 " a compatible compatibility matrix is\n"
43 " generated instead; for example, given a device manifest,\n"
44 " a framework compatibility matrix is generated. This flag\n"
45 " is ignored when input is a compatibility matrix.\n"
46 " -c [<check file>]\n"
47 " The path of the \"check file\"; for example, this is the path\n"
48 " of the device manifest for framework compatibility matrix.\n"
49 " After writing the output file, the program checks against\n"
50 " the \"check file\", depending on environment variables.\n"
51 " - PRODUCT_ENFORCE_VINTF_MANIFEST=true: check compatibility\n"
52 " - VINTF_ENFORCE_NO_UNUSED_HALS =true: check unused HALs\n"
53 " If any check fails, an error message is written to stderr.\n"
54 " Return 1.\n"
55 " --kernel=<version>:<android-base.config>[:<android-base-arch.config>[...]]\n"
56 " Add a kernel entry to framework compatibility matrix or device\n"
57 " manifest. Ignored for other input format.\n"
58 " There can be any number of --kernel for framework compatibility\n"
59 " matrix, but at most one --kernel and at most one config file for\n"
60 " device manifest.\n"
61 " <version> has format: 3.18.0\n"
62 " <android-base.config> is the location of android-base.config\n"
63 " <android-base-arch.config> is the location of an optional\n"
64 " arch-specific config fragment, more than one may be specified\n"
65 " -l, --hals-only\n"
66 " Output has only <hal> entries. Cannot be used with -n.\n"
67 " -n, --no-hals\n"
68 " Output has no <hal> entries (but all other entries).\n"
69 " Cannot be used with -l.\n"
70 " --no-kernel-requirements\n"
71 " Output has no <config> entries in <kernel>, and kernel minor\n"
72 " version is set to zero. (For example, 3.18.0).\n";
73 }
74
main(int argc,char ** argv)75 int main(int argc, char** argv) {
76 using namespace ::android::vintf;
77 const struct option longopts[] = {{"kernel", required_argument, NULL, 'k'},
78 {"hals-only", no_argument, NULL, 'l'},
79 {"no-hals", no_argument, NULL, 'n'},
80 {"no-kernel-requirements", no_argument, NULL, 'K'},
81 {0, 0, 0, 0}};
82
83 std::string outFilePath;
84 auto assembleVintf = AssembleVintf::newInstance();
85 int res;
86 int optind;
87 while ((res = getopt_long(argc, argv, "hi:o:mc:nl", longopts, &optind)) >= 0) {
88 switch (res) {
89 case 'i': {
90 for (const auto& inFilePath : ::android::base::Split(optarg, ":")) {
91 if (!assembleVintf->openInFile(inFilePath.c_str())) {
92 std::cerr << "Failed to open " << inFilePath << std::endl;
93 return 1;
94 }
95 }
96 } break;
97
98 case 'o': {
99 outFilePath = optarg;
100 if (!assembleVintf->openOutFile(optarg)) {
101 std::cerr << "Failed to open " << optarg << std::endl;
102 return 1;
103 }
104 } break;
105
106 case 'm': {
107 assembleVintf->setOutputMatrix();
108 } break;
109
110 case 'c': {
111 if (!assembleVintf->openCheckFile(optarg)) {
112 std::cerr << "Failed to open " << optarg << std::endl;
113 return 1;
114 }
115 } break;
116
117 case 'k': {
118 if (!assembleVintf->addKernel(optarg)) {
119 std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl;
120 return 1;
121 }
122 } break;
123
124 case 'l': {
125 if (!assembleVintf->setHalsOnly()) {
126 return 1;
127 }
128 } break;
129
130 case 'n': {
131 if (!assembleVintf->setNoHals()) {
132 return 1;
133 }
134 } break;
135
136 case 'K': {
137 if (!assembleVintf->setNoKernelRequirements()) {
138 return 1;
139 }
140 } break;
141
142 case 'h':
143 default: {
144 help();
145 return 1;
146 } break;
147 }
148 }
149
150 bool success = assembleVintf->assemble();
151
152 return success ? 0 : 1;
153 }
154