summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2017-08-25 20:53:38 -0500
committerYifan Hong2017-08-28 14:57:25 -0500
commit8410997ba0eeae782739ddd6921fea1d73ede13e (patch)
tree01b42874dad270edd3c2c60375f467673e73311e
parent9f12df5a9890fe84d2c666a6e54b234aa90cc461 (diff)
downloadplatform-system-libvintf-8410997ba0eeae782739ddd6921fea1d73ede13e.tar.gz
platform-system-libvintf-8410997ba0eeae782739ddd6921fea1d73ede13e.tar.xz
platform-system-libvintf-8410997ba0eeae782739ddd6921fea1d73ede13e.zip
assemble_vintf: add generateConditions
Generate <condition> tag for the kernel config fragment based on the architechture. android-base-foo.cfg -> CONFIG_FOO=y For example, requirements in android-base-arm64.cfg are only enforced when CONFIG_ARM64=y. Test: m system_compatibility_matrix.xml -j Bug: 64124223 Change-Id: Ib094fb476b8521e0fcce8a73302335d127805fc5
-rw-r--r--assemble_vintf.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/assemble_vintf.cpp b/assemble_vintf.cpp
index 251d4bc..3218d1d 100644
--- a/assemble_vintf.cpp
+++ b/assemble_vintf.cpp
@@ -73,6 +73,38 @@ class AssembleVintf {
73 return ::android::base::Basename(path) == gBaseConfig; 73 return ::android::base::Basename(path) == gBaseConfig;
74 } 74 }
75 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
76 static bool parseFileForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) { 108 static bool parseFileForKernelConfigs(const std::string& path, std::vector<KernelConfig>* out) {
77 std::ifstream ifs{path}; 109 std::ifstream ifs{path};
78 if (!ifs.is_open()) { 110 if (!ifs.is_open()) {
@@ -120,9 +152,12 @@ class AssembleVintf {
120 ret &= parseFileForKernelConfigs(pathIter, &commonConfig.second); 152 ret &= parseFileForKernelConfigs(pathIter, &commonConfig.second);
121 foundCommonConfig = true; 153 foundCommonConfig = true;
122 } else { 154 } else {
155 Condition condition = generateCondition(pathIter);
156 ret &= (condition != nullptr);
157
123 std::vector<KernelConfig> kernelConfigs; 158 std::vector<KernelConfig> kernelConfigs;
124 if ((ret &= parseFileForKernelConfigs(pathIter, &kernelConfigs))) 159 if ((ret &= parseFileForKernelConfigs(pathIter, &kernelConfigs)))
125 out->emplace_back(nullptr, std::move(kernelConfigs)); 160 out->emplace_back(std::move(condition), std::move(kernelConfigs));
126 } 161 }
127 pathIter = strtok(NULL, ":"); 162 pathIter = strtok(NULL, ":");
128 } 163 }
@@ -203,8 +238,10 @@ class AssembleVintf {
203 return false; 238 return false;
204 } 239 }
205 for (ConditionedConfig& conditionedConfig : conditionedConfigs) { 240 for (ConditionedConfig& conditionedConfig : conditionedConfigs) {
206 matrix->framework.mKernels.push_back( 241 MatrixKernel kernel(KernelVersion{pair.first}, std::move(conditionedConfig.second));
207 MatrixKernel{KernelVersion{pair.first}, std::move(conditionedConfig.second)}); 242 if (conditionedConfig.first != nullptr)
243 kernel.mConditions.push_back(std::move(*conditionedConfig.first));
244 matrix->framework.mKernels.push_back(std::move(kernel));
208 } 245 }
209 } 246 }
210 return true; 247 return true;