blob: ba7419ba0655595ff9722b7f23f5376768e029e9 [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 Hong1557a742020-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 Hong1557a742020-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 Hong1557a742020-03-27 16:54:16 -0700190 if (!isConditionalConfig(path)) {
Yifan Hong079ec242017-08-25 18:53:38 -0700191 return nullptr;
192 }
Yifan Hong1557a742020-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 Hong1557a742020-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 Hong1557a742020-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 Hong1557a742020-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;
Yifan Hongbd2033f2020-05-14 13:16:31 -0700357 // Inject empty <kernel> tag if missing.
358 if (!manifest->kernel().has_value()) {
359 manifest->device.mKernel = std::make_optional<KernelInfo>();
360 }
Yifan Hong08a48712019-12-11 14:56:00 -0800361 // Kernel FCM already set.
362 if (manifest->kernel()->level() != Level::UNSPECIFIED) return;
363
364 manifest->device.mKernel->mLevel = manifest->level();
365 }
366
Yifan Hongdbe9db32017-12-11 19:06:11 -0800367 bool assembleHalManifest(HalManifests* halManifests) {
Yifan Hong4650ad82017-05-01 17:28:02 -0700368 std::string error;
Yifan Hongffcaf992018-01-09 17:08:51 -0800369 HalManifest* halManifest = &halManifests->front().object;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800370 for (auto it = halManifests->begin() + 1; it != halManifests->end(); ++it) {
Yifan Hongffcaf992018-01-09 17:08:51 -0800371 const std::string& path = it->name;
Yifan Hong0a35ab12018-06-29 11:32:57 -0700372 HalManifest& manifestToAdd = it->object;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800373
Yifan Hong0a35ab12018-06-29 11:32:57 -0700374 if (manifestToAdd.level() != Level::UNSPECIFIED) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800375 if (halManifest->level() == Level::UNSPECIFIED) {
Yifan Hong0a35ab12018-06-29 11:32:57 -0700376 halManifest->mLevel = manifestToAdd.level();
377 } else if (halManifest->level() != manifestToAdd.level()) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800378 std::cerr << "Inconsistent FCM Version in HAL manifests:" << std::endl
Yifan Hongffcaf992018-01-09 17:08:51 -0800379 << " File '" << halManifests->front().name << "' has level "
Yifan Hongdbe9db32017-12-11 19:06:11 -0800380 << halManifest->level() << std::endl
Yifan Hong0a35ab12018-06-29 11:32:57 -0700381 << " File '" << path << "' has level " << manifestToAdd.level()
Yifan Hongdbe9db32017-12-11 19:06:11 -0800382 << std::endl;
383 return false;
384 }
385 }
386
Yifan Hong4c6962d2019-01-30 15:50:46 -0800387 if (!halManifest->addAll(&manifestToAdd, &error)) {
388 std::cerr << "File \"" << path << "\" cannot be added: " << error << std::endl;
Yifan Hong0a35ab12018-06-29 11:32:57 -0700389 return false;
390 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800391 }
Yifan Hong9aa63702017-05-16 16:37:50 -0700392
393 if (halManifest->mType == SchemaType::DEVICE) {
Yifan Hongce355902019-06-26 17:06:52 +0000394 if (!getFlagIfUnset("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion)) {
395 return false;
396 }
Steven Morelandb1392772018-05-01 11:21:35 -0700397
Yifan Hongdbe9db32017-12-11 19:06:11 -0800398 if (!setDeviceFcmVersion(halManifest)) {
399 return false;
400 }
Yifan Honga45f77d2018-12-03 16:42:52 -0800401
402 if (!setDeviceManifestKernel(halManifest)) {
403 return false;
404 }
Yifan Hong08a48712019-12-11 14:56:00 -0800405
406 inferDeviceManifestKernelFcm(halManifest);
Yifan Hong9aa63702017-05-16 16:37:50 -0700407 }
408
Yifan Hongfeb454e2018-01-09 16:16:40 -0800409 if (halManifest->mType == SchemaType::FRAMEWORK) {
Yifan Honga28729e2018-01-17 13:40:35 -0800410 for (auto&& v : getEnvList("PROVIDED_VNDK_VERSIONS")) {
411 halManifest->framework.mVendorNdks.emplace_back(std::move(v));
412 }
413
Yifan Hong8b8492b2018-01-22 14:08:40 -0800414 for (auto&& v : getEnvList("PLATFORM_SYSTEMSDK_VERSIONS")) {
Yifan Honga28729e2018-01-17 13:40:35 -0800415 halManifest->framework.mSystemSdk.mVersions.emplace(std::move(v));
Yifan Hongfeb454e2018-01-09 16:16:40 -0800416 }
417 }
418
Steven Moreland5875afc2018-04-05 13:14:08 -0700419 outputInputs(*halManifests);
420
Yifan Hong9aa63702017-05-16 16:37:50 -0700421 if (mOutputMatrix) {
422 CompatibilityMatrix generatedMatrix = halManifest->generateCompatibleMatrix();
Yifan Hong3f743912019-12-17 14:12:04 -0800423 if (!halManifest->checkCompatibility(generatedMatrix, &error, mCheckFlags)) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700424 std::cerr << "FATAL ERROR: cannot generate a compatible matrix: " << error
425 << std::endl;
426 }
427 out() << "<!-- \n"
428 " Autogenerated skeleton compatibility matrix. \n"
429 " Use with caution. Modify it to suit your needs.\n"
430 " All HALs are set to optional.\n"
431 " Many entries other than HALs are zero-filled and\n"
432 " require human attention. \n"
433 "-->\n"
Yifan Honga2635c42017-12-12 13:20:33 -0800434 << gCompatibilityMatrixConverter(generatedMatrix, mSerializeFlags);
Yifan Hong9aa63702017-05-16 16:37:50 -0700435 } else {
Yifan Honga2635c42017-12-12 13:20:33 -0800436 out() << gHalManifestConverter(*halManifest, mSerializeFlags);
Yifan Hong9aa63702017-05-16 16:37:50 -0700437 }
438 out().flush();
439
Yifan Hong8302cea2017-12-18 20:17:05 -0800440 if (mCheckFile != nullptr) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700441 CompatibilityMatrix checkMatrix;
Yifan Hong94757062018-02-09 16:36:31 -0800442 if (!gCompatibilityMatrixConverter(&checkMatrix, read(*mCheckFile), &error)) {
443 std::cerr << "Cannot parse check file as a compatibility matrix: " << error
444 << std::endl;
Yifan Hong9aa63702017-05-16 16:37:50 -0700445 return false;
446 }
Yifan Hong1044fd12018-02-27 14:51:54 -0800447 if (!checkDualFile(*halManifest, checkMatrix)) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700448 return false;
449 }
450 }
451
452 return true;
453 }
454
Yifan Honge7837b12018-10-11 10:38:57 -0700455 // Parse --kernel arguments and write to output matrix.
Yifan Honge88e1672017-08-24 14:42:54 -0700456 bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) {
Yifan Hong8302cea2017-12-18 20:17:05 -0800457 for (auto& pair : mKernels) {
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700458 std::vector<ConditionedConfig> conditionedConfigs;
Yifan Hong8302cea2017-12-18 20:17:05 -0800459 if (!parseFilesForKernelConfigs(&pair.second, &conditionedConfigs)) {
Yifan Honge88e1672017-08-24 14:42:54 -0700460 return false;
461 }
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700462 for (ConditionedConfig& conditionedConfig : conditionedConfigs) {
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800463 MatrixKernel kernel(KernelVersion{pair.first}, std::move(conditionedConfig.second));
Yifan Hong079ec242017-08-25 18:53:38 -0700464 if (conditionedConfig.first != nullptr)
465 kernel.mConditions.push_back(std::move(*conditionedConfig.first));
Yifan Honge7837b12018-10-11 10:38:57 -0700466 std::string error;
467 if (!matrix->addKernel(std::move(kernel), &error)) {
468 std::cerr << "Error:" << error << std::endl;
469 return false;
470 };
Yifan Hong9a8b1a72017-08-25 17:55:33 -0700471 }
Yifan Honge88e1672017-08-24 14:42:54 -0700472 }
473 return true;
474 }
475
Yifan Hongdbe9db32017-12-11 19:06:11 -0800476 bool setDeviceFcmVersion(HalManifest* manifest) {
Yifan Hong1e6e34c2018-03-22 16:38:09 -0700477 // Not needed for generating empty manifest for DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE.
Yifan Hong2eee1982018-03-29 10:55:30 -0700478 if (getBooleanFlag("VINTF_IGNORE_TARGET_FCM_VERSION")) {
Yifan Hong1e6e34c2018-03-22 16:38:09 -0700479 return true;
480 }
481
Yifan Hongdbe9db32017-12-11 19:06:11 -0800482 size_t shippingApiLevel = getIntegerFlag("PRODUCT_SHIPPING_API_LEVEL");
Yifan Hong9aa63702017-05-16 16:37:50 -0700483
Yifan Hongdbe9db32017-12-11 19:06:11 -0800484 if (manifest->level() != Level::UNSPECIFIED) {
485 return true;
486 }
487 if (!getBooleanFlag("PRODUCT_ENFORCE_VINTF_MANIFEST")) {
488 manifest->mLevel = Level::LEGACY;
489 return true;
490 }
491 // TODO(b/70628538): Do not infer from Shipping API level.
492 if (shippingApiLevel) {
493 std::cerr << "Warning: Shipping FCM Version is inferred from Shipping API level. "
494 << "Declare Shipping FCM Version in device manifest directly." << std::endl;
Yifan Hongafae1982018-01-11 18:15:24 -0800495 manifest->mLevel = details::convertFromApiLevel(shippingApiLevel);
Yifan Hongdbe9db32017-12-11 19:06:11 -0800496 if (manifest->mLevel == Level::UNSPECIFIED) {
497 std::cerr << "Error: Shipping FCM Version cannot be inferred from Shipping API "
498 << "level " << shippingApiLevel << "."
499 << "Declare Shipping FCM Version in device manifest directly."
500 << std::endl;
501 return false;
502 }
503 return true;
504 }
505 // TODO(b/69638851): should be an error if Shipping API level is not defined.
506 // For now, just leave it empty; when framework compatibility matrix is built,
507 // lowest FCM Version is assumed.
508 std::cerr << "Warning: Shipping FCM Version cannot be inferred, because:" << std::endl
509 << " (1) It is not explicitly declared in device manifest;" << std::endl
510 << " (2) PRODUCT_ENFORCE_VINTF_MANIFEST is set to true;" << std::endl
511 << " (3) PRODUCT_SHIPPING_API_LEVEL is undefined." << std::endl
512 << "Assuming 'unspecified' Shipping FCM Version. " << std::endl
513 << "To remove this warning, define 'level' attribute in device manifest."
514 << std::endl;
515 return true;
516 }
517
518 Level getLowestFcmVersion(const CompatibilityMatrices& matrices) {
519 Level ret = Level::UNSPECIFIED;
520 for (const auto& e : matrices) {
Yifan Hongffcaf992018-01-09 17:08:51 -0800521 if (ret == Level::UNSPECIFIED || ret > e.object.level()) {
522 ret = e.object.level();
Yifan Hongdbe9db32017-12-11 19:06:11 -0800523 }
524 }
525 return ret;
526 }
527
528 bool assembleCompatibilityMatrix(CompatibilityMatrices* matrices) {
529 std::string error;
530 CompatibilityMatrix* matrix = nullptr;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800531 std::unique_ptr<HalManifest> checkManifest;
Yifan Honge7837b12018-10-11 10:38:57 -0700532 std::unique_ptr<CompatibilityMatrix> builtMatrix;
533
534 if (mCheckFile != nullptr) {
535 checkManifest = std::make_unique<HalManifest>();
536 if (!gHalManifestConverter(checkManifest.get(), read(*mCheckFile), &error)) {
537 std::cerr << "Cannot parse check file as a HAL manifest: " << error << std::endl;
538 return false;
539 }
540 }
541
Yifan Hongffcaf992018-01-09 17:08:51 -0800542 if (matrices->front().object.mType == SchemaType::DEVICE) {
Yifan Hong5a51ea52019-04-22 14:54:57 -0700543 builtMatrix = CompatibilityMatrix::combineDeviceMatrices(matrices, &error);
544 matrix = builtMatrix.get();
545
546 if (matrix == nullptr) {
547 std::cerr << error << std::endl;
Yifan Honge7837b12018-10-11 10:38:57 -0700548 return false;
549 }
550
Yifan Hongfeb454e2018-01-09 16:16:40 -0800551 auto vndkVersion = base::Trim(getEnv("REQUIRED_VNDK_VERSION"));
552 if (!vndkVersion.empty()) {
553 auto& valueInMatrix = matrix->device.mVendorNdk;
554 if (!valueInMatrix.version().empty() && valueInMatrix.version() != vndkVersion) {
555 std::cerr << "Hard-coded <vendor-ndk> version in device compatibility matrix ("
556 << matrices->front().name << "), '" << valueInMatrix.version()
557 << "', does not match value inferred "
558 << "from BOARD_VNDK_VERSION '" << vndkVersion << "'" << std::endl;
559 return false;
560 }
561 valueInMatrix = VendorNdk{std::move(vndkVersion)};
562 }
Yifan Honga28729e2018-01-17 13:40:35 -0800563
564 for (auto&& v : getEnvList("BOARD_SYSTEMSDK_VERSIONS")) {
565 matrix->device.mSystemSdk.mVersions.emplace(std::move(v));
566 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800567 }
568
Yifan Hongffcaf992018-01-09 17:08:51 -0800569 if (matrices->front().object.mType == SchemaType::FRAMEWORK) {
Yifan Honge7837b12018-10-11 10:38:57 -0700570 Level deviceLevel =
571 checkManifest != nullptr ? checkManifest->level() : Level::UNSPECIFIED;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800572 if (deviceLevel == Level::UNSPECIFIED) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800573 deviceLevel = getLowestFcmVersion(*matrices);
Yifan Honge7837b12018-10-11 10:38:57 -0700574 if (checkManifest != nullptr && deviceLevel != Level::UNSPECIFIED) {
575 std::cerr << "Warning: No Target FCM Version for device. Assuming \""
576 << to_string(deviceLevel)
577 << "\" when building final framework compatibility matrix."
578 << std::endl;
579 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800580 }
Yifan Honge7837b12018-10-11 10:38:57 -0700581 builtMatrix = CompatibilityMatrix::combine(deviceLevel, matrices, &error);
582 matrix = builtMatrix.get();
Yifan Hongdbe9db32017-12-11 19:06:11 -0800583
Yifan Hong1e6e34c2018-03-22 16:38:09 -0700584 if (matrix == nullptr) {
585 std::cerr << error << std::endl;
586 return false;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800587 }
588
Yifan Honge88e1672017-08-24 14:42:54 -0700589 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) {
590 return false;
Yifan Hong79efa8a2017-07-06 14:10:28 -0700591 }
Yifan Honge88e1672017-08-24 14:42:54 -0700592
Yifan Hong321ee222018-02-02 12:46:52 -0800593 // Add PLATFORM_SEPOLICY_* to sepolicy.sepolicy-version. Remove dupes.
594 std::set<Version> sepolicyVersions;
595 auto sepolicyVersionStrings = getEnvList("PLATFORM_SEPOLICY_COMPAT_VERSIONS");
596 auto currentSepolicyVersionString = getEnv("PLATFORM_SEPOLICY_VERSION");
597 if (!currentSepolicyVersionString.empty()) {
598 sepolicyVersionStrings.push_back(currentSepolicyVersionString);
599 }
600 for (auto&& s : sepolicyVersionStrings) {
601 Version v;
602 if (!parse(s, &v)) {
603 std::cerr << "Error: unknown sepolicy version '" << s << "' specified by "
604 << (s == currentSepolicyVersionString
605 ? "PLATFORM_SEPOLICY_VERSION"
606 : "PLATFORM_SEPOLICY_COMPAT_VERSIONS")
607 << ".";
608 return false;
609 }
610 sepolicyVersions.insert(v);
611 }
612 for (auto&& v : sepolicyVersions) {
613 matrix->framework.mSepolicy.mSepolicyVersionRanges.emplace_back(v.majorVer,
614 v.minorVer);
Yifan Hong7f6c00c2017-07-06 19:50:29 +0000615 }
Yifan Hongf4135012017-12-18 17:27:19 -0800616
Yifan Hongce355902019-06-26 17:06:52 +0000617 if (!getFlagIfUnset("POLICYVERS",
618 &matrix->framework.mSepolicy.mKernelSepolicyVersion)) {
619 return false;
620 }
621 if (!getFlagIfUnset("FRAMEWORK_VBMETA_VERSION", &matrix->framework.mAvbMetaVersion)) {
622 return false;
623 }
Yifan Hong4dec91d2018-08-13 12:37:47 -0700624 // Hard-override existing AVB version
625 getFlag("FRAMEWORK_VBMETA_VERSION_OVERRIDE", &matrix->framework.mAvbMetaVersion,
626 false /* log */);
Yifan Hong9aa63702017-05-16 16:37:50 -0700627 }
Steven Moreland5875afc2018-04-05 13:14:08 -0700628 outputInputs(*matrices);
Yifan Honga2635c42017-12-12 13:20:33 -0800629 out() << gCompatibilityMatrixConverter(*matrix, mSerializeFlags);
Yifan Hong9aa63702017-05-16 16:37:50 -0700630 out().flush();
631
Yifan Hong1044fd12018-02-27 14:51:54 -0800632 if (checkManifest != nullptr && !checkDualFile(*checkManifest, *matrix)) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800633 return false;
Yifan Hong9aa63702017-05-16 16:37:50 -0700634 }
635
636 return true;
637 }
638
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700639 enum AssembleStatus { SUCCESS, FAIL_AND_EXIT, TRY_NEXT };
640 template <typename Schema, typename AssembleFunc>
641 AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName,
Yifan Hong94757062018-02-09 16:36:31 -0800642 AssembleFunc assemble, std::string* error) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800643 Schemas<Schema> schemas;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700644 Schema schema;
Yifan Hong94757062018-02-09 16:36:31 -0800645 if (!converter(&schema, read(mInFiles.front().stream()), error)) {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700646 return TRY_NEXT;
647 }
648 auto firstType = schema.type();
Yifan Hongaa219f52017-12-18 18:51:59 -0800649 schemas.emplace_back(mInFiles.front().name(), std::move(schema));
Yifan Hongdbe9db32017-12-11 19:06:11 -0800650
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700651 for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
652 Schema additionalSchema;
Yifan Hongaa219f52017-12-18 18:51:59 -0800653 const std::string& fileName = it->name();
Yifan Hong94757062018-02-09 16:36:31 -0800654 if (!converter(&additionalSchema, read(it->stream()), error)) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800655 std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " "
656 << schemaName << " (but the first file is a valid " << firstType << " "
Yifan Hong94757062018-02-09 16:36:31 -0800657 << schemaName << "). Error: " << *error << std::endl;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700658 return FAIL_AND_EXIT;
659 }
660 if (additionalSchema.type() != firstType) {
Yifan Hongdbe9db32017-12-11 19:06:11 -0800661 std::cerr << "File \"" << fileName << "\" is a " << additionalSchema.type() << " "
662 << schemaName << " (but a " << firstType << " " << schemaName
663 << " is expected)." << std::endl;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700664 return FAIL_AND_EXIT;
665 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800666
667 schemas.emplace_back(fileName, std::move(additionalSchema));
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700668 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800669 return assemble(&schemas) ? SUCCESS : FAIL_AND_EXIT;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700670 }
671
Yifan Hong8302cea2017-12-18 20:17:05 -0800672 bool assemble() override {
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700673 using std::placeholders::_1;
674 if (mInFiles.empty()) {
Yifan Hong9aa63702017-05-16 16:37:50 -0700675 std::cerr << "Missing input file." << std::endl;
676 return false;
677 }
678
Yifan Hong94757062018-02-09 16:36:31 -0800679 std::string manifestError;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700680 auto status = tryAssemble(gHalManifestConverter, "manifest",
Yifan Hong94757062018-02-09 16:36:31 -0800681 std::bind(&AssembleVintfImpl::assembleHalManifest, this, _1),
682 &manifestError);
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700683 if (status == SUCCESS) return true;
684 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000685
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700686 resetInFiles();
Yifan Honga59d2562017-04-18 18:01:16 -0700687
Yifan Hong94757062018-02-09 16:36:31 -0800688 std::string matrixError;
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700689 status = tryAssemble(gCompatibilityMatrixConverter, "compatibility matrix",
Yifan Hong94757062018-02-09 16:36:31 -0800690 std::bind(&AssembleVintfImpl::assembleCompatibilityMatrix, this, _1),
691 &matrixError);
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700692 if (status == SUCCESS) return true;
693 if (status == FAIL_AND_EXIT) return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000694
Yifan Hong959ee1b2017-04-28 14:37:56 -0700695 std::cerr << "Input file has unknown format." << std::endl
Yifan Hong94757062018-02-09 16:36:31 -0800696 << "Error when attempting to convert to manifest: " << manifestError << std::endl
697 << "Error when attempting to convert to compatibility matrix: " << matrixError
698 << std::endl;
Yifan Hong959ee1b2017-04-28 14:37:56 -0700699 return false;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000700 }
Yifan Hong9aa63702017-05-16 16:37:50 -0700701
Yifan Hong8302cea2017-12-18 20:17:05 -0800702 std::ostream& setOutputStream(Ostream&& out) override {
703 mOutRef = std::move(out);
704 return *mOutRef;
Yifan Hong9aa63702017-05-16 16:37:50 -0700705 }
706
Yifan Hong8302cea2017-12-18 20:17:05 -0800707 std::istream& addInputStream(const std::string& name, Istream&& in) override {
708 auto it = mInFiles.emplace(mInFiles.end(), name, std::move(in));
709 return it->stream();
Yifan Hong9aa63702017-05-16 16:37:50 -0700710 }
711
Yifan Hong8302cea2017-12-18 20:17:05 -0800712 std::istream& setCheckInputStream(Istream&& in) override {
713 mCheckFile = std::move(in);
714 return *mCheckFile;
715 }
716
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800717 bool hasKernelVersion(const KernelVersion& kernelVer) const override {
Yifan Hong8302cea2017-12-18 20:17:05 -0800718 return mKernels.find(kernelVer) != mKernels.end();
719 }
720
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800721 std::istream& addKernelConfigInputStream(const KernelVersion& kernelVer,
722 const std::string& name, Istream&& in) override {
Yifan Hong8302cea2017-12-18 20:17:05 -0800723 auto&& kernel = mKernels[kernelVer];
724 auto it = kernel.emplace(kernel.end(), name, std::move(in));
725 return it->stream();
Yifan Hong9aa63702017-05-16 16:37:50 -0700726 }
727
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700728 void resetInFiles() {
729 for (auto& inFile : mInFiles) {
Yifan Hongaa219f52017-12-18 18:51:59 -0800730 inFile.stream().clear();
731 inFile.stream().seekg(0);
Yifan Hongbfb3c1d2017-05-24 14:38:48 -0700732 }
733 }
734
Yifan Hong8302cea2017-12-18 20:17:05 -0800735 void setOutputMatrix() override { mOutputMatrix = true; }
Yifan Hong9aa63702017-05-16 16:37:50 -0700736
Yifan Hong8302cea2017-12-18 20:17:05 -0800737 bool setHalsOnly() override {
Yifan Hong5c9ff702018-08-07 17:26:12 -0700738 if (mHasSetHalsOnlyFlag) {
739 std::cerr << "Error: Cannot set --hals-only with --no-hals." << std::endl;
740 return false;
741 }
742 // Just override it with HALS_ONLY because other flags that modify mSerializeFlags
743 // does not interfere with this (except --no-hals).
744 mSerializeFlags = SerializeFlags::HALS_ONLY;
745 mHasSetHalsOnlyFlag = true;
Yifan Honga2635c42017-12-12 13:20:33 -0800746 return true;
747 }
748
Yifan Hong8302cea2017-12-18 20:17:05 -0800749 bool setNoHals() override {
Yifan Hong5c9ff702018-08-07 17:26:12 -0700750 if (mHasSetHalsOnlyFlag) {
751 std::cerr << "Error: Cannot set --hals-only with --no-hals." << std::endl;
752 return false;
753 }
754 mSerializeFlags = mSerializeFlags.disableHals();
755 mHasSetHalsOnlyFlag = true;
Yifan Honga2635c42017-12-12 13:20:33 -0800756 return true;
757 }
758
Yifan Hong86678e42018-07-26 11:38:54 -0700759 bool setNoKernelRequirements() override {
Yifan Hong5c9ff702018-08-07 17:26:12 -0700760 mSerializeFlags = mSerializeFlags.disableKernelConfigs().disableKernelMinorRevision();
Yifan Hong3f743912019-12-17 14:12:04 -0800761 mCheckFlags = mCheckFlags.disableKernel();
Yifan Hong86678e42018-07-26 11:38:54 -0700762 return true;
763 }
764
Yifan Hong9aa63702017-05-16 16:37:50 -0700765 private:
Yifan Hongaa219f52017-12-18 18:51:59 -0800766 std::vector<NamedIstream> mInFiles;
Yifan Hong8302cea2017-12-18 20:17:05 -0800767 Ostream mOutRef;
768 Istream mCheckFile;
Yifan Hong9aa63702017-05-16 16:37:50 -0700769 bool mOutputMatrix = false;
Yifan Hong5c9ff702018-08-07 17:26:12 -0700770 bool mHasSetHalsOnlyFlag = false;
Yifan Hongba588bc2018-08-08 14:19:41 -0700771 SerializeFlags::Type mSerializeFlags = SerializeFlags::EVERYTHING;
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800772 std::map<KernelVersion, std::vector<NamedIstream>> mKernels;
Yifan Hong8302cea2017-12-18 20:17:05 -0800773 std::map<std::string, std::string> mFakeEnv;
Yifan Hong3f743912019-12-17 14:12:04 -0800774 CheckFlags::Type mCheckFlags = CheckFlags::DEFAULT;
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000775};
776
Yifan Hong8302cea2017-12-18 20:17:05 -0800777bool AssembleVintf::openOutFile(const std::string& path) {
778 return static_cast<std::ofstream&>(setOutputStream(std::make_unique<std::ofstream>(path)))
779 .is_open();
780}
781
782bool AssembleVintf::openInFile(const std::string& path) {
783 return static_cast<std::ifstream&>(addInputStream(path, std::make_unique<std::ifstream>(path)))
784 .is_open();
785}
786
787bool AssembleVintf::openCheckFile(const std::string& path) {
788 return static_cast<std::ifstream&>(setCheckInputStream(std::make_unique<std::ifstream>(path)))
789 .is_open();
790}
791
792bool AssembleVintf::addKernel(const std::string& kernelArg) {
Yifan Hongb83e56b2018-01-09 14:36:30 -0800793 auto tokens = base::Split(kernelArg, ":");
Yifan Hong8302cea2017-12-18 20:17:05 -0800794 if (tokens.size() <= 1) {
795 std::cerr << "Unrecognized --kernel option '" << kernelArg << "'" << std::endl;
796 return false;
797 }
Yifan Hongfb9e8b62018-01-23 15:47:23 -0800798 KernelVersion kernelVer;
Yifan Hong8302cea2017-12-18 20:17:05 -0800799 if (!parse(tokens.front(), &kernelVer)) {
800 std::cerr << "Unrecognized kernel version '" << tokens.front() << "'" << std::endl;
801 return false;
802 }
803 if (hasKernelVersion(kernelVer)) {
804 std::cerr << "Multiple --kernel for " << kernelVer << " is specified." << std::endl;
805 return false;
806 }
807 for (auto it = tokens.begin() + 1; it != tokens.end(); ++it) {
808 bool opened =
809 static_cast<std::ifstream&>(
810 addKernelConfigInputStream(kernelVer, *it, std::make_unique<std::ifstream>(*it)))
811 .is_open();
812 if (!opened) {
813 std::cerr << "Cannot open file '" << *it << "'." << std::endl;
814 return false;
815 }
816 }
817 return true;
818}
819
820std::unique_ptr<AssembleVintf> AssembleVintf::newInstance() {
821 return std::make_unique<AssembleVintfImpl>();
822}
823
Yifan Hong4d18bcc2017-04-07 21:47:16 +0000824} // namespace vintf
825} // namespace android