• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #pragma once
17 
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 #include "linkerconfig/configwriter.h"
23 #include "linkerconfig/log.h"
24 
25 #define LOG_TAG "linkerconfig"
26 
27 namespace android {
28 namespace linkerconfig {
29 namespace modules {
30 class Link {
31  public:
32   Link(const std::string& origin_namespace, const std::string& target_namespace,
33        bool allow_all_shared_libs = false)
origin_namespace_(origin_namespace)34       : origin_namespace_(origin_namespace),
35         target_namespace_(target_namespace),
36         allow_all_shared_libs_(allow_all_shared_libs) {
37   }
38   template <typename T, typename... Args>
39   void AddSharedLib(T&& lib_name, Args&&... lib_names);
40   void WriteConfig(ConfigWriter& writer);
41 
42  private:
43   const std::string origin_namespace_;
44   const std::string target_namespace_;
45   const bool allow_all_shared_libs_;
46   std::vector<std::string> shared_libs_;
47 };
48 
49 template <typename T, typename... Args>
AddSharedLib(T && lib_name,Args &&...lib_names)50 void Link::AddSharedLib(T&& lib_name, Args&&... lib_names) {
51   if (allow_all_shared_libs_) {
52     LOG(WARNING) << "Tried to add shared libraries to link from "
53                  << origin_namespace_ << " to " << target_namespace_
54                  << "while this link is allow_all_shared_libs";
55     return;
56   }
57   shared_libs_.push_back(std::forward<T>(lib_name));
58   if constexpr (sizeof...(Args) > 0) {
59     AddSharedLib(std::forward<Args>(lib_names)...);
60   }
61 }
62 }  // namespace modules
63 }  // namespace linkerconfig
64 }  // namespace android