1 /*
2  * Copyright (C) 2021 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 ART_ODREFRESH_ODR_ARTIFACTS_H_
18 #define ART_ODREFRESH_ODR_ARTIFACTS_H_
19 
20 #include <iosfwd>
21 #include <string>
22 
23 #include <base/file_utils.h>
24 
25 namespace art {
26 namespace odrefresh {
27 
28 // A grouping of odrefresh generated artifacts.
29 class OdrArtifacts {
30  public:
ForBootImageExtension(const std::string & image_path)31   static OdrArtifacts ForBootImageExtension(const std::string& image_path) {
32     return OdrArtifacts(image_path, "oat");
33   }
34 
ForSystemServer(const std::string & image_path)35   static OdrArtifacts ForSystemServer(const std::string& image_path) {
36     return OdrArtifacts(image_path, "odex");
37   }
38 
ImagePath()39   const std::string& ImagePath() const { return image_path_; }
OatPath()40   const std::string& OatPath() const { return oat_path_; }
VdexPath()41   const std::string& VdexPath() const { return vdex_path_; }
42 
43  private:
OdrArtifacts(const std::string & image_path,const char * aot_extension)44   OdrArtifacts(const std::string& image_path, const char* aot_extension)
45       : image_path_{image_path},
46         oat_path_{ReplaceFileExtension(image_path, aot_extension)},
47         vdex_path_{ReplaceFileExtension(image_path, "vdex")} {}
48 
49   OdrArtifacts() = delete;
50   OdrArtifacts(const OdrArtifacts&) = delete;
51   OdrArtifacts& operator=(const OdrArtifacts&) = delete;
52 
53   const std::string image_path_;
54   const std::string oat_path_;
55   const std::string vdex_path_;
56 };
57 
58 }  // namespace odrefresh
59 }  // namespace art
60 
61 #endif  // ART_ODREFRESH_ODR_ARTIFACTS_H_
62