diff --git a/libs/rtemodel/include/RteProject.h b/libs/rtemodel/include/RteProject.h index 32af96a76..9cb02ed66 100644 --- a/libs/rtemodel/include/RteProject.h +++ b/libs/rtemodel/include/RteProject.h @@ -123,6 +123,11 @@ class RteLicenseInfoCollection */ void AddLicenseInfo(RteItem* item); + /** + * @brief return collection of collected license infos + */ + const std::map& GetLicensInfos() const { return m_LicensInfos; } + /** * @brief convert collection content to yml-like text * @return yml formatted text @@ -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 diff --git a/libs/rtemodel/src/RteProject.cpp b/libs/rtemodel/src/RteProject.cpp index c30d840eb..1f0438ade 100644 --- a/libs/rtemodel/src/RteProject.cpp +++ b/libs/rtemodel/src/RteProject.cpp @@ -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; @@ -2600,13 +2600,24 @@ void RteProject::CollectLicenseInfos(RteLicenseInfoCollection& licenseInfos) con set components; set 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 components; + set 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) { @@ -2616,5 +2627,4 @@ void RteProject::CollectLicenseInfos(RteLicenseInfoCollection& licenseInfos) con licenseInfos.AddLicenseInfo(p); } } - // End of RteProject.cpp diff --git a/test/projects/RteTestM3/license_info_ref.txt b/test/projects/RteTestM3/license_info_ref.txt index 620dc9f83..84f932594 100644 --- a/test/projects/RteTestM3/license_info_ref.txt +++ b/test/projects/RteTestM3/license_info_ref.txt @@ -1,13 +1,13 @@ licenses: - license: 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::RteTest@0.1.0 components: - component: ARM::RteTest:ComponentLevel@0.0.1 - license: - 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::RteTest_DFP@0.2.0 components: diff --git a/tools/projmgr/include/ProjMgrYamlParser.h b/tools/projmgr/include/ProjMgrYamlParser.h index 592116d9e..09da0bd7b 100644 --- a/tools/projmgr/include/ProjMgrYamlParser.h +++ b/tools/projmgr/include/ProjMgrYamlParser.h @@ -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"; diff --git a/tools/projmgr/schemas/common.schema.json b/tools/projmgr/schemas/common.schema.json index 74ba473ea..37bd65819 100644 --- a/tools/projmgr/schemas/common.schema.json +++ b/tools/projmgr/schemas/common.schema.json @@ -757,6 +757,10 @@ "constructed-files": { "type": "array", "items": { "$ref": "#/definitions/FileType" } + }, + "licenses": { + "type": "array", + "items": { "$ref": "#/definitions/LicenseInfoType" } } }, "additionalProperties": false @@ -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, diff --git a/tools/projmgr/src/ProjMgrYamlEmitter.cpp b/tools/projmgr/src/ProjMgrYamlEmitter.cpp index ac39f1ddf..0a8470a2c 100644 --- a/tools/projmgr/src/ProjMgrYamlEmitter.cpp +++ b/tools/projmgr/src/ProjMgrYamlEmitter.cpp @@ -43,6 +43,7 @@ class ProjMgrYamlCbuild { void SetGroupsNode(YAML::Node node, const ContextItem* context, const vector& groups); void SetFilesNode(YAML::Node node, const ContextItem* context, const vector& 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& targetAttributes); void SetMiscNode(YAML::Node miscNode, const MiscItem& misc); @@ -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) { @@ -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);