1 /*
2 * Copyright (c) 2023 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 #include "StageContext.h"
16 #include <sstream>
17 #include <fstream>
18 #include <cctype>
19 #include <algorithm>
20 #include "JsonReader.h"
21 #include "FileSystem.h"
22 #include "TraceTool.h"
23 #include "PreviewerEngineLog.h"
24 #include "CommandParser.h"
25 #include "zlib.h"
26 #include "contrib/minizip/unzip.h"
27 using namespace std;
28
29 namespace OHOS::Ide {
GetInstance()30 StageContext& StageContext::GetInstance()
31 {
32 static StageContext instance;
33 return instance;
34 }
35
ReadFileContents(const std::string & filePath) const36 const std::optional<std::vector<uint8_t>> StageContext::ReadFileContents(const std::string& filePath) const
37 {
38 if (!FileSystem::IsFileExists(filePath)) {
39 ELOG("file %s is not exist.", filePath.c_str());
40 return std::nullopt;
41 }
42 std::ifstream file(filePath, std::ios::binary | std::ios::ate);
43 if (!file) {
44 ELOG("open file %s failed.", filePath.c_str());
45 return std::nullopt;
46 }
47 std::streamsize fileSize = file.tellg();
48 file.seekg(0, std::ios::beg);
49 std::vector<uint8_t> data(fileSize);
50 if (file.read(reinterpret_cast<char*>(data.data()), fileSize)) {
51 return data;
52 } else {
53 ELOG("read file %s failed.", filePath.c_str());
54 return std::nullopt;
55 }
56 }
57
SetLoaderJsonPath(const std::string & assetPath)58 void StageContext::SetLoaderJsonPath(const std::string& assetPath)
59 {
60 loaderJsonPath = FileSystem::NormalizePath(assetPath);
61 if (loaderJsonPath.empty() || !FileSystem::IsFileExists(loaderJsonPath)) {
62 ELOG("the loaderJsonPath %s is not exist.", loaderJsonPath.c_str());
63 return;
64 }
65 ILOG("set loaderJsonPath: %s successed.", loaderJsonPath.c_str());
66 }
67
SetHosSdkPath(const std::string & hosSdkPathValue)68 void StageContext::SetHosSdkPath(const std::string& hosSdkPathValue)
69 {
70 this->hosSdkPath = hosSdkPathValue;
71 }
72
GetModulePathMapFromLoaderJson()73 void StageContext::GetModulePathMapFromLoaderJson()
74 {
75 if (!FileSystem::IsFileExists(loaderJsonPath)) {
76 ELOG("the loaderJsonPath is not exist.");
77 return;
78 }
79 string jsonStr = JsonReader::ReadFile(loaderJsonPath);
80 Json2::Value rootJson = JsonReader::ParseJsonData2(jsonStr);
81 if (rootJson.IsNull() || !rootJson.IsValid()) {
82 ELOG("Get loader.json content failed.");
83 return;
84 }
85 if (!rootJson.IsMember("modulePathMap") || !rootJson.IsMember("harNameOhmMap") ||
86 !rootJson.IsMember("projectRootPath")) {
87 ELOG("Don't find some necessary node in loader.json.");
88 return;
89 }
90 Json2::Value jsonObj = rootJson["modulePathMap"];
91 for (const auto& key : jsonObj.GetMemberNames()) {
92 modulePathMap[key] = jsonObj[key].AsString();
93 }
94 Json2::Value jsonObjOhm = rootJson["harNameOhmMap"];
95 if (rootJson.IsMember("hspNameOhmMap")) {
96 if (!rootJson["hspNameOhmMap"].IsNull() && rootJson["hspNameOhmMap"].IsValid()) {
97 ILOG("hspNameOhmMap is valid");
98 jsonObjOhm = rootJson["hspNameOhmMap"];
99 }
100 }
101 for (const auto& key : jsonObjOhm.GetMemberNames()) {
102 hspNameOhmMap[key] = jsonObjOhm[key].AsString();
103 }
104 projectRootPath = rootJson["projectRootPath"].AsString();
105 if (rootJson.IsMember("buildConfigPath")) {
106 buildConfigPath = rootJson["buildConfigPath"].AsString();
107 }
108 }
109
GetHspAceModuleBuild(const std::string & hspConfigPath)110 std::string StageContext::GetHspAceModuleBuild(const std::string& hspConfigPath)
111 {
112 if (!FileSystem::IsFileExists(hspConfigPath)) {
113 ELOG("hspConfigPath: %s is not exist.", hspConfigPath.c_str());
114 return "";
115 }
116 string jsonStr = JsonReader::ReadFile(hspConfigPath);
117 Json2::Value rootJson = JsonReader::ParseJsonData2(jsonStr);
118 if (rootJson.IsNull() || !rootJson.IsValid()) {
119 ELOG("Get hsp buildConfig.json content failed.");
120 return "";
121 }
122 if (!rootJson.IsMember("aceModuleBuild")) {
123 ELOG("Don't find aceModuleBuild node in hsp buildConfig.json.");
124 return "";
125 }
126 return rootJson["aceModuleBuild"].AsString();
127 }
128
ReleaseHspBuffers()129 void StageContext::ReleaseHspBuffers()
130 {
131 for (std::vector<uint8_t>* ptr : hspBufferPtrsVec) {
132 delete ptr;
133 }
134 hspBufferPtrsVec.clear();
135 ILOG("ReleaseHspBuffers finished.");
136 }
137
GetModulePathMap() const138 std::map<std::string, std::string> StageContext::GetModulePathMap() const
139 {
140 return modulePathMap;
141 }
142
GetModuleBuffer(const std::string & inputPath)143 std::vector<uint8_t>* StageContext::GetModuleBuffer(const std::string& inputPath)
144 {
145 ILOG("inputPath is:%s.", inputPath.c_str());
146 TraceTool::GetInstance().HandleTrace("HSP is loaded");
147 std::string spliter = "/";
148 size_t pos = inputPath.rfind(spliter);
149 if (pos == std::string::npos) {
150 ELOG("inputPath: %s format error.", inputPath.c_str());
151 return nullptr;
152 }
153 std::string bundleName = inputPath.substr(0, pos);
154 ILOG("bundleName is:%s.", bundleName.c_str());
155 if (bundleName.empty()) {
156 ELOG("bundleName is empty.");
157 return nullptr;
158 }
159 std::string moduleName = inputPath.substr(pos + spliter.size());
160 ILOG("moduleName is:%s.", moduleName.c_str());
161 if (modulePathMap.empty()) {
162 ELOG("modulePathMap is empty.");
163 return nullptr;
164 }
165 if (bundleName == localBundleName) { // local hsp
166 if (modulePathMap.count(moduleName) > 0) { // exist local hsp
167 return GetLocalModuleBuffer(moduleName);
168 } else { // local hsp not exist, load cloud hsp
169 ILOG("cloud hsp bundleName is same as the local project.");
170 return GetCloudModuleBuffer(moduleName);
171 }
172 } else {
173 // 先找三方hsp,再找系统hsp
174 std::vector<uint8_t>* buf = GetCloudModuleBuffer(moduleName);
175 if (buf) { // cloud hsp
176 return buf;
177 } else { // system hsp
178 std::vector<uint8_t>* buf = GetSystemModuleBuffer(inputPath, moduleName);
179 ILOG("system hsp buf size is %d", buf->size());
180 return buf;
181 }
182 }
183 }
184
GetLocalModuleBuffer(const std::string & moduleName)185 std::vector<uint8_t>* StageContext::GetLocalModuleBuffer(const std::string& moduleName)
186 {
187 std::string modulePath = StageContext::GetInstance().modulePathMap[moduleName];
188 if (modulePath.empty()) {
189 ELOG("modulePath is empty.");
190 return nullptr;
191 }
192 ILOG("get modulePath: %s successed.", modulePath.c_str());
193 if (!FileSystem::IsDirectoryExists(modulePath)) {
194 ELOG("don't find moduleName: %s in modulePathMap from loader.json.", moduleName.c_str());
195 return nullptr;
196 }
197 if (ContainsRelativePath(modulePath)) {
198 ELOG("modulePath format error: %s.", modulePath.c_str());
199 return nullptr;
200 }
201 std::string separator = FileSystem::GetSeparator();
202 // 读取hsp的.preview/config/buildConfig.json获取aceModuleBuild值就是hsp的modules.abc所在文件夹
203 std::string hspConfigPath = modulePath + separator + ".preview" + separator + "config" +
204 separator + "buildConfig.json";
205 if (!buildConfigPath.empty()) {
206 ILOG("buildConfigPath is not empty.");
207 hspConfigPath = modulePath + separator + buildConfigPath;
208 }
209 std::string abcDir = GetHspAceModuleBuild(hspConfigPath);
210 if (!FileSystem::IsDirectoryExists(abcDir)) {
211 ELOG("the abcDir:%s is not exist.", abcDir.c_str());
212 return nullptr;
213 }
214 std::string abcPath = abcDir + separator + "modules.abc";
215 if (!FileSystem::IsFileExists(abcPath)) {
216 ELOG("the abcPath:%s is not exist.", abcPath.c_str());
217 return nullptr;
218 }
219 ILOG("get modules.abc path: %s successed.", abcPath.c_str());
220 std::optional<std::vector<uint8_t>> opt = ReadFileContents(abcPath);
221 if (!opt.has_value()) {
222 ELOG("read modules.abc buffer failed.");
223 return nullptr;
224 }
225 std::vector<uint8_t> *buf = new std::vector<uint8_t>(opt.value());
226 hspBufferPtrsVec.push_back(buf);
227 return buf;
228 }
229
GetCloudHspVersion(const std::string & hspPath,const std::string & actualName)230 std::string StageContext::GetCloudHspVersion(const std::string& hspPath, const std::string& actualName)
231 {
232 string flag = "@";
233 std::string spliter = actualName + flag;
234 // 以partName字符串拆分出版本号
235 size_t pos = hspPath.rfind(spliter);
236 if (pos == std::string::npos) {
237 ELOG("hspPath: %s format error. no spliter:%s exist", hspPath.c_str(), spliter.c_str());
238 return "";
239 }
240 int idx = pos + spliter.size();
241 return hspPath.substr(idx);
242 }
243
SplitHspVersion(const std::string & version)244 std::vector<int> StageContext::SplitHspVersion(const std::string& version)
245 {
246 std::vector<int> segments;
247 std::istringstream iss(version);
248 std::string segment;
249 while (getline(iss, segment, '.')) {
250 segments.push_back(std::stoi(segment));
251 }
252 return segments;
253 }
254
CompareHspVersion(const std::string & version1,const std::string & version2)255 int StageContext::CompareHspVersion(const std::string& version1, const std::string& version2)
256 {
257 ILOG("module hsp version:%s, project hsp version:%s", version1.c_str(), version2.c_str());
258 std::vector<int> ver1 = SplitHspVersion(version1);
259 std::vector<int> ver2 = SplitHspVersion(version2);
260 // 将两个版本号的分段个数补齐
261 while (ver1.size() < ver2.size()) {
262 ver1.push_back(0);
263 }
264 while (ver2.size() < ver1.size()) {
265 ver2.push_back(0);
266 }
267 // 逐段比较版本号
268 for (size_t i = 0; i < ver1.size(); ++i) {
269 if (ver1[i] < ver2[i]) {
270 return -1;
271 } else if (ver1[i] > ver2[i]) {
272 return 1;
273 }
274 }
275 return 0;
276 }
277
GetActualCloudHspDir(const std::string & actualName)278 std::string StageContext::GetActualCloudHspDir(const std::string& actualName)
279 {
280 string moduleHspPath = GetCloudModuleHspPath(actualName);
281 string projectHspPath = GetCloudProjectHspPath(actualName);
282 ILOG("moduleHspPath:%s, projectHspPath:%s", moduleHspPath.c_str(), projectHspPath.c_str());
283 if (moduleHspPath.empty() || !FileSystem::IsDirectoryExists(moduleHspPath)) {
284 return projectHspPath; // 模块级不存在,加载项目级
285 }
286 if (projectHspPath.empty() || !FileSystem::IsDirectoryExists(projectHspPath)) {
287 return moduleHspPath; // 模块级存在,项目级不存在,加载模块级
288 }
289 // 模块级和项目级都存在,加载版本号高的
290 string moduleHspVersion = GetCloudHspVersion(moduleHspPath, actualName);
291 string projectHspVersion = GetCloudHspVersion(projectHspPath, actualName);
292 if (moduleHspVersion.empty()) {
293 return projectHspPath; // 模块级版本号不存在,加载项目级
294 }
295 if (projectHspVersion.empty()) {
296 return moduleHspPath; // 模块级版本号存在,项目级版本号不存在,加载模块级
297 }
298 int ret = CompareHspVersion(moduleHspVersion, projectHspVersion);
299 ILOG("CompareHspVersion result is:%d", ret);
300 return ret >= 0 ? moduleHspPath : projectHspPath; // 优先加载版本号高的,版本号相同则优先加载模块级的
301 }
302
GetCloudProjectHspPath(const std::string & actualName)303 std::string StageContext::GetCloudProjectHspPath(const std::string& actualName)
304 {
305 ILOG("get projectRootPath:%s", projectRootPath.c_str());
306 std::string hspDir = projectRootPath + "/oh_modules/.hsp";
307 if (!FileSystem::IsDirectoryExists(hspDir)) {
308 ELOG("hspDir: %s in project is not exist.", hspDir.c_str());
309 return "";
310 }
311 return GetCloudHspPath(hspDir, actualName);
312 }
313
GetCloudModuleHspPath(const std::string & actualName)314 std::string StageContext::GetCloudModuleHspPath(const std::string& actualName)
315 {
316 int upwardLevel = 5;
317 int pos = GetUpwardDirIndex(loaderJsonPath, upwardLevel);
318 if (pos < 0) {
319 ILOG("GetUpwardDirIndex:%d failed.", pos);
320 return "";
321 }
322 std::string moduleRootPath = loaderJsonPath.substr(0, pos);
323 ILOG("get moduleRootPath:%s", moduleRootPath.c_str());
324 std::string hspDir = moduleRootPath + "/oh_modules/.hsp";
325 if (!FileSystem::IsDirectoryExists(hspDir)) {
326 ELOG("hspDir: %s in module is not exist.", hspDir.c_str());
327 return "";
328 }
329 return GetCloudHspPath(hspDir, actualName);
330 }
331
GetCloudModuleBuffer(const std::string & moduleName)332 std::vector<uint8_t>* StageContext::GetCloudModuleBuffer(const std::string& moduleName)
333 {
334 std::string actualName;
335 int ret = GetHspActualName(moduleName, actualName);
336 if (ret > 1) {
337 WLOG("have more same module name hsp in the project, load the first as default.");
338 }
339 if (actualName.empty()) {
340 ELOG("get hsp actual name failed.");
341 return nullptr;
342 }
343 // 1.以entry(指代模块根目录或项目根目录)拆分,拼接oh_modules/.hsp,在这个拼接目录下查找以actualName@开头的文件夹
344 // 2.获取拼接目录下的actualName.hsp文件
345 // 3.使用zlib获取hsp压缩包下的ets/modules.abc内容
346 std::string hspPath = GetActualCloudHspDir(actualName);
347 ILOG("get hspPath:%s actualName:%s", hspPath.c_str(), actualName.c_str());
348 if (!FileSystem::IsDirectoryExists(hspPath)) {
349 ELOG("hspPath: %s is not exist.", hspPath.c_str());
350 return nullptr;
351 }
352 std::string moduleHspFile = hspPath + "/" + actualName + ".hsp";
353 ILOG("get moduleHspFile:%s.", moduleHspFile.c_str());
354 if (!FileSystem::IsFileExists(moduleHspFile)) {
355 ELOG("the moduleHspFile:%s is not exist.", moduleHspFile.c_str());
356 return nullptr;
357 }
358 // unzip and get ets/moudles.abc buffer
359 std::vector<uint8_t>* buf = GetModuleBufferFromHsp(moduleHspFile, "ets/modules.abc");
360 if (!buf) {
361 ELOG("read modules.abc buffer failed.");
362 }
363 return buf;
364 }
365
GetCloudHspPath(const std::string & hspDir,const std::string & moduleName)366 std::string StageContext::GetCloudHspPath(const std::string& hspDir, const std::string& moduleName)
367 {
368 string flag = "@";
369 std::string partName = moduleName + flag;
370 return FileSystem::FindSubfolderByName(hspDir, partName);
371 }
372
GetModuleBufferFromHsp(const std::string & hspFilePath,const std::string & fileName)373 std::vector<uint8_t>* StageContext::GetModuleBufferFromHsp(const std::string& hspFilePath,
374 const std::string& fileName)
375 {
376 unzFile zipfile = unzOpen2(hspFilePath.c_str(), nullptr);
377 if (zipfile == NULL) {
378 printf("Failed to open the zip file: %s\n", hspFilePath.c_str());
379 return nullptr;
380 }
381
382 if (unzLocateFile(zipfile, fileName.c_str(), 1) != UNZ_OK) {
383 printf("Failed to locate the file: %s\n", fileName.c_str());
384 unzClose(zipfile);
385 return nullptr;
386 }
387
388 unz_file_info file_info;
389 if (unzGetCurrentFileInfo(zipfile, &file_info, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK) {
390 printf("Failed to get the file info: %s\n", fileName.c_str());
391 unzClose(zipfile);
392 return nullptr;
393 }
394
395 if (unzOpenCurrentFile(zipfile) != UNZ_OK) {
396 printf("Failed to open the file: %s\n", fileName.c_str());
397 unzClose(zipfile);
398 return nullptr;
399 }
400
401 char buffer[1024];
402 int bytesRead;
403 std::vector<uint8_t>* fileContent = new std::vector<uint8_t>();
404 while ((bytesRead = unzReadCurrentFile(zipfile, buffer, sizeof(buffer))) > 0) {
405 fileContent->insert(fileContent->end(), buffer, buffer + bytesRead);
406 }
407 hspBufferPtrsVec.push_back(fileContent);
408 unzCloseCurrentFile(zipfile);
409 unzClose(zipfile);
410
411 printf("File extracted and content saved: %s\n", fileName.c_str());
412 return fileContent;
413 }
414
ContainsRelativePath(const std::string & path) const415 bool StageContext::ContainsRelativePath(const std::string& path) const
416 {
417 std::string flg1 = ".." + FileSystem::GetSeparator();
418 std::string flg2 = "." + FileSystem::GetSeparator();
419 return (path.find(flg1) != std::string::npos || path.find(flg2) != std::string::npos);
420 }
421
ParseMockJsonFile(const std::string & mockJsonFilePath)422 std::map<string, string> StageContext::ParseMockJsonFile(const std::string& mockJsonFilePath)
423 {
424 std::map<string, string> mapInfo;
425 if (!FileSystem::IsFileExists(mockJsonFilePath)) {
426 ELOG("the mockJsonFilePath:%s is not exist.", mockJsonFilePath.c_str());
427 return mapInfo;
428 }
429 std::string jsonStr = JsonReader::ReadFile(mockJsonFilePath);
430 Json2::Value rootJson = JsonReader::ParseJsonData2(jsonStr);
431 if (rootJson.IsNull() || !rootJson.IsValid()) {
432 ELOG("get mock-config.json content failed.");
433 return mapInfo;
434 }
435 for (const auto& key : rootJson.GetMemberNames()) {
436 if (!rootJson[key].IsNull() && rootJson[key].IsMember("source") && rootJson[key]["source"].IsString()) {
437 mapInfo[key] = rootJson[key]["source"].AsString();
438 }
439 }
440 return mapInfo;
441 }
442
GetUpwardDirIndex(const std::string & path,const int upwardLevel) const443 int StageContext::GetUpwardDirIndex(const std::string& path, const int upwardLevel) const
444 {
445 std::string::size_type pos = path.find_last_of(FileSystem::GetSeparator().c_str());
446 std::string::size_type count = 0;
447 while (count < upwardLevel) {
448 if (pos == std::string::npos) {
449 ELOG("GetUpwardDir:%s failed.");
450 int errCode = -1;
451 return errCode;
452 }
453 pos = path.find_last_of(FileSystem::GetSeparator().c_str(), pos - 1);
454 ++count;
455 }
456 ILOG("GetUpwardDir path:%s pos:%d", path.c_str(), pos);
457 return pos;
458 }
459
ReplaceLastStr(const std::string & str,const std::string & find,const std::string & replace)460 std::string StageContext::ReplaceLastStr(const std::string& str, const std::string& find, const std::string& replace)
461 {
462 std::string ret = str;
463 size_t pos = ret.rfind(find);
464 if (pos != std::string::npos) {
465 ret.replace(pos, find.size(), replace);
466 }
467 return ret;
468 }
469
GetHspActualName(const std::string & input,std::string & ret)470 int StageContext::GetHspActualName(const std::string& input, std::string& ret)
471 {
472 int num = 0;
473 std::string flag = "";
474 std::string bundleFlag = "/" + input + "/";
475 std::string normalizedFlag = "N&" + input + "&";
476 for (const auto& pair : hspNameOhmMap) {
477 if (pair.second.find("@normalized") == 0) {
478 flag = normalizedFlag;
479 } else {
480 flag = bundleFlag;
481 }
482 if (pair.second.find(flag) != std::string::npos) {
483 std::string actualName = pair.first;
484 if (actualName.find('/') != std::string::npos) { // 以组织名开头的包
485 std::replace(actualName.begin(), actualName.end(), '/', '+');
486 }
487 if (num == 0) {
488 ret = actualName;
489 }
490 num++;
491 WLOG("find hsp actual name:%s", pair.first.c_str());
492 }
493 }
494 return num;
495 }
496
GetSystemModuleBuffer(const std::string & inputPath,const std::string & moduleName)497 std::vector<uint8_t>* StageContext::GetSystemModuleBuffer(const std::string& inputPath,
498 const std::string& moduleName)
499 {
500 string head = "com.huawei";
501 string tail = moduleName;
502 size_t pos1 = inputPath.find(head) + head.size();
503 size_t pos2 = inputPath.find(tail);
504 std::string relativePath = inputPath.substr(pos1, pos2 - pos1);
505 size_t found = relativePath.find(".");
506 int len = 1;
507 while (found != std::string::npos) {
508 relativePath.replace(found, len, "/");
509 found = relativePath.find(".", found + len);
510 }
511 std::string moduleHspFile = hosSdkPath + "/systemHsp" + relativePath + moduleName + ".hsp";
512 ILOG("get system moduleHspFile:%s.", moduleHspFile.c_str());
513 if (!FileSystem::IsFileExists(moduleHspFile)) {
514 ELOG("the system moduleHspFile:%s is not exist.", moduleHspFile.c_str());
515 return nullptr;
516 }
517 // unzip and get ets/moudles.abc buffer
518 std::vector<uint8_t>* buf = GetModuleBufferFromHsp(moduleHspFile, "ets/modules.abc");
519 if (!buf) {
520 ELOG("read modules.abc buffer failed.");
521 }
522 return buf;
523 }
524
SetPkgContextInfo(std::map<std::string,std::string> & pkgContextInfoJsonStringMap,std::map<std::string,std::string> & packageNameList)525 void StageContext::SetPkgContextInfo(std::map<std::string, std::string>& pkgContextInfoJsonStringMap,
526 std::map<std::string, std::string>& packageNameList)
527 {
528 const string path = CommandParser::GetInstance().GetAppResourcePath() +
529 FileSystem::GetSeparator() + "module.json";
530 string moduleJsonStr = JsonReader::ReadFile(path);
531 if (moduleJsonStr.empty()) {
532 ELOG("Get module.json content empty.");
533 }
534 Json2::Value rootJson1 = JsonReader::ParseJsonData2(moduleJsonStr);
535 if (rootJson1.IsNull() || !rootJson1.IsValid() || !rootJson1.IsMember("module")) {
536 ELOG("Get module.json content failed.");
537 return;
538 }
539 if (!rootJson1["module"].IsMember("name") || !rootJson1["module"]["name"].IsString()) {
540 return;
541 }
542 string moduleName = rootJson1["module"]["name"].AsString();
543 if (rootJson1["module"].IsMember("packageName") && rootJson1["module"]["packageName"].IsString()) {
544 string pkgName = rootJson1["module"]["packageName"].AsString();
545 packageNameList = {{moduleName, pkgName}};
546 }
547 std::string jsonPath = CommandParser::GetInstance().GetLoaderJsonPath();
548 std::string flag = "loader.json";
549 int idx = jsonPath.find_last_of(flag);
550 std::string dirPath = jsonPath.substr(0, idx - flag.size() + 1); // 1 is for \ or /
551 std::string ctxPath = dirPath + "pkgContextInfo.json";
552 string ctxInfoJsonStr = JsonReader::ReadFile(ctxPath);
553 if (ctxInfoJsonStr.empty()) {
554 ELOG("Get pkgContextInfo.json content empty.");
555 return;
556 }
557 pkgContextInfoJsonStringMap = {{moduleName, ctxInfoJsonStr}};
558 }
559 }