Skip to content

Commit

Permalink
Implement cbuild-pack.yml support
Browse files Browse the repository at this point in the history
Fixes #1122

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-authored-by: Erik MÅLLBERG <erik.mallberg@st.com>
  • Loading branch information
Torbjorn-Svensson and ErikMallbergSTM committed Nov 17, 2023
1 parent 0123c00 commit 73d8b4c
Show file tree
Hide file tree
Showing 53 changed files with 1,455 additions and 44 deletions.
26 changes: 26 additions & 0 deletions tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ struct PackItem {
TypeFilter type;
};

/**
* @brief resolved pack item containing,
* pack ID,
* list of selected-by expressions (original expressions causing this pack to be added)
*/
struct ResolvedPackItem {
std::string pack;
std::vector<std::string> selectedBy;
};

/**
* @brief processor item containing
* processor fpu,
Expand Down Expand Up @@ -300,6 +310,21 @@ struct ContextDesc {
TypeFilter type;
};

/**
* @brief cbuild pack descriptor containing
* filename,
* full path to cbuild pack file,
* containing directory,
* list of resolved packs
*/
struct CbuildPackItem {
std::string name;
std::string path;
std::string directory;

std::vector<ResolvedPackItem> packs;
};

/**
* @brief default item containing
* cdefault path,
Expand Down Expand Up @@ -340,6 +365,7 @@ struct CsolutionItem {
std::vector<PackItem> packs;
bool enableCdefault;
GeneratorsItem generators;
CbuildPackItem cbuildPack;
};

/**
Expand Down
35 changes: 35 additions & 0 deletions tools/projmgr/include/ProjMgrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ struct OutputTypes {
OutputType cmse;
};

/**
* @brief pack info containing
* pack name,
* pack vendor,
* pack version
*/
struct PackInfo {
std::string name;
std::string vendor;
std::string version;
};

