blob: a954acde28eda04f11e37b7e2ea1b9fb71790775 [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
17#include <stdlib.h>
18#include <unistd.h>
19
20#include <fstream>
21#include <iostream>
Yifan Hong4d18bcc2017-04-07 21:47:16 +000022#include <sstream>
23#include <string>
Yifan Hong8302cea2017-12-18 20:17:05 -080024#include <unordered_map>
Yifan Hong4d18bcc2017-04-07 21:47:16 +000025
Yifan Hong9a8b1a72017-08-25 17:55:33 -070026#include <android-base/file.h>
Yifan Hongdbe9db32017-12-11 19:06:11 -080027#include <android-base/parseint.h>
Yifan Hongb83e56b2018-01-09 14:36:30 -080028#include <android-base/strings.h>
Yifan Hong9a8b1a72017-08-25 17:55:33 -070029
Yifan Hong8302cea2017-12-18 20:17:05 -080030#include <vintf/AssembleVintf.h>
Yifan Hong79efa8a2017-07-06 14:10:28 -070031#include <vintf/KernelConfigParser.h>
Yifan Hong4d18bcc2017-04-07 21:47:16 +000032#include <vintf/parse_string.h>
33#include <vintf/parse_xml.h>
Yifan Hong8302cea2017-12-18 20:17:05 -080034#include "utils.h"
Yifan Hong4d18bcc2017-04-07 21:47:16 +000035
Yifan Hong79efa8a2017-07-06 14:10:28 -070036#define BUFFER_SIZE sysconf(_SC_PAGESIZE)
37
Yifan Hong4d18bcc2017-04-07 21:47:16 +000038namespace android {
39namespace vintf {
40
Yifan Hong9a8b1a72017-08-25 17:55:33 -070041static const std::string gConfigPrefix = "android-base-";
Steve Mucklead6aa912018-07-23 15:44:01 -070042static const std::string gConfigSuffix = ".config";
43static const std::string gBaseConfig = "android-base.config";
Yifan Hong9a8b1a72017-08-25 17:55:33 -070044
Yifan Hongaa219f52017-12-18 18:51:59 -080045// An input stream with a name.
46// The input stream may be an actual file, or a stringstream for testing.
47// It takes ownership on the istream.
48class NamedIstream {
49 public:
50 NamedIstream(const std::string& name, std::unique_ptr<std::istream>&& stream)
51 : mName(name), mStream(std::move(stream)) {}
52 const std::string& name() const { return mName; }
53 std::istream& stream() { return *mStream; }
54
55 private:
56 std::string mName;
57 std::unique_ptr<std::istream> mStream;
58};
59
Yifan Hong4d18bcc2017-04-07 21:47:16 +000060/**
61 * Slurps the device manifest file and add build time flag to it.
62 */
Yifan Hong8302cea2017-12-18 20:17:05 -080063class AssembleVintfImpl : public AssembleVintf {
Yifan Hong9a8b1a72017-08-25 17:55:33 -070064 using Condition = std::unique_ptr<KernelConfig>;
65 using ConditionedConfig = std::pair<Condition, std::vector<KernelConfig> /* configs */>;
66
67 public:
Yifan Hong8302cea2017-12-18 20:17:05 -080068 void setFakeEnv(const std::string& key, const std::string& value) { mFakeEnv[key] = value; }
69
70 std::string getEnv(const std::string& key) const {
71 auto it = mFakeEnv.find(key);
72 if (it != mFakeEnv.end()) {
73 return it->second;
74 }
75 const char* envValue = getenv(key.c_str());
76 return envValue != nullptr ? std::string(envValue) : std::string();
77 }
78
Yifan Honga28729e2018-01-17 13:40:35 -080079 // Get environment variable and split with space.
80 std::vector<std::string> getEnvList(const std::string& key) const {
81 std::vector<std::string> ret;
82 for (auto&& v : base::Split(getEnv(key), " ")) {
83 v = base::Trim(v);
84 if (!v.empty()) {
85 ret.push_back(v);
86 }
87 }
88 return ret;
89 }
90
Yifan Hong8302cea2017-12-18 20:17:05 -080091 template <typename T>
Yifan Hong4dec91d2018-08-13 12:37:47 -070092 bool getFlag(const std::string& key, T* value, bool log = true) const {
Yifan Hong8302cea2017-12-18 20:17:05 -080093 std::string envValue = getEnv(key);
94 if (envValue.empty()) {
Yifan Hong4dec91d2018-08-13 12:37:47 -070095 if (log) {
96 std::cerr << "Warning: " << key << " is missing, defaulted to " << (*value) << "."
97 << std::endl;
98 }
Yifan Hong488e16a2017-07-11 13:50:41 -070099 return true;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000100 }
101
102 if (!parse(envValue, value)) {
103 std::cerr << "Cannot parse " << envValue << "." << std::endl;
104 return false;
105 }
106 return true;
107 }
108
Yifan Hongeff04662017-12-18 16:27:24 -0800109 /**
Yifan Hong0f7f7282018-02-02 13:05:43 -0800110 * Set *out to environment variable only if *out is a dummy value (i.e. default constructed).
Yifan Hongce355902019-06-26 17:06:52 +0000111 * Return false if a fatal error has occurred:
112 * - The environment variable has an unknown format
113 * - The value of the environment variable does not match a predefined variable in the files
Yifan Hongeff04662017-12-18 16:27:24 -0800114 */
115 template <typename T>
Yifan Hongce355902019-06-26 17:06:52 +0000116 bool getFlagIfUnset(const std::string& envKey, T* out) const {
Yifan Hongeff04662017-12-18 16:27:24 -0800117 bool hasExistingValue = !(*out == T{});
118
119 bool hasEnvValue = false;
120 T envValue;
Yifan Hong8302cea2017-12-18 20:17:05 -0800121 std::string envStrValue = getEnv(envKey);
122 if (!envStrValue.empty()) {
123 if (!parse(envStrValue, &envValue)) {
Yifan Hongb36e85f2019-06-26 17:06:52 +0000124 std::cerr << "Cannot parse " << envValue << "." << std::endl;
Yifan Hongce355902019-06-26 17:06:52 +0000125 return false;
Yifan Hongeff04662017-12-18 16:27:24 -0800126 }
127 hasEnvValue = true;
128 }
129
130 if (hasExistingValue) {
Yifan Hongb36e85f2019-06-26 17:06:52 +0000131 if (hasEnvValue && (*out != envValue)) {
Yifan Hongce355902019-06-26 17:06:52 +0000132 std::cerr << "Cannot override existing value " << *out << " with " << envKey
133 << " (which is " << envValue << ")." << std::endl;
134 return false;
Yifan Hongeff04662017-12-18 16:27:24 -0800135 }
Yifan Hongce355902019-06-26 17:06:52 +0000136 return true;
Yifan Hongeff04662017-12-18 16:27:24 -0800137 }
Yifan Hongb36e85f2019-06-26 17:06:52 +0000138 if (hasEnvValue) {
139 *out = envValue;
Yifan Hongeff04662017-12-18 16:27:24 -0800140 }
Yifan Hongce355902019-06-26 17:06:52 +0000141 return true;
Yifan Hongeff04662017-12-18 16:27:24 -0800142 }
143
Yifan Hong8302cea2017-12-18 20:17:05 -0800144 bool getBooleanFlag(const std::string& key) const { return getEnv(key) == std::string("true"); }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800145
Yifan Hong8302cea2017-12-18 20:17:05 -0800146 size_t getIntegerFlag(const std::string& key, size_t defaultValue = 0) const {
147 std::string envValue = getEnv(key);
Yifan Hongdbe9db32017-12-11 19:06:11 -0800148 if (envValue.empty()) {
149 return defaultValue;
150 }
151 size_t value;
152 if (!base::ParseUint(envValue, &value)) {
153 std::cerr << "Error: " << key << " must be a number." << std::endl;
154 return defaultValue;
155 }
156 return value;
157 }
158
Yifan Hong4650ad82017-05-01 17:28:02 -0700159 static std::string read(std::basic_istream<char>& is) {
160 std::stringstream ss;
161 ss << is.rdbuf();
162 return ss.str();
163 }
164
Yifan Hong4072b252020-03-27 16:54:16 -0700165 // Return true if name of file is "android-base.config". This file must be specified
166 // exactly once for each kernel version. These requirements do not have any conditions.
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700167 static bool isCommonConfig(const std::string& path) {
168 return ::android::base::Basename(path) == gBaseConfig;
169 }
170
Yifan Hong4072b252020-03-27 16:54:16 -0700171 // Return true if name of file matches "android-base-foo.config".
172 // Zero or more conditional configs may be specified for each kernel version. These
173 // requirements are conditional on CONFIG_FOO=y.
174 static bool isConditionalConfig(const std::string& path) {
175 auto fname = ::android::base::Basename(path);
176 return ::android::base::StartsWith(fname, gConfigPrefix) &&
177 ::android::base::EndsWith(fname, gConfigSuffix);
178 }
179
180 // Return true for all other file names (i.e. not android-base.config, and not conditional
181 // configs.)
182 // Zero or more conditional configs may be specified for each kernel version.
183 // These requirements do not have any conditions.
184 static bool isExtraCommonConfig(const std::string& path) {
185 return !isCommonConfig(path) && !isConditionalConfig(path);
186 }
187
Yifan Hong079ec242017-08-25 18:53:38 -0700188 // nullptr on any error, otherwise the condition.
189 static Condition generateCondition(const std::string& path) {
Yifan Hong4072b252020-03-27 16:54:16 -0700190 if (!isConditionalConfig(path)) {
Yifan Hong079ec242017-08-25 18:53:38 -0700191 return nullptr;
192 }
Yifan Hong4072b252020-03-27 16:54:16 -0700193 auto fname = ::android::base::Basename(path);
Yifan Hong079ec242017-08-25 18:53:38 -0700194 std::string sub = fname.substr(gConfigPrefix.size(),
195 fname.size() - gConfigPrefix.size() - gConfigSuffix.size());
196 if (sub.empty()) {
197 return nullptr; // should not happen
198 }
199 for (size_t i = 0; i < sub.size(); ++i) {
200 if (sub[i] == '-') {
201 sub[i] = '_';
202 continue;
203 }
204 if (isalnum(sub[i])) {
205 sub[i] = toupper(sub[i]);
206 continue;
207 }
208 std::cerr << "'" << fname << "' (in " << path
209 << ") is not a valid kernel config file name. Must match regex: "
Steve Mucklead6aa912018-07-23 15:44:01 -0700210 << "android-base(-[0-9a-zA-Z-]+)?\\" << gConfigSuffix
211 << std::endl;
Yifan Hong079ec242017-08-25 18:53:38 -0700212 return nullptr;
213 }
214 sub.insert(0, "CONFIG_");
215 return std::make_unique<KernelConfig>(std::move(sub), Tristate::YES);
216 }
217
Yifan Hong8302cea2017-12-18 20:17:05 -0800218 static bool parseFileForKernelConfigs(std::basic_istream<char>& stream,
219 std::vector<KernelConfig>* out) {
Yifan Hong02e94002017-07-10 15:41:56 -0700220 KernelConfigParser parser(true /* processComments */, true /* relaxedFormat */);
Yifan Honga45f77d2018-12-03 16:42:52 -0800221 status_t err = parser.processAndFinish(read(stream));
Yifan Hong79efa8a2017-07-06 14:10:28 -0700222 if (err != OK) {
Yifan Hongae53a0e2017-07-07 15:19:06 -0700223 std::cerr << parser.error();
Yifan Hong79efa8a2017-07-06 14:10:28 -0700224 return false;
225 }
226
227 for (auto& configPair : parser.configs()) {
228 out->push_back({});
229 KernelConfig& config = out->back();
230 config.first = std::move(configPair.first);
231 if (!parseKernelConfigTypedValue(configPair.second, &config.second)) {
232 std::cerr << "Unknown value type for key = '" << config.first << "', value = '"
233 << configPair.second << "'\n";
234 return false;
235 }
236 }
237 return true;
238 }
239
Yifan Hong8302cea2017-12-18 20:17:05 -0800240 static bool parseFilesForKernelConfigs(std::vector<NamedIstream>* streams,
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700241 std::vector<ConditionedConfig>* out) {
242 out->clear();
243 ConditionedConfig commonConfig;
244 bool foundCommonConfig = false;
Steve Muckle0bef8682017-07-31 15:47:15 -0700245 bool ret = true;
Yifan Hong8302cea2017-12-18 20:17:05 -0800246
247 for (auto& namedStream : *streams) {
Yifan Hong4072b252020-03-27 16:54:16 -0700248 if (isCommonConfig(namedStream.name()) || isExtraCommonConfig(namedStream.name())) {
249 if (!parseFileForKernelConfigs(namedStream.stream(), &commonConfig.second)) {
250 std::cerr << "Failed to generate common configs for file "
251 << namedStream.name();
252 ret = false;
253 }
254 if (isCommonConfig(namedStream.name())) {
255 foundCommonConfig = true;
256 }
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700257 } else {
Yifan Hong8302cea2017-12-18 20:17:05 -0800258 Condition condition = generateCondition(namedStream.name());
Yifan Hong4072b252020-03-27 16:54:16 -0700259 if (condition == nullptr) {
260 std::cerr << "Failed to generate conditional configs for file "
261 << namedStream.name();
262 ret = false;
263 }
Yifan Hong079ec242017-08-25 18:53:38 -0700264
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700265 std::vector<KernelConfig> kernelConfigs;
Yifan Hong8302cea2017-12-18 20:17:05 -0800266 if ((ret &= parseFileForKernelConfigs(namedStream.stream(), &kernelConfigs)))
Yifan Hong079ec242017-08-25 18:53:38 -0700267 out->emplace_back(std::move(condition), std::move(kernelConfigs));
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700268 }
Steve Muckle0bef8682017-07-31 15:47:15 -0700269 }
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700270
271 if (!foundCommonConfig) {
Steve Mucklead6aa912018-07-23 15:44:01 -0700272 std::cerr << "No " << gBaseConfig << " is found in these paths:" << std::endl;
Yifan Hong8302cea2017-12-18 20:17:05 -0800273 for (auto& namedStream : *streams) {
274 std::cerr << " " << namedStream.name() << std::endl;
275 }
Yifan Hong4072b252020-03-27 16:54:16 -0700276 ret = false;
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700277 }
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700278 // first element is always common configs (no conditions).
279 out->insert(out->begin(), std::move(commonConfig));
Steve Muckle0bef8682017-07-31 15:47:15 -0700280 return ret;
281 }
282
Yifan Hong8302cea2017-12-18 20:17:05 -0800283 std::basic_ostream<char>& out() const { return mOutRef == nullptr ? std::cout : *mOutRef; }
Yifan Hong9aa63702017-05-16 16:37:50 -0700284
Yifan Hong1044fd12018-02-27 14:51:54 -0800285 // If -c is provided, check it.
286 bool checkDualFile(const HalManifest& manifest, const CompatibilityMatrix& matrix) {
287 if (getBooleanFlag("PRODUCT_ENFORCE_VINTF_MANIFEST")) {
288 std::string error;
Yifan Hong3f743912019-12-17 14:12:04 -0800289 if (!manifest.checkCompatibility(matrix, &error, mCheckFlags)) {
Yifan Hong1044fd12018-02-27 14:51:54 -0800290 std::cerr << "Not compatible: " << error << std::endl;
291 return false;
292 }
293 }
Yifan Hong1044fd12018-02-27 14:51:54 -0800294 return true;
295 }
296
Yifan Hongdbe9db32017-12-11 19:06:11 -0800297 template <typename S>
Yifan Hongffcaf992018-01-09 17:08:51 -0800298 using Schemas = std::vector<Named<S>>;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800299 using HalManifests = Schemas<HalManifest>;
300 using CompatibilityMatrices = Schemas<CompatibilityMatrix>;
301
Steven Moreland5875afc2018-04-05 13:14:08 -0700302 template <typename M>
303 void outputInputs(const Schemas<M>& inputs) {
304 out() << "<!--" << std::endl;
305 out() << " Input:" << std::endl;
306 for (const auto& e : inputs) {
307 if (!e.name.empty()) {
308 out() << " " << base::Basename(e.name) << std::endl;
309 }
310 }
311 out() << "-->" << std::endl;
312 }
313
Yifan Honga45f77d2018-12-03 16:42:52 -0800314 // Parse --kernel arguments and write to output manifest.
315 bool setDeviceManifestKernel(HalManifest* manifest) {
316 if (mKernels.empty()) {
317 return true;
318 }
319 if (mKernels.size() > 1) {
320 std::cerr << "Warning: multiple --kernel is specified when building device manifest. "
321 << "Only the first one will be used." << std::endl;
322 }
323 auto& kernelArg = *mKernels.begin();
324 const auto& kernelVer = kernelArg.first;
325 auto& kernelConfigFiles = kernelArg.second;
326 // addKernel() guarantees that !kernelConfigFiles.empty().
327 if (kernelConfigFiles.size() > 1) {
328 std::cerr << "Warning: multiple config files are specified in --kernel when building "
329 << "device manfiest. Only the first one will be used." << std::endl;
330 }
331
332 KernelConfigParser parser(true /* processComments */, false /* relaxedFormat */);
333 status_t err = parser.processAndFinish(read(kernelConfigFiles[0].stream()));
334 if (err != OK) {
335 std::cerr << parser.error();
336 return false;
337 }
Yifan Hong08a48712019-12-11 14:56:00 -0800338
339 // Set version and configs in manifest.
340 auto kernel_info = std::make_optional<KernelInfo>();
341 kernel_info->mVersion = kernelVer;
342 kernel_info->mConfigs = parser.configs();
343 std::string error;
344 if (!manifest->mergeKernel(&kernel_info, &error)) {
345 std::cerr << error << "\n";
346 return false;
347 }
348
Yifan Honga45f77d2018-12-03 16:42:52 -0800349 return true;
350 }
351
Yifan Hong08a48712019-12-11 14:56:00 -0800352 void inferDeviceManifestKernelFcm(HalManifest* manifest) {
353 // No target FCM version.
354 if (manifest->level() == Level::UNSPECIFIED) return;
355 // target FCM version < R: leave value untouched.
356 if (manifest->level() < Level::R) return;
357 // No need to infer when <kernel> tag is missing.
358 if (!manifest->kernel().has_value()) return;
359 // Kernel FCM already set.
360 if (manifest->kernel()->level() != Level::UNSPECIFIED) return;
361
362 manifest->device.mKernel->mLevel = manifest->level();
363 }
364
Yifan Hongdbe9db32017-12-11 19:06:11 -0800365 bool assembleHalManifest(HalManifests* halManifests) {
Yifan Hong4650ad82017-05-01 17:28:02 -0700366 std::string error;
Yifan Hongffcaf992018-01-09 17:08:51 -0800367 HalManifest* halManifest = &halManifests->front().object;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800368 for (auto it = halManifests->begin() + 1; it != halManifests->end(); ++it) {
Yifan Hongffcaf992018-01-09 17:08:51 -0800369 const std::string& path = it->name;
Yifan Hong0a35ab12018-06-29 11:32:57 -0700370 HalManifest& manifestToAdd = it->object;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800371
Yifan Hong0a35ab12018-06-29 11:32:57 -0700372 if (manifestToAdd.level() != Level::UNSPECIFIED) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800373 if (halManifest->level() == Level::UNSPECIFIED) {
Yifan Hong0a35ab12018-06-29 11:32:57 -0700374 halManifest->mLevel = manifestToAdd.level();
375 } else if (halManifest->level() != manifestToAdd.level()) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800376 std::cerr << "Inconsistent FCM Version in HAL manifests:" << std::endl
Yifan Hongffcaf992018-01-09 17:08:51 -0800377 << " File '" << halManifests->front().name << "' has level "
Yifan Hongdbe9db32017-12-11 19:06:11 -0800378 << halManifest->level() << std::endl
Yifan Hong0a35ab12018-06-29 11:32:57 -0700379 << " File '" << path << "' has level " << manifestToAdd.level()
Yifan Hongdbe9db32017-12-11 19:06:11 -0800380 << std::endl;
381 return false;
382 }
383 }
384
Yifan Hong4c6962d2019-01-30 15:50:46 -0800385 if (!halManifest->addAll(&manifestToAdd, &error)) {
386 std::cerr << "File \"" << path << "\" cannot be added: " << error << std::endl;
Yifan Hong0a35ab12018-06-29 11:32:57 -0700387 return false;
388 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800389 }
Yifan Hong9aa63702017-05-16 16:37:50 -0700390
391 if (halManifest->mType == SchemaType::DEVICE) {
Yifan Hongce355902019-06-26 17:06:52 +0000392 if (!getFlagIfUnset("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion)) {
393 return false;
394 }
Steven Morelandb1392772018-05-01 11:21:35 -0700395
Yifan Hongdbe9db32017-12-11 19:06:11 -0800396 if (!setDeviceFcmVersion(halManifest)) {
397 return false;
398 }
Yifan Honga45f77d2018-12-03 16:42:52 -0800399
400 if (!setDeviceManifestKernel(halManifest)) {
401 return false;
402 }
Yifan Hong08a48712019-12-11 14:56:00 -0800403
404 inferDeviceManifestKernelFcm(halManifest);
Yifan Hong9aa63702017-05-16 16:37:50 -0700405 }
406
Yifan Hongfeb454e2018-01-09 16:16:40 -0800407 if (halManifest->mType == SchemaType::FRAMEWORK) {
Yifan Honga28729e2018-01-17 13:40:35 -0800408 for (auto&& v : getEnvList("PROVIDED_VNDK_VERSIONS")) {
409 halManifest->framework.mVendorNdks.emplace_back(std::move(v));
410 }
411
Yifan Hong8b8492b2018-01-22 14:08:40 -0800412 for (auto&& v : getEnvList("PLATFORM_SYSTEMSDK_VERSIONS")) {
Yifan Honga28729e2018-01-17 13:40:35 -0800413 halManifest->framework.mSystemSdk.mVersions.emplace(std::move(v));
Yifan Hongfeb454e2018-01-09 16:16:40 -0800414 }
415 }
416
Steven Moreland5875afc2018-04-05 13:14:08 -0700417 outputInputs(*halManifests);
418
Yifan Hong9aa63702017-05-16 16:37:50 -0700419 if (mOutputMatrix) {
420 CompatibilityMatrix generatedMatrix = halManifest->generateCompatibleMatrix();
Yifan Hong3f743912019-12-17 14:12:04 -0800421 if (!halManifest->checkCompatibility(generatedMatrix, &error, mCheckFlags)) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700422 std::cerr << "FATAL ERROR: cannot generate a compatible matrix: " << error
423 << std::endl;
424 }
425 out() << "<!-- \n"
426 " Autogenerated skeleton compatibility matrix. \n"
427 " Use with caution. Modify it to suit your needs.\n"
428 " All HALs are set to optional.\n"
429 " Many entries other than HALs are zero-filled and\n"
430 " require human attention. \n"
431 "-->\n"
Yifan Honga2635c42017-12-12 13:20:33 -0800432 << gCompatibilityMatrixConverter(generatedMatrix, mSerializeFlags);
Yifan Hong9aa63702017-05-16 16:37:50 -0700433 } else {
Yifan Honga2635c42017-12-12 13:20:33 -0800434 out() << gHalManifestConverter(*halManifest, mSerializeFlags);
Yifan Hong9aa63702017-05-16 16:37:50 -0700435 }
436 out().flush();
437
Yifan Hong8302cea2017-12-18 20:17:05 -0800438 if (mCheckFile != nullptr) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700439 CompatibilityMatrix checkMatrix;
Yifan Hong94757062018-02-09 16:36:31 -0800440 if (!gCompatibilityMatrixConverter(&checkMatrix, read(*mCheckFile), &error)) {
441 std::cerr << "Cannot parse check file as a compatibility matrix: " << error
442 << std::endl;
Yifan Hong9aa63702017-05-16 16:37:50 -0700443 return false;
444 }
Yifan Hong1044fd12018-02-27 14:51:54 -0800445 if (!checkDualFile(*halManifest, checkMatrix)) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700446 return false;
447 }
448 }
449
450 return true;
451 }
452
Yifan Honge7837b12018-10-11 10:38:57 -0700453 // Parse --kernel arguments and write to output matrix.
Yifan Honge88e1672017-08-24 14:42:54 -0700454 bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) {
Yifan Hong8302cea2017-12-18 20:17:05 -0800455 for (auto& pair : mKernels) {
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700456 std::vector<ConditionedConfig> conditionedConfigs;
Yifan Hong8302cea2017-12-18 20:17:05 -0800457 if (!parseFilesForKernelConfigs(&pair.second, &conditionedConfigs)) {
Yifan Honge88e1672017-08-24 14:42:54 -0700458 return false;
459 }
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700460 for (ConditionedConfig& conditionedConfig : conditionedConfigs) {
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800461 MatrixKernel kernel(KernelVersion{pair.first}, std::move(conditionedConfig.second));
Yifan Hong079ec242017-08-25 18:53:38 -0700462 if (conditionedConfig.first != nullptr)
463 kernel.mConditions.push_back(std::move(*conditionedConfig.first));
Yifan Honge7837b12018-10-11 10:38:57 -0700464 std::string error;
465 if (!matrix->addKernel(std::move(kernel), &error)) {
466 std::cerr << "Error:" << error << std::endl;
467 return false;
468 };
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700469 }
Yifan Honge88e1672017-08-24 14:42:54 -0700470 }
471 return true;
472 }
473
Yifan Hongdbe9db32017-12-11 19:06:11 -0800474 bool setDeviceFcmVersion(HalManifest* manifest) {
Yifan Hong1e6e34c2018-03-22 16:38:09 -0700475 // Not needed for generating empty manifest for DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE.
Yifan Hong2eee1982018-03-29 10:55:30 -0700476 if (getBooleanFlag("VINTF_IGNORE_TARGET_FCM_VERSION")) {
Yifan Hong1e6e34c2018-03-22 16:38:09 -0700477 return true;
478 }
479
Yifan Hongdbe9db32017-12-11 19:06:11 -0800480 size_t shippingApiLevel = getIntegerFlag("PRODUCT_SHIPPING_API_LEVEL");
Yifan Hong9aa63702017-05-16 16:37:50 -0700481
Yifan Hongdbe9db32017-12-11 19:06:11 -0800482 if (manifest->level() != Level::UNSPECIFIED) {
483 return true;
484 }
485 if (!getBooleanFlag("PRODUCT_ENFORCE_VINTF_MANIFEST")) {
486 manifest->mLevel = Level::LEGACY;
487 return true;
488 }
489 // TODO(b/70628538): Do not infer from Shipping API level.
490 if (shippingApiLevel) {
491 std::cerr << "Warning: Shipping FCM Version is inferred from Shipping API level. "
492 << "Declare Shipping FCM Version in device manifest directly." << std::endl;
Yifan Hongafae1982018-01-11 18:15:24 -0800493 manifest->mLevel = details::convertFromApiLevel(shippingApiLevel);
Yifan Hongdbe9db32017-12-11 19:06:11 -0800494 if (manifest->mLevel == Level::UNSPECIFIED) {
495 std::cerr << "Error: Shipping FCM Version cannot be inferred from Shipping API "
496 << "level " << shippingApiLevel << "."
497 << "Declare Shipping FCM Version in device manifest directly."
498 << std::endl;
499 return false;
500 }
501 return true;
502 }
503 // TODO(b/69638851): should be an error if Shipping API level is not defined.
504 // For now, just leave it empty; when framework compatibility matrix is built,
505 // lowest FCM Version is assumed.
506 std::cerr << "Warning: Shipping FCM Version cannot be inferred, because:" << std::endl
507 << " (1) It is not explicitly declared in device manifest;" << std::endl
508 << " (2) PRODUCT_ENFORCE_VINTF_MANIFEST is set to true;" << std::endl
509 << " (3) PRODUCT_SHIPPING_API_LEVEL is undefined." << std::endl
510 << "Assuming 'unspecified' Shipping FCM Version. " << std::endl
511 << "To remove this warning, define 'level' attribute in device manifest."
512 << std::endl;
513 return true;
514 }
515
516 Level getLowestFcmVersion(const CompatibilityMatrices& matrices) {
517 Level ret = Level::UNSPECIFIED;
518 for (const auto& e : matrices) {
Yifan Hongffcaf992018-01-09 17:08:51 -0800519 if (ret == Level::UNSPECIFIED || ret > e.object.level()) {
520 ret = e.object.level();
Yifan Hongdbe9db32017-12-11 19:06:11 -0800521 }
522 }
523 return ret;
524 }
525
526 bool assembleCompatibilityMatrix(CompatibilityMatrices* matrices) {
527 std::string error;
528 CompatibilityMatrix* matrix = nullptr;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800529 std::unique_ptr<HalManifest> checkManifest;
Yifan Honge7837b12018-10-11 10:38:57 -0700530 std::unique_ptr<CompatibilityMatrix> builtMatrix;
531
532 if (mCheckFile != nullptr) {
533 checkManifest = std::make_unique<HalManifest>();
534 if (!gHalManifestConverter(checkManifest.get(), read(*mCheckFile), &error)) {
535 std::cerr << "Cannot parse check file as a HAL manifest: " << error << std::endl;
536 return false;
537 }
538 }
539
Yifan Hongffcaf992018-01-09 17:08:51 -0800540 if (matrices->front().object.mType == SchemaType::DEVICE) {
Yifan Hong5a51ea52019-04-22 14:54:57 -0700541 builtMatrix = CompatibilityMatrix::combineDeviceMatrices(matrices, &error);
542 matrix = builtMatrix.get();
543
544 if (matrix == nullptr) {
545 std::cerr << error << std::endl;
Yifan Honge7837b12018-10-11 10:38:57 -0700546 return false;
547 }
548
Yifan Hongfeb454e2018-01-09 16:16:40 -0800549 auto vndkVersion = base::Trim(getEnv("REQUIRED_VNDK_VERSION"));
550 if (!vndkVersion.empty()) {
551 auto& valueInMatrix = matrix->device.mVendorNdk;
552 if (!valueInMatrix.version().empty() && valueInMatrix.version() != vndkVersion) {
553 std::cerr << "Hard-coded <vendor-ndk> version in device compatibility matrix ("
554 << matrices->front().name << "), '" << valueInMatrix.version()
555 << "', does not match value inferred "
556 << "from BOARD_VNDK_VERSION '" << vndkVersion << "'" << std::endl;
557 return false;
558 }
559 valueInMatrix = VendorNdk{std::move(vndkVersion)};
560 }
Yifan Honga28729e2018-01-17 13:40:35 -0800561
562 for (auto&& v : getEnvList("BOARD_SYSTEMSDK_VERSIONS")) {
563 matrix->device.mSystemSdk.mVersions.emplace(std::move(v));
564 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800565 }
566
Yifan Hongffcaf992018-01-09 17:08:51 -0800567 if (matrices->front().object.mType == SchemaType::FRAMEWORK) {
Yifan Honge7837b12018-10-11 10:38:57 -0700568 Level deviceLevel =
569 checkManifest != nullptr ? checkManifest->level() : Level::UNSPECIFIED;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800570 if (deviceLevel == Level::UNSPECIFIED) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800571 deviceLevel = getLowestFcmVersion(*matrices);
Yifan Honge7837b12018-10-11 10:38:57 -0700572 if (checkManifest != nullptr && deviceLevel != Level::UNSPECIFIED) {
573 std::cerr << "Warning: No Target FCM Version for device. Assuming \""
574 << to_string(deviceLevel)
575 << "\" when building final framework compatibility matrix."
576 << std::endl;
577 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800578 }
Yifan Honge7837b12018-10-11 10:38:57 -0700579 builtMatrix = CompatibilityMatrix::combine(deviceLevel, matrices, &error);
580 matrix = builtMatrix.get();
Yifan Hongdbe9db32017-12-11 19:06:11 -0800581
Yifan Hong1e6e34c2018-03-22 16:38:09 -0700582 if (matrix == nullptr) {
583 std::cerr << error << std::endl;
584 return false;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800585 }
586
Yifan Honge88e1672017-08-24 14:42:54 -0700587 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) {
588 return false;
Yifan Hong79efa8a2017-07-06 14:10:28 -0700589 }
Yifan Honge88e1672017-08-24 14:42:54 -0700590
Yifan Hong321ee222018-02-02 12:46:52 -0800591 // Add PLATFORM_SEPOLICY_* to sepolicy.sepolicy-version. Remove dupes.
592 std::set<Version> sepolicyVersions;
593 auto sepolicyVersionStrings = getEnvList("PLATFORM_SEPOLICY_COMPAT_VERSIONS");
594 auto currentSepolicyVersionString = getEnv("PLATFORM_SEPOLICY_VERSION");
595 if (!currentSepolicyVersionString.empty()) {
596 sepolicyVersionStrings.push_back(currentSepolicyVersionString);
597 }
598 for (auto&& s : sepolicyVersionStrings) {
599 Version v;
600 if (!parse(s, &v)) {
601 std::cerr << "Error: unknown sepolicy version '" << s << "' specified by "
602 << (s == currentSepolicyVersionString
603 ? "PLATFORM_SEPOLICY_VERSION"
604 : "PLATFORM_SEPOLICY_COMPAT_VERSIONS")
605 << ".";
606 return false;
607 }
608 sepolicyVersions.insert(v);
609 }
610 for (auto&& v : sepolicyVersions) {
611 matrix->framework.mSepolicy.mSepolicyVersionRanges.emplace_back(v.majorVer,
612 v.minorVer);
Yifan Hong7f6c00c2017-07-06 19:50:29 +0000613 }
Yifan Hongf4135012017-12-18 17:27:19 -0800614
Yifan Hongce355902019-06-26 17:06:52 +0000615 if (!getFlagIfUnset("POLICYVERS",
616 &matrix->framework.mSepolicy.mKernelSepolicyVersion)) {
617 return false;
618 }
619 if (!getFlagIfUnset("FRAMEWORK_VBMETA_VERSION", &matrix->framework.mAvbMetaVersion)) {
620 return false;
621 }
Yifan Hong4dec91d2018-08-13 12:37:47 -0700622 // Hard-override existing AVB version
623 getFlag("FRAMEWORK_VBMETA_VERSION_OVERRIDE", &matrix->framework.mAvbMetaVersion,
624 false /* log */);
Yifan Hong9aa63702017-05-16 16:37:50 -0700625 }
Steven Moreland5875afc2018-04-05 13:14:08 -0700626 outputInputs(*matrices);
Yifan Honga2635c42017-12-12 13:20:33 -0800627 out() << gCompatibilityMatrixConverter(*matrix, mSerializeFlags);
Yifan Hong9aa63702017-05-16 16:37:50 -0700628 out().flush();
629
Yifan Hong1044fd12018-02-27 14:51:54 -0800630 if (checkManifest != nullptr && !checkDualFile(*checkManifest, *matrix)) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800631 return false;
Yifan Hong9aa63702017-05-16 16:37:50 -0700632 }
633
634 return true;
635 }
636
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700637 enum AssembleStatus { SUCCESS, FAIL_AND_EXIT, TRY_NEXT };
638 template <typename Schema, typename AssembleFunc>
639 AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName,
Yifan Hong94757062018-02-09 16:36:31 -0800640 AssembleFunc assemble, std::string* error) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800641 Schemas<Schema> schemas;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700642 Schema schema;
Yifan Hong94757062018-02-09 16:36:31 -0800643 if (!converter(&schema, read(mInFiles.front().stream()), error)) {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700644 return TRY_NEXT;
645 }
646 auto firstType = schema.type();
Yifan Hongaa219f52017-12-18 18:51:59 -0800647 schemas.emplace_back(mInFiles.front().name(), std::move(schema));
Yifan Hongdbe9db32017-12-11 19:06:11 -0800648
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700649 for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
650 Schema additionalSchema;
Yifan Hongaa219f52017-12-18 18:51:59 -0800651 const std::string& fileName = it->name();
Yifan Hong94757062018-02-09 16:36:31 -0800652 if (!converter(&additionalSchema, read(it->stream()), error)) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800653 std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " "
654 << schemaName << " (but the first file is a valid " << firstType << " "
Yifan Hong94757062018-02-09 16:36:31 -0800655 << schemaName << "). Error: " << *error << std::endl;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700656 return FAIL_AND_EXIT;
657 }
658 if (additionalSchema.type() != firstType) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800659 std::cerr << "File \"" << fileName << "\" is a " << additionalSchema.type() << " "
660 << schemaName << " (but a " << firstType << " " << schemaName
661 << " is expected)." << std::endl;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700662 return FAIL_AND_EXIT;
663 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800664
665 schemas.emplace_back(fileName, std::move(additionalSchema));
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700666 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800667 return assemble(&schemas) ? SUCCESS : FAIL_AND_EXIT;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700668 }
669
Yifan Hong8302cea2017-12-18 20:17:05 -0800670 bool assemble() override {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700671 using std::placeholders::_1;
672 if (mInFiles.empty()) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700673 std::cerr << "Missing input file." << std::endl;
674 return false;
675 }
676
Yifan Hong94757062018-02-09 16:36:31 -0800677 std::string manifestError;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700678 auto status = tryAssemble(gHalManifestConverter, "manifest",
Yifan Hong94757062018-02-09 16:36:31 -0800679 std::bind(&AssembleVintfImpl::assembleHalManifest, this, _1),
680 &manifestError);
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700681 if (status == SUCCESS) return true;
682 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000683
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700684 resetInFiles();
Yifan Honga59d2562017-04-18 18:01:16 -0700685
Yifan Hong94757062018-02-09 16:36:31 -0800686 std::string matrixError;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700687 status = tryAssemble(gCompatibilityMatrixConverter, "compatibility matrix",
Yifan Hong94757062018-02-09 16:36:31 -0800688 std::bind(&AssembleVintfImpl::assembleCompatibilityMatrix, this, _1),
689 &matrixError);
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700690 if (status == SUCCESS) return true;
691 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000692
Yifan Hong959ee1b2017-04-28 14:37:56 -0700693 std::cerr << "Input file has unknown format." << std::endl
Yifan Hong94757062018-02-09 16:36:31 -0800694 << "Error when attempting to convert to manifest: " << manifestError << std::endl
695 << "Error when attempting to convert to compatibility matrix: " << matrixError
696 << std::endl;
Yifan Hong959ee1b2017-04-28 14:37:56 -0700697 return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000698 }
Yifan Hong9aa63702017-05-16 16:37:50 -0700699
Yifan Hong8302cea2017-12-18 20:17:05 -0800700 std::ostream& setOutputStream(Ostream&& out) override {
701 mOutRef = std::move(out);
702 return *mOutRef;
Yifan Hong9aa63702017-05-16 16:37:50 -0700703 }
704
Yifan Hong8302cea2017-12-18 20:17:05 -0800705 std::istream& addInputStream(const std::string& name, Istream&& in) override {
706 auto it = mInFiles.emplace(mInFiles.end(), name, std::move(in));
707 return it->stream();
Yifan Hong9aa63702017-05-16 16:37:50 -0700708 }
709
Yifan Hong8302cea2017-12-18 20:17:05 -0800710 std::istream& setCheckInputStream(Istream&& in) override {
711 mCheckFile = std::move(in);
712 return *mCheckFile;
713 }
714
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800715 bool hasKernelVersion(const KernelVersion& kernelVer) const override {
Yifan Hong8302cea2017-12-18 20:17:05 -0800716 return mKernels.find(kernelVer) != mKernels.end();
717 }
718
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800719 std::istream& addKernelConfigInputStream(const KernelVersion& kernelVer,
720 const std::string& name, Istream&& in) override {
Yifan Hong8302cea2017-12-18 20:17:05 -0800721 auto&& kernel = mKernels[kernelVer];
722 auto it = kernel.emplace(kernel.end(), name, std::move(in));
723 return it->stream();
Yifan Hong9aa63702017-05-16 16:37:50 -0700724 }
725
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700726 void resetInFiles() {
727 for (auto& inFile : mInFiles) {
Yifan Hongaa219f52017-12-18 18:51:59 -0800728 inFile.stream().clear();
729 inFile.stream().seekg(0);
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700730 }
731 }
732
Yifan Hong8302cea2017-12-18 20:17:05 -0800733 void setOutputMatrix() override { mOutputMatrix = true; }
Yifan Hong9aa63702017-05-16 16:37:50 -0700734
Yifan Hong8302cea2017-12-18 20:17:05 -0800735 bool setHalsOnly() override {
Yifan Hong5c9ff702018-08-07 17:26:12 -0700736 if (mHasSetHalsOnlyFlag) {
737 std::cerr << "Error: Cannot set --hals-only with --no-hals." << std::endl;
738 return false;
739 }
740 // Just override it with HALS_ONLY because other flags that modify mSerializeFlags
741 // does not interfere with this (except --no-hals).
742 mSerializeFlags = SerializeFlags::HALS_ONLY;
743 mHasSetHalsOnlyFlag = true;
Yifan Honga2635c42017-12-12 13:20:33 -0800744 return true;
745 }
746
Yifan Hong8302cea2017-12-18 20:17:05 -0800747 bool setNoHals() override {
Yifan Hong5c9ff702018-08-07 17:26:12 -0700748 if (mHasSetHalsOnlyFlag) {
749 std::cerr << "Error: Cannot set --hals-only with --no-hals." << std::endl;
750 return false;
751 }
752 mSerializeFlags = mSerializeFlags.disableHals();
753 mHasSetHalsOnlyFlag = true;
Yifan Honga2635c42017-12-12 13:20:33 -0800754 return true;
755 }
756
Yifan Hong86678e42018-07-26 11:38:54 -0700757 bool setNoKernelRequirements() override {
Yifan Hong5c9ff702018-08-07 17:26:12 -0700758 mSerializeFlags = mSerializeFlags.disableKernelConfigs().disableKernelMinorRevision();
Yifan Hong3f743912019-12-17 14:12:04 -0800759 mCheckFlags = mCheckFlags.disableKernel();
Yifan Hong86678e42018-07-26 11:38:54 -0700760 return true;
761 }
762
Yifan Hong9aa63702017-05-16 16:37:50 -0700763 private:
Yifan Hongaa219f52017-12-18 18:51:59 -0800764 std::vector<NamedIstream> mInFiles;
Yifan Hong8302cea2017-12-18 20:17:05 -0800765 Ostream mOutRef;
766 Istream mCheckFile;
Yifan Hong9aa63702017-05-16 16:37:50 -0700767 bool mOutputMatrix = false;
Yifan Hong5c9ff702018-08-07 17:26:12 -0700768 bool mHasSetHalsOnlyFlag = false;
Yifan Hongba588bc2018-08-08 14:19:41 -0700769 SerializeFlags::Type mSerializeFlags = SerializeFlags::EVERYTHING;
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800770 std::map<KernelVersion, std::vector<NamedIstream>> mKernels;
Yifan Hong8302cea2017-12-18 20:17:05 -0800771 std::map<std::string, std::string> mFakeEnv;
Yifan Hong3f743912019-12-17 14:12:04 -0800772 CheckFlags::Type mCheckFlags = CheckFlags::DEFAULT;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000773};
774
Yifan Hong8302cea2017-12-18 20:17:05 -0800775bool AssembleVintf::openOutFile(const std::string& path) {
776 return static_cast<std::ofstream&>(setOutputStream(std::make_unique<std::ofstream>(path)))
777 .is_open();
778}
779
780bool AssembleVintf::openInFile(const std::string& path) {
781 return static_cast<std::ifstream&>(addInputStream(path, std::make_unique<std::ifstream>(path)))
782 .is_open();
783}
784
785bool AssembleVintf::openCheckFile(const std::string& path) {
786 return static_cast<std::ifstream&>(setCheckInputStream(std::make_unique<std::ifstream>(path)))
787 .is_open();
788}
789
790bool AssembleVintf::addKernel(const std::string& kernelArg) {
Yifan Hongb83e56b2018-01-09 14:36:30 -0800791 auto tokens = base::Split(kernelArg, ":");
Yifan Hong8302cea2017-12-18 20:17:05 -0800792 if (tokens.size() <= 1) {
793 std::cerr << "Unrecognized --kernel option '" << kernelArg << "'" << std::endl;
794 return false;
795 }
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800796 KernelVersion kernelVer;
Yifan Hong8302cea2017-12-18 20:17:05 -0800797 if (!parse(tokens.front(), &kernelVer)) {
798 std::cerr << "Unrecognized kernel version '" << tokens.front() << "'" << std::endl;
799 return false;
800 }
801 if (hasKernelVersion(kernelVer)) {
802 std::cerr << "Multiple --kernel for " << kernelVer << " is specified." << std::endl;
803 return false;
804 }
805 for (auto it = tokens.begin() + 1; it != tokens.end(); ++it) {
806 bool opened =
807 static_cast<std::ifstream&>(
808 addKernelConfigInputStream(kernelVer, *it, std::make_unique<std::ifstream>(*it)))
809 .is_open();
810 if (!opened) {
811 std::cerr << "Cannot open file '" << *it << "'." << std::endl;
812 return false;
813 }
814 }
815 return true;
816}
817
818std::unique_ptr<AssembleVintf> AssembleVintf::newInstance() {
819 return std::make_unique<AssembleVintfImpl>();
820}
821
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000822} // namespace vintf
823} // namespace android