Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtemodel] Retrieve local pack version from pdsc (#253) #392

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions libs/rtemodel/src/RteKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> 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;
}
}
}
}
}
Expand Down
38 changes: 29 additions & 9 deletions libs/rtemodel/test/src/RteModelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand All @@ -94,6 +96,30 @@ class RteModelPrjTest :public ::testing::Test {
void compareFile(const string &newFile, const string &refFile,
const std::unordered_map<string, string> &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<string> 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<string>::iterator it = buffer.begin(); it != buffer.end(); it++) {
out << *it << endl;
}
return pdsc;
}

void GenerateHeadersTest(const string& project, const string& rteFolder) {

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions libs/rtemodel/test/src/RteModelTestConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
1 change: 1 addition & 0 deletions libs/rtemodel/test/src/RteModelTestConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down