1 /*
2  * Copyright (C) 2022 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 #include <string>
18 #include <vector>
19 
20 #include "android-base/stringprintf.h"
21 #include "base/file_utils.h"
22 #include "base/globals.h"
23 
24 namespace art {
25 namespace testing {
26 
27 namespace {
28 
GetDexFileName(const std::string & jar_prefix,const std::string & prefix)29 std::string GetDexFileName(const std::string& jar_prefix, const std::string& prefix) {
30   const char* apexPath =
31       (jar_prefix == "conscrypt") ?
32           kAndroidConscryptApexDefaultPath :
33           (jar_prefix == "core-icu4j" ? kAndroidI18nApexDefaultPath : kAndroidArtApexDefaultPath);
34   return android::base::StringPrintf(
35       "%s%s/javalib/%s.jar", prefix.c_str(), apexPath, jar_prefix.c_str());
36 }
37 
38 }  // namespace
39 
GetLibCoreModuleNames(bool core_only)40 std::vector<std::string> GetLibCoreModuleNames(bool core_only) {
41   // Note: This must start with the CORE_IMG_JARS in Android.common_path.mk because that's what we
42   // use for compiling the boot.art image. It may contain additional modules from TEST_CORE_JARS.
43 
44   // CORE_IMG_JARS modules.
45   std::vector<std::string> modules{
46       "core-oj",
47       "core-libart",
48       "okhttp",
49       "bouncycastle",
50       "apache-xml",
51   };
52 
53   // Additional modules.
54   if (!core_only) {
55     modules.push_back("core-icu4j");
56     modules.push_back("conscrypt");
57   }
58 
59   return modules;
60 }
61 
GetLibCoreDexFileNames(const std::string & prefix,const std::vector<std::string> & modules)62 std::vector<std::string> GetLibCoreDexFileNames(const std::string& prefix,
63                                                 const std::vector<std::string>& modules) {
64   std::vector<std::string> result;
65   result.reserve(modules.size());
66   for (const std::string& module : modules) {
67     result.push_back(GetDexFileName(module, prefix));
68   }
69   return result;
70 }
71 
GetLibCoreDexFileNames(const std::string & prefix,bool core_only)72 std::vector<std::string> GetLibCoreDexFileNames(const std::string& prefix, bool core_only) {
73   std::vector<std::string> modules = GetLibCoreModuleNames(core_only);
74   return GetLibCoreDexFileNames(prefix, modules);
75 }
76 
GetLibCoreDexLocations(const std::vector<std::string> & modules)77 std::vector<std::string> GetLibCoreDexLocations(const std::vector<std::string>& modules) {
78   return GetLibCoreDexFileNames(/*prefix=*/"", modules);
79 }
80 
GetLibCoreDexLocations(bool core_only)81 std::vector<std::string> GetLibCoreDexLocations(bool core_only) {
82   std::vector<std::string> modules = GetLibCoreModuleNames(core_only);
83   return GetLibCoreDexLocations(modules);
84 }
85 
86 }  // namespace testing
87 }  // namespace art
88