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

[projmgr] csolution usage of local_repository.pidx packs #1430 #1436

Merged
merged 1 commit into from
Apr 12, 2024
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
37 changes: 14 additions & 23 deletions libs/rtefsutils/test/src/RteFsUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,39 +1176,30 @@ TEST_F(RteFsUtilsTest, FileCategoryFromExtension) {
}

TEST_F(RteFsUtilsTest, GetAbsPathFromLocalUrl) {
#ifdef _WIN32
// Absolute dummy path
const string& absoluteFilename = "C:/path/to/file.txt";

// Local host
const string& testUrlLocalHost = "file://localhost/" + absoluteFilename;
EXPECT_EQ(absoluteFilename, RteFsUtils::GetAbsPathFromLocalUrl(testUrlLocalHost));

// Empty host
const string& testUrlEmptyHost = "file:///" + absoluteFilename;
EXPECT_EQ(absoluteFilename, RteFsUtils::GetAbsPathFromLocalUrl(testUrlEmptyHost));

// Omitted host
const string& testUrlOmittedHost = "file:/" + absoluteFilename;
EXPECT_EQ(absoluteFilename, RteFsUtils::GetAbsPathFromLocalUrl(testUrlOmittedHost));

#else
// Absolute dummy path
const string& absoluteFilename = "/path/to/file.txt";
#ifdef _WIN32
const string absoluteFilename = "C:/path/to/file.txt";
#else
const string absoluteFilename = "/path/to/file.txt";
#endif
vector<string> files = {absoluteFilename, "relative/file", "./relative/file", "../relative/file"};
for(auto fileName : files) {
// file itself always passes: relative or absolute
EXPECT_EQ(fileName, RteFsUtils::GetAbsPathFromLocalUrl(fileName));
}

// Local host
const string& testUrlLocalHost = "file://localhost" + absoluteFilename;
//other support cases only absolute file names
const string testUrlLocalHost = "file://localhost/" + absoluteFilename;
EXPECT_EQ(absoluteFilename, RteFsUtils::GetAbsPathFromLocalUrl(testUrlLocalHost));

// Empty host
const string& testUrlEmptyHost = "file://" + absoluteFilename;
const string testUrlEmptyHost = "file:///" + absoluteFilename;
EXPECT_EQ(absoluteFilename, RteFsUtils::GetAbsPathFromLocalUrl(testUrlEmptyHost));

// Omitted host
const string& testUrlOmittedHost = "file:" + absoluteFilename;
const string testUrlOmittedHost = "file:/" + absoluteFilename;
EXPECT_EQ(absoluteFilename, RteFsUtils::GetAbsPathFromLocalUrl(testUrlOmittedHost));
#endif

}

// end of RteFsUtilsTest.cpp
68 changes: 44 additions & 24 deletions libs/rtemodel/include/RteKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ class RteKernel
*/
virtual CprjFile* GetActiveCprjFile() const;

/**
* @brief get installed packs
* @param pdscFiles list of installed packs
* @param bool latest get only latest versions (default true)
*/
bool GetInstalledPacks(std::list<std::string>& pdscFiles, bool latest = true);

/**
* @brief load and insert pack into global model
* @param packs list of loaded packages
Expand All @@ -225,40 +218,58 @@ class RteKernel
*/
bool LoadAndInsertPacks(std::list<RtePackage*>& packs, std::list<std::string>& pdscFiles);

/**
* @brief get installed and local pdsc files as list sorted by pack ID
* @param pdscFiles list of pdsc files to fill
* @param bool latest get only latest versions (default true)
* @return true if CMSIS_PACK_ROOT is set and accessible
*/
bool GetEffectivePdscFiles(std::list<std::string>& pdscFiles, bool latest = true) const;

/**
* @brief get installed and local pdsc files as map sorted by ID
* @param pdscMap map of pID to pdsc file to fill
* @param bool latest get only latest versions (default true)
* @return true if CMSIS_PACK_ROOT is set and accessible
*/
bool GetEffectivePdscFilesAsMap(std::map<std::string, std::string, RtePackageComparator>& pdscMap, bool latest = true) const;

/**
* @brief get list of installed pdsc files
* @param files collection to fill with absolute pdsc filenames;
* @param bool latest get only latest versions (default true)
* @param rtePath pack path
*/
static void GetInstalledPdscFiles(std::list<std::string>& files, const std::string& rtePath, bool latest = true);
void GetInstalledPdscFiles(std::map<std::string, std::string, RtePackageComparator>& pdscMap) const;

/**
* @brief getter for pdsc file determined by pack ID, pack path and pack attributes
* @param attributes pack attributes
* @param rtePath pack path
* @param packId pack ID
* @return pdsc file
* @return pair of pack ID to pdsc file
*/
static std::string GetInstalledPdscFile(const XmlItem& attributes, const std::string& rtePath, std::string& packId);
std::pair<std::string, std::string> GetInstalledPdscFile(const XmlItem& attributes) const;

/**
* @brief getter for pdsc file pointed by the local repository index and determined by pack attributes, pack path and pack ID.
* @param attributes pack attributes
* @param rtePath pack path
* @param packId pack ID
* @return pdsc file
* @return pair of pack ID to pdsc file
*/
std::string GetLocalPdscFile(const XmlItem& attributes, const std::string& rtePath, std::string& packId);
std::pair<std::string, std::string> GetLocalPdscFile(const XmlItem& attributes) const;

/**
* @brief getter for pdsc file pointed by the pack 'path' attribute
* @brief get local or installed pdsc file corresponding to supplied pack ID, pack path and pack attributes
* @param attributes pack attributes
* @param cprjPath cprj path
* @param packId pack ID
* @return pdsc file
* @return pair of pack ID to pdsc file
*/
std::pair<std::string, std::string> GetEffectivePdscFile(const XmlItem& attributes) const;

/**
* @brief get pdsc file pointed by the pack 'path' attribute in a project
* @param attributes pack attributes
* @param prjPath path from project
* @return pair of pack ID to pdsc file
*/
std::string GetPdscFileFromPath(const XmlItem& attributes, const std::string& cprjPath, std::string& packId);
std::pair<std::string, std::string> GetPdscFileFromPath(const XmlItem& attributes, const std::string& cprjPath) const;

/**
* @brief create a smart pointer holding an XMLTree pointer to parse XML or YAML files
Expand Down Expand Up @@ -325,9 +336,18 @@ class RteKernel
void SetToolInfo(const XmlItem& attr) { m_toolInfo = attr; }

protected:
bool GetUrlFromIndex(const std::string& indexFile, const std::string& name, const std::string& vendor, const std::string& version, std::string& indexedUrl, std::string& indexedVersion) const;
bool GetLocalPacksUrls(const std::string& rtePath, std::list<std::string>& urls) const;
XMLTreeElement* ParseLocalRepositoryIdx(const std::string& rtePath) const;
/**
* @brief get local pdsc files, optionally filtered
* @param attr pack attributes to filter
* @param pdscMap map packId to pdsc path to fill
* @return true if an entry is found
*/
bool GetLocalPdscFiles(const XmlItem& attr, std::map<std::string, std::string, RtePackageComparator>& pdscMap) const;
/**
* @brief parses $CMSIS_PACK_ROOT/.Local/loacl_repository.pidx file
* @return pointer to "index" element if successful, nullptr otherwise
*/
XMLTreeElement* ParseLocalRepositoryIdx() const;

/**
* @brief create an XMLTree object to parse XML files
Expand Down
Loading