summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-08-30 02:28:59 -0500
committerandroid-build-team Robot2017-08-30 02:28:59 -0500
commit3650e2fc4e7214b4ac8b243ed4ea60eea824fafb (patch)
tree757ed780f286d54e63fabe5338fc7e7495795fc0
parent97152a35dad0896acc8554307d5f3e383500e044 (diff)
parentbfbbdeac0982c3c3851075fe000fe626a2bb54bf (diff)
downloadplatform-system-libvintf-3650e2fc4e7214b4ac8b243ed4ea60eea824fafb.tar.gz
platform-system-libvintf-3650e2fc4e7214b4ac8b243ed4ea60eea824fafb.tar.xz
platform-system-libvintf-3650e2fc4e7214b4ac8b243ed4ea60eea824fafb.zip
release-request-81b48854-d0e0-49af-bcf2-857273cbb8dc-for-git_oc-mr1-release-4306444 snap-temp-L17300000097872583
Change-Id: I77d08f512193f6a1476b230884253a4a4970274e
-rw-r--r--Android.bp3
-rw-r--r--assemble_vintf.cpp129
2 files changed, 109 insertions, 23 deletions
diff --git a/Android.bp b/Android.bp
index 70c7dc8..a6bfe7f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -90,7 +90,8 @@ cc_binary_host {
90 name: "assemble_vintf", 90 name: "assemble_vintf",
91 cflags: libvintf_flags, 91 cflags: libvintf_flags,
92 shared_libs: [ 92 shared_libs: [
93 "libvintf" 93 "libvintf",
94 "libbase",
94 ], 95 ],
95 srcs: [ 96 srcs: [
96 "assemble_vintf.cpp" 97 "assemble_vintf.cpp"
diff --git a/assemble_vintf.cpp b/assemble_vintf.cpp
index d75e889..974c7fc 100644
--- a/assemble_vintf.cpp
+++ b/assemble_vintf.cpp
@@ -24,6 +24,8 @@
24#include <sstream> 24#include <sstream>
25#include <string> 25#include <string>
26 26
27#include <android-base/file.h>
28
27#include <vintf/KernelConfigParser.h> 29#include <vintf/KernelConfigParser.h>
28#include <vintf/parse_string.h> 30#include <vintf/parse_string.h>
29#include <vintf/parse_xml.h> 31#include <vintf/parse_xml.h>
@@ -33,11 +35,18 @@
33namespace android { 35namespace android {
34namespace vintf { 36namespace vintf {
35 37
38static const std::string gConfigPrefix = "android-base-";
39static const std::string gConfigSuffix = ".cfg";
40static const std::string gBaseConfig = "android-base.cfg";
41
36/** 42/**
37 * Slurps the device manifest file and add build time flag to it. 43 * Slurps the device manifest file and add build time flag to it.
38 */ 44 */
39class AssembleVintf { 45class AssembleVintf {
40public: 46 using Condition = std::unique_ptr<KernelConfig>;
47 using ConditionedConfig = std::pair<Condition, std::vector<KernelConfig> /* configs */>;
48
49 public:
41 template<typename T> 50 template<typename T>
42 static bool getFlag(const std::string& key, T* value) { 51 static bool getFlag(const std::string& key, T* value) {
43 const char *envValue = getenv(key.c_str()); 52 const char *envValue = getenv(key.c_str());
@@ -60,6 +69,42 @@ public:
60 return ss.str(); 69 return ss.str();
61 } 70 }
62 71
72 static bool isCommonConfig(const std::string& path) {
73 return ::android::base::Basename(path) == gBaseConfig;
74 }
75
76 // nullptr on any error, otherwise the condition.
77 static Condition generateCondition(const std::string& path) {
78 std::string fname = ::android::base::Basename(path);
79 if (fname.size() <= gConfigPrefix.size() + gConfigSuffix.size() ||
80 !std::equal(gConfigPrefix.begin(), gConfigPrefix.end(), fname.begin()) ||
81 !std::equal(gConfigSuffix.rbegin(), gConfigSuffix.rend(), fname.rbegin())) {
82 return nullptr;
83 }
84
85 std::string sub = fname.substr(gConfigPrefix.size(),
86 fname.size() - gConfigPrefix.size() - gConfigSuffix.size());
87 if (sub.empty()) {
88 return nullptr; // should not happen
89 }
90 for (size_t i = 0; i < sub.size(); ++i) {
91 if (sub[i] == '-') {
92 sub[i] = '_';
93 continue;
94 }
95 if (isalnum(sub[i])) {
96 sub[i] = toupper(sub[i]);
97 continue;
98 }
99 std::cerr << "'" << fname << "' (in " << path
100 << ") is not a valid kernel config file name. Must match regex: "
101 << "android-base(-[0-9a-zA-Z-]+)?\\.cfg" << std::endl;
102 return nullptr;
103 }
104 sub.insert(0, "CONFIG_");
105 return std::make_unique<KernelConfig>(std::move(sub), Tristate::YES);
106 }
107
63 static bool parseFileForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) { 108 static bool parseFileForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) {
64 std::ifstream ifs{path}; 109 std::ifstream ifs{path};
65 if (!ifs.is_open()) { 110 if (!ifs.is_open()) {
@@ -92,17 +137,39 @@ public:
92 return true; 137 return true;
93 } 138 }
94 139
95 static bool parseFilesForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) { 140 static bool parseFilesForKernelConfigs(const std::string& path,
141 std::vector<ConditionedConfig>* out) {
142 out->clear();
143 ConditionedConfig commonConfig;
144 bool foundCommonConfig = false;
96 bool ret = true; 145 bool ret = true;
97 char *pathIter; 146 char *pathIter;
98 char *modPath = new char[path.length() + 1]; 147 char *modPath = new char[path.length() + 1];
99 strcpy(modPath, path.c_str()); 148 strcpy(modPath, path.c_str());
100 pathIter = strtok(modPath, ":"); 149 pathIter = strtok(modPath, ":");
101 while (ret && pathIter != NULL) { 150 while (ret && pathIter != NULL) {
102 ret &= parseFileForKernelConfigs(pathIter, out); 151 if (isCommonConfig(pathIter)) {
152 ret &= parseFileForKernelConfigs(pathIter, &commonConfig.second);
153 foundCommonConfig = true;
154 } else {
155 Condition condition = generateCondition(pathIter);
156 ret &= (condition != nullptr);
157
158 std::vector<KernelConfig> kernelConfigs;
159 if ((ret &= parseFileForKernelConfigs(pathIter, &kernelConfigs)))
160 out->emplace_back(std::move(condition), std::move(kernelConfigs));
161 }
103 pathIter = strtok(NULL, ":"); 162 pathIter = strtok(NULL, ":");
104 } 163 }
105 delete[] modPath; 164 delete[] modPath;
165
166 if (!foundCommonConfig) {
167 std::cerr << "No android-base.cfg is found in these paths: '" << path << "'"
168 << std::endl;
169 }
170 ret &= foundCommonConfig;
171 // first element is always common configs (no conditions).
172 out->insert(out->begin(), std::move(commonConfig));
106 return ret; 173 return ret;
107 } 174 }
108 175
@@ -154,6 +221,33 @@ public:
154 return true; 221 return true;
155 } 222 }
156 223
224 bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) {
225 if (!matrix->framework.mKernels.empty()) {
226 // Remove hard-coded <kernel version="x.y.z" /> in legacy files.
227 std::cerr << "WARNING: framework compatibility matrix has hard-coded kernel"
228 << " requirements for version";
229 for (const auto& kernel : matrix->framework.mKernels) {
230 std::cerr << " " << kernel.minLts();
231 }
232 std::cerr << ". Hard-coded requirements are removed." << std::endl;
233 matrix->framework.mKernels.clear();
234 }
235 for (const auto& pair : mKernels) {
236 std::vector<ConditionedConfig> conditionedConfigs;
237 if (!parseFilesForKernelConfigs(pair.second, &conditionedConfigs)) {
238 return false;
239 }
240 for (ConditionedConfig& conditionedConfig : conditionedConfigs) {
241 MatrixKernel kernel(KernelVersion{pair.first.majorVer, pair.first.minorVer, 0u},
242 std::move(conditionedConfig.second));
243 if (conditionedConfig.first != nullptr)
244 kernel.mConditions.push_back(std::move(*conditionedConfig.first));
245 matrix->framework.mKernels.push_back(std::move(kernel));
246 }
247 }
248 return true;
249 }
250
157 bool assembleCompatibilityMatrix(CompatibilityMatrix* matrix) { 251 bool assembleCompatibilityMatrix(CompatibilityMatrix* matrix) {
158 std::string error; 252 std::string error;
159 253
@@ -166,24 +260,11 @@ public:
166 if (!getFlag("POLICYVERS", &kernelSepolicyVers)) { 260 if (!getFlag("POLICYVERS", &kernelSepolicyVers)) {
167 return false; 261 return false;
168 } 262 }
169 for (const auto& pair : mKernels) { 263
170 std::vector<KernelConfig> configs; 264 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) {
171 if (!parseFilesForKernelConfigs(pair.second, &configs)) { 265 return false;
172 return false;
173 }
174 bool added = false;
175 for (auto& e : matrix->framework.mKernels) {
176 if (e.minLts() == pair.first) {
177 e.mConfigs.insert(e.mConfigs.end(), configs.begin(), configs.end());
178 added = true;
179 break;
180 }
181 }
182 if (!added) {
183 matrix->framework.mKernels.push_back(
184 MatrixKernel{KernelVersion{pair.first}, std::move(configs)});
185 }
186 } 266 }
267
187 matrix->framework.mSepolicy = 268 matrix->framework.mSepolicy =
188 Sepolicy(kernelSepolicyVers, {{sepolicyVers.majorVer, sepolicyVers.minorVer}}); 269 Sepolicy(kernelSepolicyVers, {{sepolicyVers.majorVer, sepolicyVers.minorVer}});
189 270
@@ -309,7 +390,11 @@ public:
309 std::cerr << "Unrecognized kernel version '" << kernelVerStr << "'" << std::endl; 390 std::cerr << "Unrecognized kernel version '" << kernelVerStr << "'" << std::endl;
310 return false; 391 return false;
311 } 392 }
312 mKernels.push_back({{kernelVer.majorVer, kernelVer.minorVer, 0u}, kernelConfigPath}); 393 if (mKernels.find(kernelVer) != mKernels.end()) {
394 std::cerr << "Multiple --kernel for " << kernelVer << " is specified." << std::endl;
395 return false;
396 }
397 mKernels[kernelVer] = kernelConfigPath;
313 return true; 398 return true;
314 } 399 }
315 400
@@ -319,7 +404,7 @@ public:
319 std::unique_ptr<std::ofstream> mOutFileRef; 404 std::unique_ptr<std::ofstream> mOutFileRef;
320 std::ifstream mCheckFile; 405 std::ifstream mCheckFile;
321 bool mOutputMatrix = false; 406 bool mOutputMatrix = false;
322 std::vector<std::pair<KernelVersion, std::string>> mKernels; 407 std::map<Version, std::string> mKernels;
323}; 408};
324 409
325} // namespace vintf 410} // namespace vintf