/**
* @brief vector of ConnectionsCollection
*/
Expand Down Expand Up @@ -357,6 +369,29 @@ class ProjMgrUtils {
*/
static const std::string& GetDeviceAttribute(const std::string& key, const std::string& value);

/**
* @brief convert a pack ID to a pack info
* @param packId the pack id (YML format)
* @param packInfo the pack info struct
* @return true on success
*/
static bool ConvertToPackInfo(const std::string& packId, PackInfo& packInfo);

/**
* @brief check if the two pack info structs match
* @param exactPackInfo fully qualified pack ID, without wildcards or ranges
* @param packInfoToMatch pack ID, may include wildcards or ranges
* @return true if match
*/
static bool IsMatchingPackInfo(const PackInfo& exactPackInfo, const PackInfo& packInfoToMatch);

/**
* @brief convert version in YML format to CPRJ range format
* @param version version in YML format
* @return version in CPRJ range format
*/
static std::string ConvertToVersionRange(const std::string& version);

protected:
static std::string ConstructID(const std::vector<std::pair<const char*, const std::string&>>& elements);
/**
Expand Down
19 changes: 6 additions & 13 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ struct ToolchainItem {
std::string config;
};

/**
* @brief pack info containing
* pack name,
* pack vendor,
* pack version
*/
struct PackInfo {
std::string name;
std::string vendor;
std::string version;
};

/**
* @brief package item containing
* pack information pack,
Expand Down Expand Up @@ -275,6 +263,8 @@ struct ContextTypesItem {
* device pack,
* board pack,
* boolean processed precedences
* map of user inputed pack ID to resolved pack ID
* set of absolute file paths of project local packs
*/
struct ContextItem {
CdefaultItem* cdefault = nullptr;
Expand Down Expand Up @@ -320,6 +310,8 @@ struct ContextItem {
RtePackage* devicePack;
RtePackage* boardPack;
bool precedences;
std::map<std::string, std::set<std::string>> userInputToResolvedPackIdMap;
std::set<std::string> localPackPaths;
};

/**
Expand Down Expand Up @@ -675,7 +667,7 @@ class ProjMgrWorker {
bool ProcessDevicePrecedence(StringCollection& item);
bool ProcessBoardPrecedence(StringCollection& item);
bool ProcessToolchain(ContextItem& context);
bool ProcessPackages(ContextItem& context);
bool ProcessPackages(ContextItem& context, const std::string& packRoot);
bool ProcessComponents(ContextItem& context);
RteComponent* ProcessComponent(ContextItem& context, ComponentItem& item, RteComponentMap& componentMap);
bool ProcessGpdsc(ContextItem& context);
Expand Down Expand Up @@ -759,6 +751,7 @@ class ProjMgrWorker {
void CheckCompilerFilterSpelling(const std::string& compiler);
bool ProcessGeneratedLayers(ContextItem& context);
void CheckDeviceAttributes(const std::string& device, const ProcessorItem& userSelection, const StrMap& targetAttributes);
std::vector<std::string> FindMatchingPackIdsInCbuildPack(const PackItem& needle, const std::vector<ResolvedPackItem>& resolvedPacks);
};

#endif // PROJMGRWORKER_H
8 changes: 8 additions & 0 deletions tools/projmgr/include/ProjMgrYamlEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class ProjMgrYamlEmitter {
*/
static bool GenerateCbuildSet(const std::vector<ContextItem*> contexts,
const std::string& selectedCompiler, const std::string& cbuildSetFile);

/**
* @brief generate cbuild pack file
* @param contexts vector with pointers to contexts
* @param keepExistingPackContent if true, all entries from existing cbuild-pack should be preserved
* @return true if executed successfully
*/
static bool GenerateCbuildPack(ProjMgrParser& parser, const std::vector<ContextItem*> contexts, bool keepExistingPackContent);
};

#endif // PROJMGRYAMLEMITTER_H
6 changes: 6 additions & 0 deletions tools/projmgr/include/ProjMgrYamlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static constexpr const char* YAML_CBUILDS = "cbuilds";
static constexpr const char* YAML_CBUILD = "cbuild";
static constexpr const char* YAML_CBUILD_GENS = "cbuild-gens";
static constexpr const char* YAML_CBUILD_GEN = "cbuild-gen";
static constexpr const char* YAML_CBUILD_PACK = "cbuild-pack";
static constexpr const char* YAML_CBUILD_SET = "cbuild-set";
static constexpr const char* YAML_CDEFAULT = "cdefault";
static constexpr const char* YAML_CLAYERS = "clayers";
Expand Down Expand Up @@ -123,6 +124,8 @@ static constexpr const char* YAML_PROJECTS = "projects";
static constexpr const char* YAML_PROJECT_TYPE = "project-type";
static constexpr const char* YAML_PROVIDES = "provides";
static constexpr const char* YAML_REGIONS = "regions";
static constexpr const char* YAML_RESOLVED_PACK = "resolved-pack";
static constexpr const char* YAML_RESOLVED_PACKS = "resolved-packs";
static constexpr const char* YAML_RTE = "rte";
static constexpr const char* YAML_RUN = "run";
static constexpr const char* YAML_SCOPE = "scope";
Expand Down Expand Up @@ -214,9 +217,11 @@ class ProjMgrYamlParser {
std::map<std::string, GlobalGeneratorItem>& generators, bool checkSchema);

protected:
bool ParseCbuildPack(const std::string& input, CbuildPackItem& cbuildPack, bool checkSchema);
void ParseMisc(const YAML::Node& parent, std::vector<MiscItem>& misc);
void ParseDefine(const YAML::Node& parent, std::vector<std::string>& define);
void ParsePacks(const YAML::Node& parent, const std::string& file, std::vector<PackItem>& packs);
void ParseResolvedPacks(const YAML::Node& parent, std::vector<ResolvedPackItem>& resolvedPacks);
void ParseProcessor(const YAML::Node& parent, ProcessorItem& processor);
void ParseBoolean(const YAML::Node& parent, const std::string& key, bool& value, bool def);
void ParseString(const YAML::Node& parent, const std::string& key, std::string& value);
Expand Down Expand Up @@ -246,6 +251,7 @@ class ProjMgrYamlParser {
bool ValidateCsolution(const std::string& input, const YAML::Node& root);
bool ValidateCproject(const std::string& input, const YAML::Node& root);
bool ValidateClayer(const std::string& input, const YAML::Node& root);
bool ValidateCbuildPack(const std::string& input, const YAML::Node& root);
bool ValidateCbuildSet(const std::string& input, const YAML::Node& root);
bool ValidateKeys(const std::string& input, const YAML::Node& parent, const std::set<std::string>& keys);
bool ValidateSequence(const std::string& input, const YAML::Node& parent, const std::string& seqKey);
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgrYamlSchemaChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ProjMgrYamlSchemaChecker : public YmlSchemaChecker {
PROJECT,
LAYER,
BUILD,
BUILD_PACK,
BUILDIDX,
BUILDSET,
GENERATOR,
Expand Down
13 changes: 13 additions & 0 deletions tools/projmgr/schemas/cbuild-pack.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.1.0/tools/projmgr/schemas/cbuild-pack.schema.json",
"title": "CMSIS cbuild-pack",
"description": "file containing all pack versions used, used for pack locking",
"version": "2.1.0",
"properties": {
"cbuild-pack": {
"$ref": "./common.schema.json#/definitions/BuildPackDescType"
}
},
"required": [ "cbuild-pack" ]
}
26 changes: 26 additions & 0 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,32 @@
}
}
},
"BuildPackDescType": {
"type": "object",
"properties": {
"resolved-packs": { "$ref": "#/definitions/ResolvedPacksType" }
},
"additionalProperties": false,
"required": [ "resolved-packs" ]
},
"ResolvedPacksType": {
"type": "array",
"uniqueItems": true,
"items": { "$ref": "#/definitions/ResolvedPackType" }
},
"ResolvedPackType": {
"type": "object",
"properties": {
"resolved-pack": { "$ref": "#/definitions/PackID" },
"selected-by": {
"type": "array",
"uniqueItems": true,
"items": { "$ref": "#/definitions/PackID" }
}
},
"additionalProperties": false,
"required": [ "resolved-pack" ]
},
"BuildPacksType": {
"type": "array",
"uniqueItems": true,
Expand Down
19 changes: 12 additions & 7 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,18 @@ bool ProjMgr::RunConfigure(bool printConfig) {
}
}

