1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "runtime/include/file_manager.h"
17 #include "runtime/include/runtime.h"
18 #include "libpandabase/os/filesystem.h"
19
20 namespace panda {
21
LoadAbcFile(const PandaString & location,panda_file::File::OpenMode open_mode)22 bool FileManager::LoadAbcFile(const PandaString &location, panda_file::File::OpenMode open_mode)
23 {
24 auto pf = panda_file::OpenPandaFile(location, "", open_mode);
25 if (pf == nullptr) {
26 LOG(ERROR, PANDAFILE) << "Load panda file failed: " << location;
27 return false;
28 }
29 auto runtime = Runtime::GetCurrent();
30 runtime->GetClassLinker()->AddPandaFile(std::move(pf));
31 if (Runtime::GetOptions().IsEnableAn()) {
32 auto an_location = FileManager::ResolveAnFilePath(location);
33 auto res = FileManager::LoadAnFile(an_location);
34 if (res && res.Value()) {
35 LOG(INFO, PANDAFILE) << "Found .an file for '" << location << "': '" << an_location << "'";
36 } else if (!res) {
37 LOG(INFO, PANDAFILE) << "Failed to load AOT file: '" << an_location << "': " << res.Error();
38 } else {
39 LOG(INFO, PANDAFILE) << "Failed to load '" << an_location << "' with unknown reason";
40 }
41 }
42
43 return true;
44 }
45
LoadAnFile(const PandaString & an_location)46 Expected<bool, std::string> FileManager::LoadAnFile(const PandaString &an_location)
47 {
48 return Unexpected(std::string("Cannot load file: ") + std::string(an_location) + ": AOT files unsupported");
49 }
50
ResolveAnFilePath(const PandaString & abc_path)51 PandaString FileManager::ResolveAnFilePath([[maybe_unused]] const PandaString &abc_path)
52 {
53 return "";
54 }
55
56 } // namespace panda
57