blob: d74cc0312ccb9718944c70629aa10c56c1f20f32 [file] [log] [blame]
Yifan Hong8302cea2017-12-18 20:17:05 -08001/*
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
Yifan Hongb83e56b2018-01-09 14:36:30 -080021#include <android-base/strings.h>
Yifan Hong8302cea2017-12-18 20:17:05 -080022#include <vintf/AssembleVintf.h>
23#include "utils.h"
24
25void 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"
Steven Moreland34f74052018-04-05 11:39:35 -070037 " other entries are ignored. Argument may also be specified\n"
38 " multiple times.\n"
Yifan Hong8302cea2017-12-18 20:17:05 -080039 " -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"
Yifan Hongbe95df72018-04-30 15:02:31 -070047 " 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"
Yifan Hongbe95df72018-04-30 15:02:31 -070052 " If any check fails, an error message is written to stderr.\n"
53 " Return 1.\n"
Steve Mucklead6aa912018-07-23 15:44:01 -070054 " --kernel=<version>:<android-base.config>[:<android-base-arch.config>[...]]\n"
Yifan Honga45f77d2018-12-03 16:42:52 -080055 " 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"
Yifan Hongbe95df72018-04-30 15:02:31 -070060 " <version> has format: 3.18.0\n"
Steve Mucklead6aa912018-07-23 15:44:01 -070061 " <android-base.config> is the location of android-base.config\n"
62 " <android-base-arch.config> is the location of an optional\n"
Yifan Hong8302cea2017-12-18 20:17:05 -080063 " 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"
Yifan Hong86678e42018-07-26 11:38:54 -070068 " 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";
Yifan Hong8302cea2017-12-18 20:17:05 -080072}
73
74int 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'},
Yifan Hong86678e42018-07-26 11:38:54 -070079 {"no-kernel-requirements", no_argument, NULL, 'K'},
Yifan Hong8302cea2017-12-18 20:17:05 -080080 {0, 0, 0, 0}};
81
82 std::string outFilePath;
83 auto assembleVintf = AssembleVintf::newInstance();
84 int res;
85 int optind;
86 while ((res = getopt_long(argc, argv, "hi:o:mc:nl", longopts, &optind)) >= 0) {
87 switch (res) {
88 case 'i': {
Yifan Hongb83e56b2018-01-09 14:36:30 -080089 for (const auto& inFilePath : ::android::base::Split(optarg, ":")) {
Yifan Hong8302cea2017-12-18 20:17:05 -080090 if (!assembleVintf->openInFile(inFilePath.c_str())) {
91 std::cerr << "Failed to open " << inFilePath << std::endl;
92 return 1;
93 }
94 }
95 } break;
96
97 case 'o': {
98 outFilePath = optarg;
99 if (!assembleVintf->openOutFile(optarg)) {
100 std::cerr << "Failed to open " << optarg << std::endl;
101 return 1;
102 }
103 } break;
104
105 case 'm': {
106 assembleVintf->setOutputMatrix();
107 } break;
108
109 case 'c': {
110 if (!assembleVintf->openCheckFile(optarg)) {
111 std::cerr << "Failed to open " << optarg << std::endl;
112 return 1;
113 }
114 } break;
115
116 case 'k': {
117 if (!assembleVintf->addKernel(optarg)) {
118 std::cerr << "ERROR: Unrecognized --kernel argument." << std::endl;
119 return 1;
120 }
121 } break;
122
123 case 'l': {
124 if (!assembleVintf->setHalsOnly()) {
125 return 1;
126 }
127 } break;
128
129 case 'n': {
130 if (!assembleVintf->setNoHals()) {
131 return 1;
132 }
133 } break;
134
Yifan Hong86678e42018-07-26 11:38:54 -0700135 case 'K': {
136 if (!assembleVintf->setNoKernelRequirements()) {
137 return 1;
138 }
139 } break;
140
Yifan Hong8302cea2017-12-18 20:17:05 -0800141 case 'h':
142 default: {
143 help();
144 return 1;
145 } break;
146 }
147 }
148
149 bool success = assembleVintf->assemble();
150
151 return success ? 0 : 1;
152}