diff --git a/libs/rtemodel/src/RteKernel.cpp b/libs/rtemodel/src/RteKernel.cpp index b853725ea..6543ce2cb 100644 --- a/libs/rtemodel/src/RteKernel.cpp +++ b/libs/rtemodel/src/RteKernel.cpp @@ -326,8 +326,7 @@ string RteKernel::GetLocalPdscFile(const RteAttributes& attributes, const string string url, version; if (GetUrlFromIndex(rtePath, name, vendor, versionRange, url, version)) { packId = vendor + '.' + name + '.' + version; - url = RteFsUtils::GetAbsPathFromLocalUrl(url); - return url + vendor + '.' + name + ".pdsc"; + return url; } return RteUtils::EMPTY_STRING; @@ -368,9 +367,17 @@ bool RteKernel::GetUrlFromIndex(const string& rtePath, const string& name, const // Populate map with items matching name, vendor and version range for (const auto& item : indexList) { if ((name == item->GetAttribute("name")) && (vendor == item->GetAttribute("vendor"))) { - const string& version = item->GetAttribute("version"); - if (versionRange.empty() || VersionCmp::RangeCompare(version, versionRange) == 0) { - pdscMap[version] = item->GetAttribute("url"); + // Load the local pack to get its version. The 'version' attribute in the local repository index is ignored. + list localPdscFiles; + RteFsUtils::GetPackageDescriptionFiles(localPdscFiles, RteFsUtils::GetAbsPathFromLocalUrl(item->GetAttribute("url")), 1); + for (const auto& localPdscFile : localPdscFiles) { + RtePackage* pack = LoadPack(localPdscFile); + if (pack) { + const string& version = pack->GetVersionString(); + if (versionRange.empty() || VersionCmp::RangeCompare(version, versionRange) == 0) { + pdscMap[version] = localPdscFile; + } + } } } } diff --git a/libs/rtemodel/test/src/RteModelTest.cpp b/libs/rtemodel/test/src/RteModelTest.cpp index e814e14bb..d0aff0933 100644 --- a/libs/rtemodel/test/src/RteModelTest.cpp +++ b/libs/rtemodel/test/src/RteModelTest.cpp @@ -61,6 +61,7 @@ TEST(RteModelTest, LoadPacks) { // define project and header file names with relative paths const string prjsDir = "RteModelTestProjects"; +const string localRepoDir = "RteModelLocalRepo"; const string RteTestM3 = "/RteTestM3"; const string RteTestM3_cprj = prjsDir + RteTestM3 + "/RteTestM3.cprj"; const string RteTestM3_ConfigFolder_cprj = prjsDir + RteTestM3 + "/RteTestM3_ConfigFolder.cprj"; @@ -84,6 +85,7 @@ class RteModelPrjTest :public ::testing::Test { { RteFsUtils::DeleteTree(prjsDir); RteFsUtils::CopyTree(RteModelTestConfig::PROJECTS_DIR, prjsDir); + RteFsUtils::CopyTree(RteModelTestConfig::LOCAL_REPO_DIR, localRepoDir); } void TearDown() override @@ -94,6 +96,30 @@ class RteModelPrjTest :public ::testing::Test { void compareFile(const string &newFile, const string &refFile, const std::unordered_map &expectedChangedFlags, const string &toolchain) const; + string UpdateLocalIndex() { + const string index = localRepoDir + "/.Local/local_repository.pidx"; + const string pdsc = RteModelTestConfig::CMSIS_PACK_ROOT + "/ARM/RteTest/0.1.0/ARM.RteTest.pdsc"; + const string original = "file://localhost/packs/LocalVendor/LocalPack/"; + const string replace = "file://localhost/" + RteModelTestConfig::CMSIS_PACK_ROOT + "/ARM/RteTest/0.1.0/"; + string line; + vector buffer; + + ifstream in(index); + while (getline(in, line)) { + size_t pos = line.find(original); + if (pos != string::npos) { + line.replace(pos, original.length(), replace); + } + buffer.push_back(line); + } + in.close(); + + ofstream out(index); + for (vector::iterator it = buffer.begin(); it != buffer.end(); it++) { + out << *it << endl; + } + return pdsc; + } void GenerateHeadersTest(const string& project, const string& rteFolder) { @@ -278,27 +304,21 @@ TEST_F(RteModelPrjTest, LoadCprjConfigVer) { TEST_F(RteModelPrjTest, GetLocalPdscFile) { RteKernelSlim rteKernel; - const string& packRoot = RteModelTestConfig::CMSIS_PACK_ROOT + "/../local"; + const string& expectedPdsc = UpdateLocalIndex(); RteAttributes attributes; attributes.AddAttribute("name", "LocalPack"); attributes.AddAttribute("vendor", "LocalVendor"); attributes.AddAttribute("version", "0.1.0"); string packId; - string pdsc = rteKernel.GetLocalPdscFile(attributes, packRoot, packId); + string pdsc = rteKernel.GetLocalPdscFile(attributes, localRepoDir, packId); // check returned packId EXPECT_EQ(packId, "LocalVendor.LocalPack.0.1.0"); // check returned pdsc error_code ec; -#ifdef _WIN32 - const string&& expectedPdsc = "packs/LocalVendor/LocalPack/LocalVendor.LocalPack.pdsc"; - EXPECT_EQ(pdsc, expectedPdsc); -#else - const string&& expectedPdsc = "/packs/LocalVendor/LocalPack/LocalVendor.LocalPack.pdsc"; - EXPECT_EQ(pdsc, expectedPdsc); -#endif + EXPECT_TRUE(fs::equivalent(pdsc, expectedPdsc, ec)); } TEST_F(RteModelPrjTest, GenerateHeadersTestDefault) diff --git a/libs/rtemodel/test/src/RteModelTestConfig.cpp b/libs/rtemodel/test/src/RteModelTestConfig.cpp index 088e204c7..3491872e7 100644 --- a/libs/rtemodel/test/src/RteModelTestConfig.cpp +++ b/libs/rtemodel/test/src/RteModelTestConfig.cpp @@ -6,6 +6,7 @@ #include "RteModelTestConfig.h" const std::string RteModelTestConfig::CMSIS_PACK_ROOT = std::string(GLOBAL_TEST_DIR) + std::string("/packs"); +const std::string RteModelTestConfig::LOCAL_REPO_DIR = std::string(GLOBAL_TEST_DIR) + std::string("/local"); const std::string RteModelTestConfig::PROJECTS_DIR = std::string(GLOBAL_TEST_DIR) + std::string("/projects"); const std::string RteModelTestConfig::M3_CPRJ = PROJECTS_DIR + std::string("/RteTestM3/RteTestM3.cprj"); diff --git a/libs/rtemodel/test/src/RteModelTestConfig.h b/libs/rtemodel/test/src/RteModelTestConfig.h index 94e79e332..852f74201 100644 --- a/libs/rtemodel/test/src/RteModelTestConfig.h +++ b/libs/rtemodel/test/src/RteModelTestConfig.h @@ -23,6 +23,7 @@ class RteModelTestConfig public: static const std::string CMSIS_PACK_ROOT; + static const std::string LOCAL_REPO_DIR; static const std::string PROJECTS_DIR; static const std::string M3_CPRJ; };