Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 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 <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | |
| 20 | #include <fstream> |
| 21 | #include <iostream> |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 22 | #include <sstream> |
| 23 | #include <string> |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 24 | #include <unordered_map> |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 25 | |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 26 | #include <android-base/file.h> |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 27 | #include <android-base/parseint.h> |
Yifan Hong | b83e56b | 2018-01-09 14:36:30 -0800 | [diff] [blame] | 28 | #include <android-base/strings.h> |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 29 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 30 | #include <vintf/AssembleVintf.h> |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 31 | #include <vintf/KernelConfigParser.h> |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 32 | #include <vintf/parse_string.h> |
| 33 | #include <vintf/parse_xml.h> |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 34 | #include "utils.h" |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 35 | |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 36 | #define BUFFER_SIZE sysconf(_SC_PAGESIZE) |
| 37 | |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 38 | namespace android { |
| 39 | namespace vintf { |
| 40 | |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 41 | static const std::string gConfigPrefix = "android-base-"; |
| 42 | static const std::string gConfigSuffix = ".cfg"; |
| 43 | static const std::string gBaseConfig = "android-base.cfg"; |
| 44 | |
Yifan Hong | aa219f5 | 2017-12-18 18:51:59 -0800 | [diff] [blame] | 45 | // 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. |
| 48 | class 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 Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Slurps the device manifest file and add build time flag to it. |
| 62 | */ |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 63 | class AssembleVintfImpl : public AssembleVintf { |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 64 | using Condition = std::unique_ptr<KernelConfig>; |
| 65 | using ConditionedConfig = std::pair<Condition, std::vector<KernelConfig> /* configs */>; |
| 66 | |
| 67 | public: |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 68 | 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 Hong | a28729e | 2018-01-17 13:40:35 -0800 | [diff] [blame] | 79 | // 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 Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 91 | template <typename T> |
| 92 | bool getFlag(const std::string& key, T* value) const { |
| 93 | std::string envValue = getEnv(key); |
| 94 | if (envValue.empty()) { |
| 95 | std::cerr << "Warning: " << key << " is missing, defaulted to " << (*value) << "." |
Yifan Hong | 488e16a | 2017-07-11 13:50:41 -0700 | [diff] [blame] | 96 | << std::endl; |
| 97 | return true; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | if (!parse(envValue, value)) { |
| 101 | std::cerr << "Cannot parse " << envValue << "." << std::endl; |
| 102 | return false; |
| 103 | } |
| 104 | return true; |
| 105 | } |
| 106 | |
Yifan Hong | eff0466 | 2017-12-18 16:27:24 -0800 | [diff] [blame] | 107 | /** |
| 108 | * Set *out to environment variable if *out is not a dummy value (i.e. default constructed). |
| 109 | */ |
| 110 | template <typename T> |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 111 | bool getFlagIfUnset(const std::string& envKey, T* out) const { |
Yifan Hong | eff0466 | 2017-12-18 16:27:24 -0800 | [diff] [blame] | 112 | bool hasExistingValue = !(*out == T{}); |
| 113 | |
| 114 | bool hasEnvValue = false; |
| 115 | T envValue; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 116 | std::string envStrValue = getEnv(envKey); |
| 117 | if (!envStrValue.empty()) { |
| 118 | if (!parse(envStrValue, &envValue)) { |
| 119 | std::cerr << "Cannot parse " << envValue << "." << std::endl; |
Yifan Hong | eff0466 | 2017-12-18 16:27:24 -0800 | [diff] [blame] | 120 | return false; |
| 121 | } |
| 122 | hasEnvValue = true; |
| 123 | } |
| 124 | |
| 125 | if (hasExistingValue) { |
| 126 | if (hasEnvValue) { |
| 127 | std::cerr << "Warning: cannot override existing value " << *out << " with " |
| 128 | << envKey << " (which is " << envValue << ")." << std::endl; |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | if (!hasEnvValue) { |
| 133 | std::cerr << "Warning: " << envKey << " is not specified. Default to " << T{} << "." |
| 134 | << std::endl; |
| 135 | return false; |
| 136 | } |
| 137 | *out = envValue; |
| 138 | return true; |
| 139 | } |
| 140 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 141 | bool getBooleanFlag(const std::string& key) const { return getEnv(key) == std::string("true"); } |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 142 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 143 | size_t getIntegerFlag(const std::string& key, size_t defaultValue = 0) const { |
| 144 | std::string envValue = getEnv(key); |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 145 | if (envValue.empty()) { |
| 146 | return defaultValue; |
| 147 | } |
| 148 | size_t value; |
| 149 | if (!base::ParseUint(envValue, &value)) { |
| 150 | std::cerr << "Error: " << key << " must be a number." << std::endl; |
| 151 | return defaultValue; |
| 152 | } |
| 153 | return value; |
| 154 | } |
| 155 | |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 156 | static std::string read(std::basic_istream<char>& is) { |
| 157 | std::stringstream ss; |
| 158 | ss << is.rdbuf(); |
| 159 | return ss.str(); |
| 160 | } |
| 161 | |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 162 | static bool isCommonConfig(const std::string& path) { |
| 163 | return ::android::base::Basename(path) == gBaseConfig; |
| 164 | } |
| 165 | |
Yifan Hong | 079ec24 | 2017-08-25 18:53:38 -0700 | [diff] [blame] | 166 | // nullptr on any error, otherwise the condition. |
| 167 | static Condition generateCondition(const std::string& path) { |
| 168 | std::string fname = ::android::base::Basename(path); |
| 169 | if (fname.size() <= gConfigPrefix.size() + gConfigSuffix.size() || |
| 170 | !std::equal(gConfigPrefix.begin(), gConfigPrefix.end(), fname.begin()) || |
| 171 | !std::equal(gConfigSuffix.rbegin(), gConfigSuffix.rend(), fname.rbegin())) { |
| 172 | return nullptr; |
| 173 | } |
| 174 | |
| 175 | std::string sub = fname.substr(gConfigPrefix.size(), |
| 176 | fname.size() - gConfigPrefix.size() - gConfigSuffix.size()); |
| 177 | if (sub.empty()) { |
| 178 | return nullptr; // should not happen |
| 179 | } |
| 180 | for (size_t i = 0; i < sub.size(); ++i) { |
| 181 | if (sub[i] == '-') { |
| 182 | sub[i] = '_'; |
| 183 | continue; |
| 184 | } |
| 185 | if (isalnum(sub[i])) { |
| 186 | sub[i] = toupper(sub[i]); |
| 187 | continue; |
| 188 | } |
| 189 | std::cerr << "'" << fname << "' (in " << path |
| 190 | << ") is not a valid kernel config file name. Must match regex: " |
| 191 | << "android-base(-[0-9a-zA-Z-]+)?\\.cfg" << std::endl; |
| 192 | return nullptr; |
| 193 | } |
| 194 | sub.insert(0, "CONFIG_"); |
| 195 | return std::make_unique<KernelConfig>(std::move(sub), Tristate::YES); |
| 196 | } |
| 197 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 198 | static bool parseFileForKernelConfigs(std::basic_istream<char>& stream, |
| 199 | std::vector<KernelConfig>* out) { |
Yifan Hong | 02e9400 | 2017-07-10 15:41:56 -0700 | [diff] [blame] | 200 | KernelConfigParser parser(true /* processComments */, true /* relaxedFormat */); |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 201 | std::string content = read(stream); |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 202 | status_t err = parser.process(content.c_str(), content.size()); |
| 203 | if (err != OK) { |
Yifan Hong | ae53a0e | 2017-07-07 15:19:06 -0700 | [diff] [blame] | 204 | std::cerr << parser.error(); |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 205 | return false; |
| 206 | } |
| 207 | err = parser.finish(); |
| 208 | if (err != OK) { |
Yifan Hong | ae53a0e | 2017-07-07 15:19:06 -0700 | [diff] [blame] | 209 | std::cerr << parser.error(); |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 210 | return false; |
| 211 | } |
| 212 | |
| 213 | for (auto& configPair : parser.configs()) { |
| 214 | out->push_back({}); |
| 215 | KernelConfig& config = out->back(); |
| 216 | config.first = std::move(configPair.first); |
| 217 | if (!parseKernelConfigTypedValue(configPair.second, &config.second)) { |
| 218 | std::cerr << "Unknown value type for key = '" << config.first << "', value = '" |
| 219 | << configPair.second << "'\n"; |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | return true; |
| 224 | } |
| 225 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 226 | static bool parseFilesForKernelConfigs(std::vector<NamedIstream>* streams, |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 227 | std::vector<ConditionedConfig>* out) { |
| 228 | out->clear(); |
| 229 | ConditionedConfig commonConfig; |
| 230 | bool foundCommonConfig = false; |
Steve Muckle | 0bef868 | 2017-07-31 15:47:15 -0700 | [diff] [blame] | 231 | bool ret = true; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 232 | |
| 233 | for (auto& namedStream : *streams) { |
| 234 | if (isCommonConfig(namedStream.name())) { |
| 235 | ret &= parseFileForKernelConfigs(namedStream.stream(), &commonConfig.second); |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 236 | foundCommonConfig = true; |
| 237 | } else { |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 238 | Condition condition = generateCondition(namedStream.name()); |
Yifan Hong | 079ec24 | 2017-08-25 18:53:38 -0700 | [diff] [blame] | 239 | ret &= (condition != nullptr); |
| 240 | |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 241 | std::vector<KernelConfig> kernelConfigs; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 242 | if ((ret &= parseFileForKernelConfigs(namedStream.stream(), &kernelConfigs))) |
Yifan Hong | 079ec24 | 2017-08-25 18:53:38 -0700 | [diff] [blame] | 243 | out->emplace_back(std::move(condition), std::move(kernelConfigs)); |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 244 | } |
Steve Muckle | 0bef868 | 2017-07-31 15:47:15 -0700 | [diff] [blame] | 245 | } |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 246 | |
| 247 | if (!foundCommonConfig) { |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 248 | std::cerr << "No android-base.cfg is found in these paths:" << std::endl; |
| 249 | for (auto& namedStream : *streams) { |
| 250 | std::cerr << " " << namedStream.name() << std::endl; |
| 251 | } |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 252 | } |
| 253 | ret &= foundCommonConfig; |
| 254 | // first element is always common configs (no conditions). |
| 255 | out->insert(out->begin(), std::move(commonConfig)); |
Steve Muckle | 0bef868 | 2017-07-31 15:47:15 -0700 | [diff] [blame] | 256 | return ret; |
| 257 | } |
| 258 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 259 | std::basic_ostream<char>& out() const { return mOutRef == nullptr ? std::cout : *mOutRef; } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 260 | |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 261 | template <typename S> |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 262 | using Schemas = std::vector<Named<S>>; |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 263 | using HalManifests = Schemas<HalManifest>; |
| 264 | using CompatibilityMatrices = Schemas<CompatibilityMatrix>; |
| 265 | |
| 266 | bool assembleHalManifest(HalManifests* halManifests) { |
Yifan Hong | 4650ad8 | 2017-05-01 17:28:02 -0700 | [diff] [blame] | 267 | std::string error; |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 268 | HalManifest* halManifest = &halManifests->front().object; |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 269 | for (auto it = halManifests->begin() + 1; it != halManifests->end(); ++it) { |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 270 | const std::string& path = it->name; |
| 271 | HalManifest& halToAdd = it->object; |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 272 | |
| 273 | if (halToAdd.level() != Level::UNSPECIFIED) { |
| 274 | if (halManifest->level() == Level::UNSPECIFIED) { |
| 275 | halManifest->mLevel = halToAdd.level(); |
| 276 | } else if (halManifest->level() != halToAdd.level()) { |
| 277 | std::cerr << "Inconsistent FCM Version in HAL manifests:" << std::endl |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 278 | << " File '" << halManifests->front().name << "' has level " |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 279 | << halManifest->level() << std::endl |
| 280 | << " File '" << path << "' has level " << halToAdd.level() |
| 281 | << std::endl; |
| 282 | return false; |
| 283 | } |
| 284 | } |
| 285 | |
Yifan Hong | ea25dd4 | 2017-12-18 17:03:24 -0800 | [diff] [blame] | 286 | if (!halManifest->addAllHals(&halToAdd, &error)) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 287 | std::cerr << "File \"" << path << "\" cannot be added: conflict on HAL \"" << error |
| 288 | << "\" with an existing HAL. See <hal> with the same name " |
| 289 | << "in previously parsed files or previously declared in this file." |
| 290 | << std::endl; |
| 291 | return false; |
| 292 | } |
| 293 | } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 294 | |
| 295 | if (halManifest->mType == SchemaType::DEVICE) { |
| 296 | if (!getFlag("BOARD_SEPOLICY_VERS", &halManifest->device.mSepolicyVersion)) { |
| 297 | return false; |
| 298 | } |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 299 | if (!setDeviceFcmVersion(halManifest)) { |
| 300 | return false; |
| 301 | } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Yifan Hong | feb454e | 2018-01-09 16:16:40 -0800 | [diff] [blame] | 304 | if (halManifest->mType == SchemaType::FRAMEWORK) { |
Yifan Hong | a28729e | 2018-01-17 13:40:35 -0800 | [diff] [blame] | 305 | for (auto&& v : getEnvList("PROVIDED_VNDK_VERSIONS")) { |
| 306 | halManifest->framework.mVendorNdks.emplace_back(std::move(v)); |
| 307 | } |
| 308 | |
Yifan Hong | 8b8492b | 2018-01-22 14:08:40 -0800 | [diff] [blame^] | 309 | for (auto&& v : getEnvList("PLATFORM_SYSTEMSDK_VERSIONS")) { |
Yifan Hong | a28729e | 2018-01-17 13:40:35 -0800 | [diff] [blame] | 310 | halManifest->framework.mSystemSdk.mVersions.emplace(std::move(v)); |
Yifan Hong | feb454e | 2018-01-09 16:16:40 -0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 314 | if (mOutputMatrix) { |
| 315 | CompatibilityMatrix generatedMatrix = halManifest->generateCompatibleMatrix(); |
| 316 | if (!halManifest->checkCompatibility(generatedMatrix, &error)) { |
| 317 | std::cerr << "FATAL ERROR: cannot generate a compatible matrix: " << error |
| 318 | << std::endl; |
| 319 | } |
| 320 | out() << "<!-- \n" |
| 321 | " Autogenerated skeleton compatibility matrix. \n" |
| 322 | " Use with caution. Modify it to suit your needs.\n" |
| 323 | " All HALs are set to optional.\n" |
| 324 | " Many entries other than HALs are zero-filled and\n" |
| 325 | " require human attention. \n" |
| 326 | "-->\n" |
Yifan Hong | a2635c4 | 2017-12-12 13:20:33 -0800 | [diff] [blame] | 327 | << gCompatibilityMatrixConverter(generatedMatrix, mSerializeFlags); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 328 | } else { |
Yifan Hong | a2635c4 | 2017-12-12 13:20:33 -0800 | [diff] [blame] | 329 | out() << gHalManifestConverter(*halManifest, mSerializeFlags); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 330 | } |
| 331 | out().flush(); |
| 332 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 333 | if (mCheckFile != nullptr) { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 334 | CompatibilityMatrix checkMatrix; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 335 | if (!gCompatibilityMatrixConverter(&checkMatrix, read(*mCheckFile))) { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 336 | std::cerr << "Cannot parse check file as a compatibility matrix: " |
| 337 | << gCompatibilityMatrixConverter.lastError() << std::endl; |
| 338 | return false; |
| 339 | } |
| 340 | if (!halManifest->checkCompatibility(checkMatrix, &error)) { |
| 341 | std::cerr << "Not compatible: " << error << std::endl; |
| 342 | return false; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | return true; |
| 347 | } |
| 348 | |
Yifan Hong | e88e167 | 2017-08-24 14:42:54 -0700 | [diff] [blame] | 349 | bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) { |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 350 | for (auto& pair : mKernels) { |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 351 | std::vector<ConditionedConfig> conditionedConfigs; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 352 | if (!parseFilesForKernelConfigs(&pair.second, &conditionedConfigs)) { |
Yifan Hong | e88e167 | 2017-08-24 14:42:54 -0700 | [diff] [blame] | 353 | return false; |
| 354 | } |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 355 | for (ConditionedConfig& conditionedConfig : conditionedConfigs) { |
Yifan Hong | 48602df | 2017-08-28 13:04:12 -0700 | [diff] [blame] | 356 | MatrixKernel kernel(KernelVersion{pair.first.majorVer, pair.first.minorVer, 0u}, |
| 357 | std::move(conditionedConfig.second)); |
Yifan Hong | 079ec24 | 2017-08-25 18:53:38 -0700 | [diff] [blame] | 358 | if (conditionedConfig.first != nullptr) |
| 359 | kernel.mConditions.push_back(std::move(*conditionedConfig.first)); |
| 360 | matrix->framework.mKernels.push_back(std::move(kernel)); |
Yifan Hong | 9a8b1a7 | 2017-08-25 17:55:33 -0700 | [diff] [blame] | 361 | } |
Yifan Hong | e88e167 | 2017-08-24 14:42:54 -0700 | [diff] [blame] | 362 | } |
| 363 | return true; |
| 364 | } |
| 365 | |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 366 | bool setDeviceFcmVersion(HalManifest* manifest) { |
| 367 | size_t shippingApiLevel = getIntegerFlag("PRODUCT_SHIPPING_API_LEVEL"); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 368 | |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 369 | if (manifest->level() != Level::UNSPECIFIED) { |
| 370 | return true; |
| 371 | } |
| 372 | if (!getBooleanFlag("PRODUCT_ENFORCE_VINTF_MANIFEST")) { |
| 373 | manifest->mLevel = Level::LEGACY; |
| 374 | return true; |
| 375 | } |
| 376 | // TODO(b/70628538): Do not infer from Shipping API level. |
| 377 | if (shippingApiLevel) { |
| 378 | std::cerr << "Warning: Shipping FCM Version is inferred from Shipping API level. " |
| 379 | << "Declare Shipping FCM Version in device manifest directly." << std::endl; |
Yifan Hong | afae198 | 2018-01-11 18:15:24 -0800 | [diff] [blame] | 380 | manifest->mLevel = details::convertFromApiLevel(shippingApiLevel); |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 381 | if (manifest->mLevel == Level::UNSPECIFIED) { |
| 382 | std::cerr << "Error: Shipping FCM Version cannot be inferred from Shipping API " |
| 383 | << "level " << shippingApiLevel << "." |
| 384 | << "Declare Shipping FCM Version in device manifest directly." |
| 385 | << std::endl; |
| 386 | return false; |
| 387 | } |
| 388 | return true; |
| 389 | } |
| 390 | // TODO(b/69638851): should be an error if Shipping API level is not defined. |
| 391 | // For now, just leave it empty; when framework compatibility matrix is built, |
| 392 | // lowest FCM Version is assumed. |
| 393 | std::cerr << "Warning: Shipping FCM Version cannot be inferred, because:" << std::endl |
| 394 | << " (1) It is not explicitly declared in device manifest;" << std::endl |
| 395 | << " (2) PRODUCT_ENFORCE_VINTF_MANIFEST is set to true;" << std::endl |
| 396 | << " (3) PRODUCT_SHIPPING_API_LEVEL is undefined." << std::endl |
| 397 | << "Assuming 'unspecified' Shipping FCM Version. " << std::endl |
| 398 | << "To remove this warning, define 'level' attribute in device manifest." |
| 399 | << std::endl; |
| 400 | return true; |
| 401 | } |
| 402 | |
| 403 | Level getLowestFcmVersion(const CompatibilityMatrices& matrices) { |
| 404 | Level ret = Level::UNSPECIFIED; |
| 405 | for (const auto& e : matrices) { |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 406 | if (ret == Level::UNSPECIFIED || ret > e.object.level()) { |
| 407 | ret = e.object.level(); |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | bool assembleCompatibilityMatrix(CompatibilityMatrices* matrices) { |
| 414 | std::string error; |
| 415 | CompatibilityMatrix* matrix = nullptr; |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 416 | std::unique_ptr<HalManifest> checkManifest; |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 417 | if (matrices->front().object.mType == SchemaType::DEVICE) { |
| 418 | matrix = &matrices->front().object; |
Yifan Hong | feb454e | 2018-01-09 16:16:40 -0800 | [diff] [blame] | 419 | |
| 420 | auto vndkVersion = base::Trim(getEnv("REQUIRED_VNDK_VERSION")); |
| 421 | if (!vndkVersion.empty()) { |
| 422 | auto& valueInMatrix = matrix->device.mVendorNdk; |
| 423 | if (!valueInMatrix.version().empty() && valueInMatrix.version() != vndkVersion) { |
| 424 | std::cerr << "Hard-coded <vendor-ndk> version in device compatibility matrix (" |
| 425 | << matrices->front().name << "), '" << valueInMatrix.version() |
| 426 | << "', does not match value inferred " |
| 427 | << "from BOARD_VNDK_VERSION '" << vndkVersion << "'" << std::endl; |
| 428 | return false; |
| 429 | } |
| 430 | valueInMatrix = VendorNdk{std::move(vndkVersion)}; |
| 431 | } |
Yifan Hong | a28729e | 2018-01-17 13:40:35 -0800 | [diff] [blame] | 432 | |
| 433 | for (auto&& v : getEnvList("BOARD_SYSTEMSDK_VERSIONS")) { |
| 434 | matrix->device.mSystemSdk.mVersions.emplace(std::move(v)); |
| 435 | } |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 438 | if (matrices->front().object.mType == SchemaType::FRAMEWORK) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 439 | Level deviceLevel = Level::UNSPECIFIED; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 440 | if (mCheckFile != nullptr) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 441 | checkManifest = std::make_unique<HalManifest>(); |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 442 | if (!gHalManifestConverter(checkManifest.get(), read(*mCheckFile))) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 443 | std::cerr << "Cannot parse check file as a HAL manifest: " |
| 444 | << gHalManifestConverter.lastError() << std::endl; |
| 445 | return false; |
| 446 | } |
| 447 | deviceLevel = checkManifest->level(); |
| 448 | } |
| 449 | |
| 450 | if (deviceLevel == Level::UNSPECIFIED) { |
| 451 | // For GSI build, legacy devices that do not have a HAL manifest, |
| 452 | // and devices in development, merge all compatibility matrices. |
| 453 | deviceLevel = getLowestFcmVersion(*matrices); |
| 454 | } |
| 455 | |
Yifan Hong | ddae77e | 2017-12-18 16:57:07 -0800 | [diff] [blame] | 456 | if (deviceLevel == Level::UNSPECIFIED) { |
| 457 | // building empty.xml |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 458 | matrix = &matrices->front().object; |
Yifan Hong | ddae77e | 2017-12-18 16:57:07 -0800 | [diff] [blame] | 459 | } else { |
| 460 | matrix = CompatibilityMatrix::combine(deviceLevel, matrices, &error); |
| 461 | if (matrix == nullptr) { |
| 462 | std::cerr << error << std::endl; |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 463 | return false; |
| 464 | } |
| 465 | } |
| 466 | |
Yifan Hong | e88e167 | 2017-08-24 14:42:54 -0700 | [diff] [blame] | 467 | if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) { |
| 468 | return false; |
Yifan Hong | 79efa8a | 2017-07-06 14:10:28 -0700 | [diff] [blame] | 469 | } |
Yifan Hong | e88e167 | 2017-08-24 14:42:54 -0700 | [diff] [blame] | 470 | |
Yifan Hong | f413501 | 2017-12-18 17:27:19 -0800 | [diff] [blame] | 471 | // set sepolicy.sepolicy-version to BOARD_SEPOLICY_VERS when none is specified. |
| 472 | std::vector<VersionRange>* sepolicyVrs = |
| 473 | &matrix->framework.mSepolicy.mSepolicyVersionRanges; |
| 474 | VersionRange sepolicyVr; |
| 475 | if (!sepolicyVrs->empty()) sepolicyVr = sepolicyVrs->front(); |
| 476 | if (getFlagIfUnset("BOARD_SEPOLICY_VERS", &sepolicyVr)) { |
| 477 | *sepolicyVrs = {{sepolicyVr}}; |
Yifan Hong | 7f6c00c | 2017-07-06 19:50:29 +0000 | [diff] [blame] | 478 | } |
Yifan Hong | f413501 | 2017-12-18 17:27:19 -0800 | [diff] [blame] | 479 | |
| 480 | getFlagIfUnset("POLICYVERS", &matrix->framework.mSepolicy.mKernelSepolicyVersion); |
| 481 | getFlagIfUnset("FRAMEWORK_VBMETA_VERSION", &matrix->framework.mAvbMetaVersion); |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 482 | |
| 483 | out() << "<!--" << std::endl; |
| 484 | out() << " Input:" << std::endl; |
Yifan Hong | ddae77e | 2017-12-18 16:57:07 -0800 | [diff] [blame] | 485 | for (const auto& e : *matrices) { |
Yifan Hong | ffcaf99 | 2018-01-09 17:08:51 -0800 | [diff] [blame] | 486 | if (!e.name.empty()) { |
Yifan Hong | 4f67f3b | 2018-01-11 17:05:47 -0800 | [diff] [blame] | 487 | out() << " " << base::Basename(e.name) << std::endl; |
Yifan Hong | ddae77e | 2017-12-18 16:57:07 -0800 | [diff] [blame] | 488 | } |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 489 | } |
| 490 | out() << "-->" << std::endl; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 491 | } |
Yifan Hong | a2635c4 | 2017-12-12 13:20:33 -0800 | [diff] [blame] | 492 | out() << gCompatibilityMatrixConverter(*matrix, mSerializeFlags); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 493 | out().flush(); |
| 494 | |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 495 | if (checkManifest != nullptr && getBooleanFlag("PRODUCT_ENFORCE_VINTF_MANIFEST") && |
| 496 | !checkManifest->checkCompatibility(*matrix, &error)) { |
| 497 | std::cerr << "Not compatible: " << error << std::endl; |
| 498 | return false; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | return true; |
| 502 | } |
| 503 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 504 | enum AssembleStatus { SUCCESS, FAIL_AND_EXIT, TRY_NEXT }; |
| 505 | template <typename Schema, typename AssembleFunc> |
| 506 | AssembleStatus tryAssemble(const XmlConverter<Schema>& converter, const std::string& schemaName, |
| 507 | AssembleFunc assemble) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 508 | Schemas<Schema> schemas; |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 509 | Schema schema; |
Yifan Hong | aa219f5 | 2017-12-18 18:51:59 -0800 | [diff] [blame] | 510 | if (!converter(&schema, read(mInFiles.front().stream()))) { |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 511 | return TRY_NEXT; |
| 512 | } |
| 513 | auto firstType = schema.type(); |
Yifan Hong | aa219f5 | 2017-12-18 18:51:59 -0800 | [diff] [blame] | 514 | schemas.emplace_back(mInFiles.front().name(), std::move(schema)); |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 515 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 516 | for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) { |
| 517 | Schema additionalSchema; |
Yifan Hong | aa219f5 | 2017-12-18 18:51:59 -0800 | [diff] [blame] | 518 | const std::string& fileName = it->name(); |
| 519 | if (!converter(&additionalSchema, read(it->stream()))) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 520 | std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " " |
| 521 | << schemaName << " (but the first file is a valid " << firstType << " " |
| 522 | << schemaName << "). Error: " << converter.lastError() << std::endl; |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 523 | return FAIL_AND_EXIT; |
| 524 | } |
| 525 | if (additionalSchema.type() != firstType) { |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 526 | std::cerr << "File \"" << fileName << "\" is a " << additionalSchema.type() << " " |
| 527 | << schemaName << " (but a " << firstType << " " << schemaName |
| 528 | << " is expected)." << std::endl; |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 529 | return FAIL_AND_EXIT; |
| 530 | } |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 531 | |
| 532 | schemas.emplace_back(fileName, std::move(additionalSchema)); |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 533 | } |
Yifan Hong | dbe9db3 | 2017-12-11 19:06:11 -0800 | [diff] [blame] | 534 | return assemble(&schemas) ? SUCCESS : FAIL_AND_EXIT; |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 537 | bool assemble() override { |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 538 | using std::placeholders::_1; |
| 539 | if (mInFiles.empty()) { |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 540 | std::cerr << "Missing input file." << std::endl; |
| 541 | return false; |
| 542 | } |
| 543 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 544 | auto status = tryAssemble(gHalManifestConverter, "manifest", |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 545 | std::bind(&AssembleVintfImpl::assembleHalManifest, this, _1)); |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 546 | if (status == SUCCESS) return true; |
| 547 | if (status == FAIL_AND_EXIT) return false; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 548 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 549 | resetInFiles(); |
Yifan Hong | a59d256 | 2017-04-18 18:01:16 -0700 | [diff] [blame] | 550 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 551 | status = tryAssemble(gCompatibilityMatrixConverter, "compatibility matrix", |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 552 | std::bind(&AssembleVintfImpl::assembleCompatibilityMatrix, this, _1)); |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 553 | if (status == SUCCESS) return true; |
| 554 | if (status == FAIL_AND_EXIT) return false; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 555 | |
Yifan Hong | 959ee1b | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 556 | std::cerr << "Input file has unknown format." << std::endl |
| 557 | << "Error when attempting to convert to manifest: " |
| 558 | << gHalManifestConverter.lastError() << std::endl |
| 559 | << "Error when attempting to convert to compatibility matrix: " |
| 560 | << gCompatibilityMatrixConverter.lastError() << std::endl; |
| 561 | return false; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 562 | } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 563 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 564 | std::ostream& setOutputStream(Ostream&& out) override { |
| 565 | mOutRef = std::move(out); |
| 566 | return *mOutRef; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 569 | std::istream& addInputStream(const std::string& name, Istream&& in) override { |
| 570 | auto it = mInFiles.emplace(mInFiles.end(), name, std::move(in)); |
| 571 | return it->stream(); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 574 | std::istream& setCheckInputStream(Istream&& in) override { |
| 575 | mCheckFile = std::move(in); |
| 576 | return *mCheckFile; |
| 577 | } |
| 578 | |
| 579 | bool hasKernelVersion(const Version& kernelVer) const override { |
| 580 | return mKernels.find(kernelVer) != mKernels.end(); |
| 581 | } |
| 582 | |
| 583 | std::istream& addKernelConfigInputStream(const Version& kernelVer, const std::string& name, |
| 584 | Istream&& in) override { |
| 585 | auto&& kernel = mKernels[kernelVer]; |
| 586 | auto it = kernel.emplace(kernel.end(), name, std::move(in)); |
| 587 | return it->stream(); |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 590 | void resetInFiles() { |
| 591 | for (auto& inFile : mInFiles) { |
Yifan Hong | aa219f5 | 2017-12-18 18:51:59 -0800 | [diff] [blame] | 592 | inFile.stream().clear(); |
| 593 | inFile.stream().seekg(0); |
Yifan Hong | bfb3c1d | 2017-05-24 14:38:48 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 597 | void setOutputMatrix() override { mOutputMatrix = true; } |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 598 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 599 | bool setHalsOnly() override { |
Yifan Hong | a2635c4 | 2017-12-12 13:20:33 -0800 | [diff] [blame] | 600 | if (mSerializeFlags) return false; |
| 601 | mSerializeFlags |= SerializeFlag::HALS_ONLY; |
| 602 | return true; |
| 603 | } |
| 604 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 605 | bool setNoHals() override { |
Yifan Hong | a2635c4 | 2017-12-12 13:20:33 -0800 | [diff] [blame] | 606 | if (mSerializeFlags) return false; |
| 607 | mSerializeFlags |= SerializeFlag::NO_HALS; |
| 608 | return true; |
| 609 | } |
| 610 | |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 611 | private: |
Yifan Hong | aa219f5 | 2017-12-18 18:51:59 -0800 | [diff] [blame] | 612 | std::vector<NamedIstream> mInFiles; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 613 | Ostream mOutRef; |
| 614 | Istream mCheckFile; |
Yifan Hong | 9aa6370 | 2017-05-16 16:37:50 -0700 | [diff] [blame] | 615 | bool mOutputMatrix = false; |
Yifan Hong | a2635c4 | 2017-12-12 13:20:33 -0800 | [diff] [blame] | 616 | SerializeFlags mSerializeFlags = SerializeFlag::EVERYTHING; |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 617 | std::map<Version, std::vector<NamedIstream>> mKernels; |
| 618 | std::map<std::string, std::string> mFakeEnv; |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 619 | }; |
| 620 | |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 621 | bool AssembleVintf::openOutFile(const std::string& path) { |
| 622 | return static_cast<std::ofstream&>(setOutputStream(std::make_unique<std::ofstream>(path))) |
| 623 | .is_open(); |
| 624 | } |
| 625 | |
| 626 | bool AssembleVintf::openInFile(const std::string& path) { |
| 627 | return static_cast<std::ifstream&>(addInputStream(path, std::make_unique<std::ifstream>(path))) |
| 628 | .is_open(); |
| 629 | } |
| 630 | |
| 631 | bool AssembleVintf::openCheckFile(const std::string& path) { |
| 632 | return static_cast<std::ifstream&>(setCheckInputStream(std::make_unique<std::ifstream>(path))) |
| 633 | .is_open(); |
| 634 | } |
| 635 | |
| 636 | bool AssembleVintf::addKernel(const std::string& kernelArg) { |
Yifan Hong | b83e56b | 2018-01-09 14:36:30 -0800 | [diff] [blame] | 637 | auto tokens = base::Split(kernelArg, ":"); |
Yifan Hong | 8302cea | 2017-12-18 20:17:05 -0800 | [diff] [blame] | 638 | if (tokens.size() <= 1) { |
| 639 | std::cerr << "Unrecognized --kernel option '" << kernelArg << "'" << std::endl; |
| 640 | return false; |
| 641 | } |
| 642 | Version kernelVer; |
| 643 | if (!parse(tokens.front(), &kernelVer)) { |
| 644 | std::cerr << "Unrecognized kernel version '" << tokens.front() << "'" << std::endl; |
| 645 | return false; |
| 646 | } |
| 647 | if (hasKernelVersion(kernelVer)) { |
| 648 | std::cerr << "Multiple --kernel for " << kernelVer << " is specified." << std::endl; |
| 649 | return false; |
| 650 | } |
| 651 | for (auto it = tokens.begin() + 1; it != tokens.end(); ++it) { |
| 652 | bool opened = |
| 653 | static_cast<std::ifstream&>( |
| 654 | addKernelConfigInputStream(kernelVer, *it, std::make_unique<std::ifstream>(*it))) |
| 655 | .is_open(); |
| 656 | if (!opened) { |
| 657 | std::cerr << "Cannot open file '" << *it << "'." << std::endl; |
| 658 | return false; |
| 659 | } |
| 660 | } |
| 661 | return true; |
| 662 | } |
| 663 | |
| 664 | std::unique_ptr<AssembleVintf> AssembleVintf::newInstance() { |
| 665 | return std::make_unique<AssembleVintfImpl>(); |
| 666 | } |
| 667 | |
Yifan Hong | 4d18bcc | 2017-04-07 21:47:16 +0000 | [diff] [blame] | 668 | } // namespace vintf |
| 669 | } // namespace android |