Skip to content

Commit

Permalink
Add License Information to cbuild.yml files (BOM for projects) #1046 (#…
Browse files Browse the repository at this point in the history
…668) (#1083)

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

Add license info to cbuild.yml

Co-authored-by: Evgueni Driouk <[email protected]>
  • Loading branch information
grasci-arm and Evgueni Driouk authored Aug 4, 2023
1 parent 5f35f49 commit f367407
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 11 deletions.
13 changes: 13 additions & 0 deletions libs/rtemodel/include/RteProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class RteLicenseInfoCollection
*/
void AddLicenseInfo(RteItem* item);

/**
* @brief return collection of collected license infos
*/
const std::map<std::string, RteLicenseInfo*>& GetLicensInfos() const { return m_LicensInfos; }

/**
* @brief convert collection content to yml-like text
* @return yml formatted text
Expand Down Expand Up @@ -554,6 +559,14 @@ class RteProject : public RteRootItem
*/
void CollectLicenseInfos(RteLicenseInfoCollection& licenseInfos) const;

/**
* @brief collect license info used in project target
* @param collection of license infos
* @param targetName target name to collect info, empty string for active one
*/
void CollectLicenseInfosForTarget(RteLicenseInfoCollection& licenseInfos, const std::string& targetName) 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
28 changes: 19 additions & 9 deletions libs/rtemodel/src/RteProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ RteLicenseInfo* RteLicenseInfoCollection::EnsureLicenseInfo(RteItem* item, RteIt
licFile = pack->GetChildText("license");
}
if (!licFile.empty()) {
info->AddAttribute("agreement", "%CMSIS_PACK_ROOT%/" + pack->GetPackagePath(true) + licFile);
info->AddAttribute("agreement", "${CMSIS_PACK_ROOT}/" + pack->GetPackagePath(true) + licFile);
}
} else {
info = it->second;
Expand Down Expand Up @@ -2600,13 +2600,24 @@ void RteProject::CollectLicenseInfos(RteLicenseInfoCollection& licenseInfos) con
set<RteComponent*> components;
set<RtePackage*> packs;
for (auto [targetName, t] : GetTargets()) {
packs.insert(t->GetDevicePackage());
packs.insert(t->GetBoardPackage());
for (auto [_c, ci] : m_components) {
RteComponent* c = ci->GetResolvedComponent(targetName);
if (c) {
components.insert(c);
}
CollectLicenseInfosForTarget(licenseInfos, targetName);
}
}

void RteProject::CollectLicenseInfosForTarget(RteLicenseInfoCollection& licenseInfos, const std::string& targetName) const
{
RteTarget* t = GetTarget(targetName); // returns active one if targetName is empty
if (!t) {
return; // no such target
}
set<RteComponent*> components;
set<RtePackage*> packs;
packs.insert(t->GetDevicePackage());
packs.insert(t->GetBoardPackage());
for (auto [_c, ci] : m_components) {
RteComponent* c = ci->GetResolvedComponent(targetName);
if (c) {
components.insert(c);
}
}
for (auto c : components) {
Expand All @@ -2616,5 +2627,4 @@ void RteProject::CollectLicenseInfos(RteLicenseInfoCollection& licenseInfos) con
licenseInfos.AddLicenseInfo(p);
}
}

// End of RteProject.cpp
4 changes: 2 additions & 2 deletions test/projects/RteTestM3/license_info_ref.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
licenses:
- license: <proprietary> Proprietary Test License
license-agreement: %CMSIS_PACK_ROOT%/ARM/RteTest/0.1.0/licenses/ProprietaryLicense.txt
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest/0.1.0/licenses/ProprietaryLicense.txt
packs:
- pack: ARM::[email protected]
components:
- component: ARM::RteTest:[email protected]

- license: <unknown>
license-agreement: %CMSIS_PACK_ROOT%/ARM/RteTest_DFP/0.2.0/Doc/license.txt
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
packs:
- pack: ARM::[email protected]
components:
Expand Down
3 changes: 3 additions & 0 deletions tools/projmgr/include/ProjMgrYamlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ static constexpr const char* YAML_LANGUAGE_C = "language-C";
static constexpr const char* YAML_LANGUAGE_CPP = "language-CPP";
static constexpr const char* YAML_LAYER = "layer";
static constexpr const char* YAML_LAYERS = "layers";
static constexpr const char* YAML_LICENSE = "license";
static constexpr const char* YAML_LICENSES = "licenses";
static constexpr const char* YAML_LICENSE_AGREEMENT = "license-agreement";
static constexpr const char* YAML_LINKER = "linker";
static constexpr const char* YAML_MISC = "misc";
static constexpr const char* YAML_MISC_ASM = "ASM";
Expand Down
39 changes: 39 additions & 0 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@
"constructed-files": {
"type": "array",
"items": { "$ref": "#/definitions/FileType" }
},
"licenses": {
"type": "array",
"items": { "$ref": "#/definitions/LicenseInfoType" }
}
},
"additionalProperties": false
Expand Down Expand Up @@ -795,6 +799,41 @@
},
"additionalProperties": false
},
"LicenseInfoPackType": {
"type": "object",
"properties": {
"pack": { "$ref": "#/definitions/PackID" }
}
},
"LicenseInfoComponentType": {
"type": "object",
"properties": {
"component": { "type": "string" }
}
},
"LicenseInfoType": {
"type": "object",
"description": "License information about packs and components",
"properties": {
"license": {
"type": "string",
"description": "License SPDX name or title"
},
"license-agreement": {
"type": "string",
"description": "Path to license agreement file"
},
"packs": {
"type": "array",
"items": { "$ref": "#/definitions/LicenseInfoPackType" }
},
"components": {
"type": "array",
"description": "List of components or APIs component to license agreement file",
"items": { "$ref": "#/definitions/LicenseInfoComponentType" }
}
}
},
"PacksType": {
"type": "array",
"uniqueItems": true,
Expand Down
31 changes: 31 additions & 0 deletions tools/projmgr/src/ProjMgrYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ProjMgrYamlCbuild {
void SetGroupsNode(YAML::Node node, const ContextItem* context, const vector<GroupNode>& groups);
void SetFilesNode(YAML::Node node, const ContextItem* context, const vector<FileNode>& files);
void SetLinkerNode(YAML::Node node, const ContextItem* context);
void SetLicenseInfoNode(YAML::Node node, const ContextItem* context);
void SetControlsNode(YAML::Node Node, const ContextItem* context, const BuildType& controls);
void SetProcessorNode(YAML::Node node, const map<string, string>& targetAttributes);
void SetMiscNode(YAML::Node miscNode, const MiscItem& misc);
Expand Down Expand Up @@ -147,6 +148,7 @@ void ProjMgrYamlCbuild::SetContextNode(YAML::Node contextNode, const ContextItem
SetLinkerNode(contextNode[YAML_LINKER], context);
SetGroupsNode(contextNode[YAML_GROUPS], context, context->groups);
SetConstructedFilesNode(contextNode[YAML_CONSTRUCTEDFILES], context);
SetLicenseInfoNode(contextNode[YAML_LICENSES], context);
}

void ProjMgrYamlCbuild::SetComponentsNode(YAML::Node node, const ContextItem* context) {
Expand Down Expand Up @@ -346,6 +348,35 @@ void ProjMgrYamlCbuild::SetLinkerNode(YAML::Node node, const ContextItem* contex
SetDefineNode(node[YAML_DEFINE], context->linker.defines);
}

void ProjMgrYamlCbuild::SetLicenseInfoNode(YAML::Node node, const ContextItem* context) {
// add licensing info for active target
RteLicenseInfoCollection licenseInfos;
context->rteActiveProject->CollectLicenseInfosForTarget(licenseInfos, context->rteActiveTarget->GetName());
for (auto [id, licInfo] : licenseInfos.GetLicensInfos()) {

YAML::Node licNode;
SetNodeValue(licNode[YAML_LICENSE], RteLicenseInfo::ConstructLicenseTitle(licInfo));
const string& license_agreement = licInfo->GetAttribute("agreement");
if (!license_agreement.empty()) {
SetNodeValue(licNode[YAML_LICENSE_AGREEMENT], license_agreement);
}
YAML::Node packsNode = licNode[YAML_PACKS];
for (auto pack : licInfo->GetPackIDs()) {
YAML::Node packNode;
SetNodeValue(packNode[YAML_PACK], pack);
packsNode.push_back(packNode);
}
YAML::Node componentsNode = licNode[YAML_COMPONENTS];
for (auto compID : licInfo->GetComponentIDs()) {
YAML::Node componentNode;
SetNodeValue(componentNode[YAML_COMPONENT], compID);
componentsNode.push_back(componentNode);
}
node.push_back(licNode);
}
}


void ProjMgrYamlCbuild::SetControlsNode(YAML::Node node, const ContextItem* context, const BuildType& controls) {
SetNodeValue(node[YAML_OPTIMIZE], controls.optimize);
SetNodeValue(node[YAML_DEBUG], controls.debug);
Expand Down

0 comments on commit f367407

Please sign in to comment.