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

Add License Information to cbuild.yml files (BOM for projects) #1046 (#666) #1080

Merged
merged 1 commit into from
Aug 2, 2023
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
6 changes: 3 additions & 3 deletions libs/rtemodel/include/RteItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ class RteItem : public XmlTreeItem<RteItem>
virtual const std::string& GetID() const;

/**
* @brief get unique component ID: "Vendor::Class&Bundle:Group:Sub&[email protected](condition)[pack]"
* @brief get unique component ID: "Vendor::Class&Bundle:Group:Sub&Variant\@1.2.3(condition)[pack]"
* @return component unique ID
*/
virtual std::string GetComponentUniqueID() const;

/**
* @brief get full component ID: "Vendor::Class&Bundle:Group:Sub&[email protected]"
* @param withVersion true to append version as "@1.2.3"
* @brief get full component ID: "Vendor::Class&Bundle:Group:Sub&Variant\@1.2.3"
* @param withVersion true to append version as "\@1.2.3"
* @return full component ID
*/
virtual std::string GetComponentID(bool withVersion) const;
Expand Down
23 changes: 23 additions & 0 deletions libs/rtemodel/include/RtePackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ class RtePackage : public RteRootItem
*/
static std::string NameFromId(const std::string& id);

/**
* @brief helper static method to construct pack ID from supplied path
* @param path pack absolute or relative path
* @return pack ID string
*/
static std::string PackIdFromPath(const std::string& path);

/**
* @brief helper static method to compare pack IDs.
* Alpha-numeric comparison for vendor and name.
Expand Down Expand Up @@ -462,6 +469,16 @@ class RtePackage : public RteRootItem
*/
static std::string GetPackageIDfromAttributes(const XmlItem& attr, bool withVersion = true);

/**
* @brief get fully specified package identifier composed from individual strings
* @param vendor pack vendor
* @param name pack name
* @param version pack version
* @return string package identifier
*/
static std::string ComposePackageID(const std::string& vendor, const std::string& name, const std::string& version);


/**
* @brief get URL to download this pack from
* @param withVersion flag to return url with this version, otherwise without
Expand All @@ -484,6 +501,12 @@ class RtePackage : public RteRootItem
*/
RteItem* GetDefaultLicenseSet() const;

/**
* @brief get relative path to default license file agreement
* @return text of <license> element if any
*/
const std::string& GetPackLicenseFile() const { return GetChildText("license");}

/**
* @brief get condition with specified ID
* @param id condition ID to search for
Expand Down
124 changes: 123 additions & 1 deletion libs/rtemodel/include/RteProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,123 @@ class RteGenerator;
class RteTarget;
class CprjTargetElement;

/**
* @brief class to represent aggregated license info
*/
class RteLicenseInfo :public RteItem
{
public:
/**
* @brief default constructor
* @param parent
*/
RteLicenseInfo(RteItem* parent = nullptr);

/**
* @brief add component ID to the internal collection
* @param componentID component ID string
*/
void AddComponentId(const std::string& componentID) { m_componentIDs.insert(componentID); }

/**
* @brief add pack ID to the internal collection
* @param packID pack ID string
*/
void AddPackId(const std::string& packID) { m_packIDs.insert(packID); }


/**
* @brief return collection of component IDs associated with the license
* @return set of component IDs
*/
const std::set<std::string>& GetComponentIDs() const { return m_componentIDs; }

/**
* @brief return collection of pack IDs associated with the license
* @return set of pack IDs
*/
const std::set<std::string>& GetPackIDs() const { return m_packIDs; };

/**
* @brief return collection package IDs associated with the license
* @return pack ID string
*/
std::string GetPackageID(bool withVersion = true) const override { return GetAttribute("pack"); };

/**
* @brief convert info content to yml-like text
* @return yml formatted text
*/
std::string ToString(unsigned indent = 0);

/**
* @brief construct license title
* @param license pointer to RteItem representing <license> element
* @return license ID string : spdx or combination of title and type
*/
static std::string ConstructLicenseTitle(const RteItem* license);

/**
* @brief construct license internal ID
* @param license pointer to RteItem representing <license> element
* @return license ID string : spdx or combination of title, type and pack ID
*/
static std::string ConstructLicenseID(const RteItem* license);

protected:
std::set<std::string> m_componentIDs;
std::set<std::string> m_packIDs;
};

class RteLicenseInfoCollection
{
public:
/**
* @brief default constructor
*/
RteLicenseInfoCollection() {};

/**
* @brief virtual destructor
*/
virtual ~RteLicenseInfoCollection();

/**
* @brief clear internal structures
*/
void Clear();

/**
* @brief add license info to the collection
* @param item pointer to RteItem (RteComponent, RteApi, RtePackage)
*/
void AddLicenseInfo(RteItem* item);

/**
* @brief convert collection content to yml-like text
* @return yml formatted text
*/
std::string ToString();

protected:
/**
* @brief Ensure collection contains RteLicenseInfo object for specified object
* @param item RteItem* object to add
* @param license RteItem* pointing to license element, may be NULL
* @return pointer to RteLicenseInfo object
*/
RteLicenseInfo* EnsureLicensInfo(RteItem* item, RteItem* licenseElement);

/**
* @brief Ensure collection contains RteLicenseInfo object for specified ID
* @param licId internal license ID
* @return reference to RteLicenseInfo object
*/
RteLicenseInfo* EnsureLicensInfo(const std::string& licId);

std::map<std::string, RteLicenseInfo*> m_LicensInfos;
};

/**
* @brief class representing project consuming CMSIS RTE data
*/
Expand Down Expand Up @@ -431,7 +548,12 @@ class RteProject : public RteRootItem
*/
const RteFileInfo* GetFileInfo(const std::string& groupName, const std::string& file, const std::string& target) const;

public:
/**
* @brief collect license info used in project
* @param collection of license infos
*/
void CollectLicenseInfos(RteLicenseInfoCollection& licenseInfos) const;

/**
* @brief update CMSIS RTE data such as components, boards, gpdsc information, project files in project.
* @return true if CMSIS RTE data is updated otherwise false
Expand Down
5 changes: 2 additions & 3 deletions libs/rtemodel/src/RteKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RteCallback* RteKernel::GetRteCallback() const
return m_rteCallback ? m_rteCallback : RteCallback::GetGlobal();
}

void RteKernel::SetRteCallback(RteCallback* callback)
void RteKernel::SetRteCallback(RteCallback* callback)
{
m_rteCallback = callback;
GetGlobalModel()->SetCallback(m_rteCallback);
Expand Down Expand Up @@ -342,10 +342,9 @@ string RteKernel::GetInstalledPdscFile(const XmlItem& attributes, const string&
string path(rtePath);
path += '/' + vendor + '/' + name;


string installedVersion = RteFsUtils::GetInstalledPackVersion(path, versionRange);
if (!installedVersion.empty()) {
packId = vendor + '.' + name + '.' + installedVersion;
packId = RtePackage::ComposePackageID(vendor, name, installedVersion);
return path + '/' + installedVersion + '/' + vendor + '.' + name + ".pdsc";
}

Expand Down
Loading
Loading