Jooyung Han | 86b57f6 | 2020-01-06 18:09:30 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | #include "linkerconfig/apex.h" |
| 17 | |
| 18 | #include <unistd.h> |
| 19 | |
| 20 | #include <apexutil.h> |
| 21 | |
| 22 | namespace { |
| 23 | bool DirExists(const std::string& path) { |
| 24 | return access(path.c_str(), F_OK) == 0; |
| 25 | } |
| 26 | } // namespace |
| 27 | |
| 28 | namespace android { |
| 29 | namespace linkerconfig { |
| 30 | namespace modules { |
| 31 | std::map<std::string, ApexInfo> ScanActiveApexes(const std::string& apex_root) { |
| 32 | std::map<std::string, ApexInfo> apexes; |
| 33 | for (const auto& [path, manifest] : apex::GetActivePackages(apex_root)) { |
| 34 | bool has_bin = DirExists(path + "/bin"); |
| 35 | bool has_lib = DirExists(path + "/lib") || DirExists(path + "/lib64"); |
| 36 | ApexInfo info(manifest.name(), |
| 37 | path, |
| 38 | {manifest.providenativelibs().begin(), |
| 39 | manifest.providenativelibs().end()}, |
| 40 | {manifest.requirenativelibs().begin(), |
| 41 | manifest.requirenativelibs().end()}, |
| 42 | has_bin, |
| 43 | has_lib); |
| 44 | apexes.emplace(manifest.name(), std::move(info)); |
| 45 | } |
| 46 | return apexes; |
| 47 | } |
| 48 | } // namespace modules |
| 49 | } // namespace linkerconfig |
| 50 | } // namespace android |