Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [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 | #ifndef AAPT2_ABISPLITTER_H |
| 18 | #define AAPT2_ABISPLITTER_H |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <string> |
| 22 | #include <unordered_set> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "configuration/ConfigurationParser.h" |
| 26 | #include "filter/Filter.h" |
| 27 | |
| 28 | namespace aapt { |
| 29 | |
| 30 | /** |
| 31 | * Filters native library paths by ABI. ABIs present in the filter list are kept and all over |
| 32 | * libraries are removed. The filter is only applied to native library paths (this under lib/). |
| 33 | */ |
| 34 | class AbiFilter : public IPathFilter { |
| 35 | public: |
| 36 | /** Factory method to create a filter from a list of configuration::Abi. */ |
| 37 | static std::unique_ptr<AbiFilter> FromAbiList(const std::vector<configuration::Abi>& abi_list); |
| 38 | |
| 39 | /** Returns true if the path is for a native library in the list of desired ABIs. */ |
| 40 | bool Keep(const std::string& path) override; |
| 41 | |
| 42 | private: |
| 43 | explicit AbiFilter(std::unordered_set<std::string> abis) : abis_(std::move(abis)) { |
| 44 | } |
| 45 | |
| 46 | /** The path prefix to where all native libs end up inside an APK file. */ |
| 47 | static constexpr const char* kLibPrefix = "lib/"; |
| 48 | static constexpr size_t kLibPrefixLen = 4; |
| 49 | const std::unordered_set<std::string> abis_; |
| 50 | }; |
| 51 | |
| 52 | } // namespace aapt |
| 53 | |
| 54 | #endif // AAPT2_ABISPLITTER_H |