// Generate cbuild files
for (auto& contextItem : m_processedContexts) {
if (!m_emitter.GenerateCbuild(contextItem)) {
return false;
}

}

// Generate cbuild-pack file
const bool isUsingContexts = m_contextSet || m_context.size() != 0;
m_emitter.GenerateCbuildPack(m_parser, m_processedContexts, isUsingContexts);

return !error;
}

Expand Down Expand Up @@ -547,13 +559,6 @@ bool ProjMgr::RunConvert(void) {
}
}

// Generate cbuild files
for (auto& contextItem : m_processedContexts) {
if (!m_emitter.GenerateCbuild(contextItem)) {
return false;
}
}

return !error;
}

Expand Down
58 changes: 58 additions & 0 deletions tools/projmgr/src/ProjMgrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,61 @@ vector<string> ProjMgrUtils::GetFilteredContexts(
}
return selectedContexts;
}

bool ProjMgrUtils::ConvertToPackInfo(const string& packId, PackInfo& packInfo) {
string packInfoStr = packId;
if (packInfoStr.find("::") != string::npos) {
packInfo.vendor = RteUtils::RemoveSuffixByString(packInfoStr, "::");
packInfoStr = RteUtils::RemovePrefixByString(packInfoStr, "::");
packInfo.name = RteUtils::GetPrefix(packInfoStr, '@');
} else {
packInfo.vendor = RteUtils::GetPrefix(packInfoStr, '@');
}
packInfo.version = RteUtils::GetSuffix(packInfoStr, '@');

return true;
}

bool ProjMgrUtils::IsMatchingPackInfo(const PackInfo& exactPackInfo, const PackInfo& packInfoToMatch) {
// Check if vendor matches
if (packInfoToMatch.vendor != exactPackInfo.vendor) {
// Not same vendor
return false;
}

// Check if pack name matches
if (!packInfoToMatch.name.empty()) {
if (WildCards::IsWildcardPattern(packInfoToMatch.name)) {
// Check if filter matches
if (!WildCards::Match(packInfoToMatch.name, exactPackInfo.name)) {
// Name filter does not match needle
return false;
}
} else if (packInfoToMatch.name != exactPackInfo.name) {
// Not same pack name
return false;
}
}

// Check if version matches
string reqVersionRange = ConvertToVersionRange(packInfoToMatch.version);
if (!reqVersionRange.empty() && VersionCmp::RangeCompare(exactPackInfo.version, reqVersionRange) != 0) {
// Version out of range
return false;
}

// Needle matches this resolved pack
return true;
}

string ProjMgrUtils::ConvertToVersionRange(const string& version) {
string versionRange = version;
if (!versionRange.empty()) {
if (versionRange.find(">=") != string::npos) {
versionRange = versionRange.substr(2);
} else {
versionRange = versionRange + ":" + versionRange;
}
}
return versionRange;
}
Loading

0 comments on commit 73d8b4c

Please sign in to comment.