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 Oct 19, 2023
1 parent afcc7e5 commit df61a22
Show file tree
Hide file tree
Showing 45 changed files with 1,159 additions and 39 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 @@ -294,6 +304,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 @@ -334,6 +359,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 @@ -57,6 +57,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 @@ -299,6 +311,29 @@ class ProjMgrUtils {
const std::vector<std::string>& allContexts,
const std::string& contextReplace);


/**
* @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: 5 additions & 14 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 @@ -272,7 +260,8 @@ struct ContextTypesItem {
* linker options,
* map of variables,
* external generator directory,
* boolean processed precedences
* boolean processed precedences,
* map of fully qualified pack ID to pack ID with version range
*/
struct ContextItem {
CdefaultItem* cdefault = nullptr;
Expand Down Expand Up @@ -316,6 +305,7 @@ struct ContextItem {
std::map<std::string, std::string> variables;
StrMap extGenDir;
bool precedences;
std::map<std::string, std::string> eagerlyReplacedPackIdMap;
};

/**
Expand Down Expand Up @@ -672,7 +662,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 @@ -755,6 +745,7 @@ class ProjMgrWorker {
void CheckTypeFilterSpelling(const TypeFilter& typeFilter);
void CheckCompilerFilterSpelling(const std::string& compiler);
bool ProcessGeneratedLayers(ContextItem& context);
bool IsPackInCbuildPack(const PackItem& needle, const std::vector<ResolvedPackItem>& resolvedPacks, ResolvedPackItem& match);
};

#endif // PROJMGRWORKER_H
7 changes: 7 additions & 0 deletions tools/projmgr/include/ProjMgrYamlEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class ProjMgrYamlEmitter {
* @return true if executed successfully
*/
static bool GenerateCbuildSet(ProjMgrParser& parser, const std::vector<ContextItem*> contexts, const std::string& selectedCompiler);

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

#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 @@ -30,6 +30,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 @@ -118,6 +119,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 @@ -209,9 +212,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 @@ -241,6 +246,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 {
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 @@ -899,6 +899,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
2 changes: 2 additions & 0 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ bool ProjMgr::RunConvert(void) {
if (!m_emitter.GenerateCbuild(contextItem)) {
return false;
}

m_emitter.GenerateCbuildPack(m_parser, m_processedContexts);
}

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 @@ -420,3 +420,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 df61a22

Please sign in to comment.