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