diff --git a/libs/rtefsutils/include/RteFsUtils.h b/libs/rtefsutils/include/RteFsUtils.h index 1fac98326..347d43317 100644 --- a/libs/rtefsutils/include/RteFsUtils.h +++ b/libs/rtefsutils/include/RteFsUtils.h @@ -359,6 +359,24 @@ class RteFsUtils * @return string containing the absolute path */ static std::string GetAbsPathFromLocalUrl(const std::string& url); + + /** + * @brief finds file in directories relative to the base path + * @param fileName file name to search for + * @param baseDir path to look in + * @param relSearchOrder vector of relative directories to look in + * @return absolute file name if found, empty string otherwise + */ + static std::string FindFile(const std::string& fileName, const std::string& baseDir, + const std::vector& relSearchOrder); + + /** + * @brief finds file in ./, ../etc/, and ../../etc directories relative to the base + * @param fileName file name to search for + * @param baseDir path to look in + * @return absolute file name if found, empty string otherwise + */ + static std::string FindFileInEtc(const std::string& fileName, const std::string& baseDir); }; #endif // RteFsUtils_H diff --git a/libs/rtefsutils/src/RteFsUtils.cpp b/libs/rtefsutils/src/RteFsUtils.cpp index d6e177944..fa7146ae9 100644 --- a/libs/rtefsutils/src/RteFsUtils.cpp +++ b/libs/rtefsutils/src/RteFsUtils.cpp @@ -822,4 +822,22 @@ string RteFsUtils::GetAbsPathFromLocalUrl(const string& url) { return filepath; } +std::string RteFsUtils::FindFile(const std::string& fileName, const std::string& baseDir, + const std::vector& relSearchOrder) +{ + for(auto& relPath : relSearchOrder) { + string file = baseDir + relPath + fileName; + if(RteFsUtils::Exists(file)) { + return MakePathCanonical(file); + } + } + return RteUtils::EMPTY_STRING; +} + +std::string RteFsUtils::FindFileInEtc(const std::string& fileName, const std::string& baseDir) +{ + static const std::vector& relSearchOrder = { "./", "../etc/", "../../etc/" }; + return FindFile(fileName, baseDir, relSearchOrder); +} + // End of RteFsUtils.cpp diff --git a/libs/rtemodel/CMakeLists.txt b/libs/rtemodel/CMakeLists.txt index 2da3a3ac1..19c75394e 100644 --- a/libs/rtemodel/CMakeLists.txt +++ b/libs/rtemodel/CMakeLists.txt @@ -21,4 +21,4 @@ set_property(TARGET RteModel PROPERTY target_include_directories(RteModel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_link_libraries(RteModel RteFsUtils RteUtils XmlTree CrossPlatform) +target_link_libraries(RteModel RteFsUtils RteUtils XmlTree YmlTree CrossPlatform) diff --git a/libs/rtemodel/include/RteKernel.h b/libs/rtemodel/include/RteKernel.h index 8aeeff454..b7404922b 100644 --- a/libs/rtemodel/include/RteKernel.h +++ b/libs/rtemodel/include/RteKernel.h @@ -18,7 +18,7 @@ #include "RteTarget.h" #include "RteUtils.h" -#include "XMLTree.h" +#include "YmlTree.h" #include @@ -57,6 +57,19 @@ class RteKernel */ bool SetCmsisPackRoot(const std::string& cmsisPackRoot); + /** + * @brief getter for CMSIS-Toolbox installation directory + * @return CMSIS-Toolbox installation directory if available + */ + const std::string& GetCmsisToolboxDir() const { return m_cmsisToolboxDir; } + + /** + * @brief setter for CMSIS-Toolbox installation directory + * @param cmsisToolboxDir CMSIS-Toolbox installation directory to set + */ + void SetCmsisToolboxDir(const std::string& cmsisToolboxDir) { m_cmsisToolboxDir = cmsisToolboxDir; } + + /** * @brief getter for RteCallback object * @return pointer to RteCallback object @@ -218,11 +231,19 @@ class RteKernel std::string GetPdscFileFromPath(const XmlItem& attributes, const std::string& cprjPath, std::string& packId); /** - * @brief create a smart pointer holding a XMLTree pointer - * @return a std::unique_ptr object holding a XMLTree pointer which is nullptr in the default implementation + * @brief create a smart pointer holding an XMLTree pointer to parse XML files + * @param itemBuilder pointer to IXmlItemBuilder item factory + * @return a std::unique_ptr object holding an XMLTree-derived pointer which is nullptr in the default implementation */ virtual std::unique_ptr CreateUniqueXmlTree(IXmlItemBuilder* itemBuilder = nullptr) const; + /** + * @brief create a smart pointer holding a YmlTree pointer to parse YAML files + * @param itemBuilder pointer to IXmlItemBuilder item factory + * @return a std::unique_ptr object holding a YmlTree-derived pointer which is nullptr in the default implementation + */ + virtual std::unique_ptr CreateUniqueYmlTree(IXmlItemBuilder* itemBuilder = nullptr) const; + /** * @brief save active project into cprj file * @param file cprj file name @@ -274,7 +295,19 @@ class RteKernel bool GetLocalPacksUrls(const std::string& rtePath, std::list& urls) const; XMLTreeElement* ParseLocalRepositoryIdx(const std::string& rtePath) const; - virtual XMLTree* CreateXmlTree(IXmlItemBuilder* itemBuilder) const { return nullptr; } // creates new XMLTree implementation + /** + * @brief create an XMLTree object to parse XML files + * @param itemBuilder pointer to IXmlItemBuilder item factory + * @return XMLTree-derived pointer which is nullptr in the default implementation + */ + virtual XMLTree* CreateXmlTree(IXmlItemBuilder* itemBuilder) const { return nullptr; } + + /** + * @brief create a YmlTree object to parse YAML files + * @param itemBuilder pointer to IXmlItemBuilder item factory + * @return YmlTree-derived pointer + */ + virtual YmlTree* CreateYmlTree(IXmlItemBuilder* itemBuilder) const; protected: /** @@ -288,5 +321,6 @@ class RteKernel RteCallback* m_rteCallback; XmlItem m_toolInfo; std::string m_cmsisPackRoot; + std::string m_cmsisToolboxDir; }; #endif // RteKernel_H diff --git a/libs/rtemodel/src/RteKernel.cpp b/libs/rtemodel/src/RteKernel.cpp index 8ff11e458..f1430eefc 100644 --- a/libs/rtemodel/src/RteKernel.cpp +++ b/libs/rtemodel/src/RteKernel.cpp @@ -21,6 +21,7 @@ #include "RteUtils.h" #include "RteFsUtils.h" #include "XmlFormatter.h" +#include "YmlFormatter.h" using namespace std; @@ -560,4 +561,15 @@ unique_ptr RteKernel::CreateUniqueXmlTree(IXmlItemBuilder* itemBuilder) return xmlTree; } +unique_ptr RteKernel::CreateUniqueYmlTree(IXmlItemBuilder* itemBuilder) const +{ + unique_ptr ymlTree(CreateYmlTree(itemBuilder)); + return ymlTree; +} + +YmlTree* RteKernel::CreateYmlTree(IXmlItemBuilder* itemBuilder) const +{ + return new YmlTree(itemBuilder); +} + // End of RteKernel.cpp diff --git a/libs/rteutils/include/ISchemaChecker.h b/libs/rteutils/include/ISchemaChecker.h index d1f569cb2..53974c258 100644 --- a/libs/rteutils/include/ISchemaChecker.h +++ b/libs/rteutils/include/ISchemaChecker.h @@ -8,6 +8,7 @@ #define ISCHEMA_CHECKER_H #include "RteError.h" +#include "RteUtils.h" #include /** @@ -29,6 +30,20 @@ class ISchemaChecker */ virtual bool ValidateFile(const std::string& file, const std::string& schemaFile) = 0; + /** + * @brief Validates a file against schema obtained by FindSchema() method + * @param fileName file to validate + * @return true if successful + */ + virtual bool Validate(const std::string& file) { return ValidateFile(file, FindSchema(file)); } + + /** + * @brief Finds schema for given file to validate + * @param fileName file to validate + * @return schema file name if found, empty string otherwise + */ + virtual std::string FindSchema(const std::string& file) const { return RteUtils::EMPTY_STRING; } + /** * @brief returns collection of error messages found during last run of validate */ diff --git a/libs/xmltree/include/XMLTree.h b/libs/xmltree/include/XMLTree.h index 7c424c38b..dc57a6bb8 100644 --- a/libs/xmltree/include/XMLTree.h +++ b/libs/xmltree/include/XMLTree.h @@ -11,7 +11,7 @@ */ /******************************************************************************/ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -347,7 +347,7 @@ class XMLTree : public XMLTreeElement * @param xmlString buffer containing XML formatted text * @return true if buffer is successfully parsed */ - bool ParseXmlString(const std::string& xmlString); + bool ParseString(const std::string& xmlString); /** * @brief parse either file or buffer containing XML formatted text @@ -401,6 +401,11 @@ class XMLTree : public XMLTreeElement protected: // parses file or XML sting (fileName can be used to associate parsed document with the file) bool DoParse(const std::string& fileName, const std::string& xmlString); + /** + * @brief creates underling parser interface + * @return XMLTreeParserInterface; + */ + virtual XMLTreeParserInterface* CreateParserInterface() = 0; protected: std::string m_schemaFile; // schema file with path diff --git a/libs/xmltree/src/XMLTree.cpp b/libs/xmltree/src/XMLTree.cpp index e1b3c9db8..a65cbb683 100644 --- a/libs/xmltree/src/XMLTree.cpp +++ b/libs/xmltree/src/XMLTree.cpp @@ -1,6 +1,6 @@ /******************************************************************************/ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -120,7 +120,13 @@ void XMLTree::SetIgnoreTags(const set& ignoreTags) bool XMLTree::Init() { - return m_p->Init(); + if(!m_p) { + m_p = CreateParserInterface(); + } + if(m_p) { + return m_p->Init(); + } + return false; } @@ -173,30 +179,36 @@ bool XMLTree::ParseAll() bool XMLTree::ParseFile(const string& fileName) { - if(m_schemaChecker && !m_schemaFile.empty()) { - m_schemaChecker->ClearErrors(); - if(!m_schemaChecker->ValidateFile(fileName, m_schemaFile)) { - for(auto& err : m_schemaChecker->GetErrors()) { - if(err.m_severity == RteError::SevERROR) { - m_nErrors++; - } else if(err.m_severity == RteError::SevWARNING) { - m_nWarnings++; + if(m_schemaChecker ) { + const string& schema = m_schemaFile.empty() ? m_schemaChecker->FindSchema(fileName) : m_schemaFile; + if(!schema.empty()) { + m_schemaChecker->ClearErrors(); + if(!m_schemaChecker->ValidateFile(fileName, m_schemaFile)) { + for(auto& err : m_schemaChecker->GetErrors()) { + if(err.m_severity == RteError::SevERROR) { + m_nErrors++; + } else if(err.m_severity == RteError::SevWARNING) { + m_nWarnings++; + } + m_errorStrings.push_back(err.ToString()); } - m_errorStrings.push_back(err.ToString()); + return false; } - return false; } } return Parse(fileName, EMPTY_STRING); } -bool XMLTree::ParseXmlString(const std::string& xmlString) { +bool XMLTree::ParseString(const std::string& xmlString) { return Parse(EMPTY_STRING, xmlString); } bool XMLTree::Parse(const std::string& fileName, const std::string& xmlString) { + if(!Init()) { + return false; + } m_p->Clear(); return DoParse(fileName, xmlString); } diff --git a/libs/xmltree/test/src/XmlFormatterTest.cpp b/libs/xmltree/test/src/XmlFormatterTest.cpp index 7fd9e8e72..8129d6ba7 100644 --- a/libs/xmltree/test/src/XmlFormatterTest.cpp +++ b/libs/xmltree/test/src/XmlFormatterTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,6 +14,8 @@ class XMLTreeDummy : public XMLTree { public: XMLTreeDummy(IXmlItemBuilder* itemBuilder = NULL) : XMLTree(itemBuilder) {} +protected: + XMLTreeParserInterface* CreateParserInterface() override { return nullptr; } }; static const string xmlSchemaFile = "CPRJ.xsd"; @@ -84,6 +86,10 @@ static const string jsonResExpected = string("{\n") + "}\n"; +TEST(XMLTree, CannotParseWithoutInterface) { + auto tree = make_unique(); + EXPECT_FALSE(tree->ParseString(xmlResExpected)); +} TEST(XMLFormatterTest, HeaderAndContentTest) diff --git a/libs/xmltreeslim/include/XMLTreeSlim.h b/libs/xmltreeslim/include/XMLTreeSlim.h index 88fa3b471..dbcdc643f 100644 --- a/libs/xmltreeslim/include/XMLTreeSlim.h +++ b/libs/xmltreeslim/include/XMLTreeSlim.h @@ -3,8 +3,8 @@ /******************************************************************************/ /** @file XmlTreeSlim.h * @brief A simple XML interface that reads data into a tree structure - * @uses XmlReader -*/ + * @uses XmlReader +*/ /******************************************************************************/ /* * The reader should be kept semantics-free: @@ -12,8 +12,8 @@ */ /******************************************************************************/ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. - * + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 */ /******************************************************************************/ @@ -35,6 +35,12 @@ class XMLTreeSlim : public XMLTree * @param bIgnoreAttributePrefixes true to ignore attribute prefixes otherwise false */ XMLTreeSlim(IXmlItemBuilder* itemBuilder = NULL, bool bRedirectErrLog = false, bool bIgnoreAttributePrefixes = true); + +protected: + XMLTreeParserInterface* CreateParserInterface() override; + bool m_bRedirectErrLog; + bool m_bIgnoreAttributePrefixes; + }; #endif // XMLTreeSlim_H diff --git a/libs/xmltreeslim/include/XMLTreeSlimString.h b/libs/xmltreeslim/include/XMLTreeSlimString.h index 74e00b523..fb6f3c57e 100644 --- a/libs/xmltreeslim/include/XMLTreeSlimString.h +++ b/libs/xmltreeslim/include/XMLTreeSlimString.h @@ -12,20 +12,20 @@ */ /******************************************************************************/ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ /******************************************************************************/ -#include "XMLTree.h" +#include "XMLTreeSlim.h" class IXmlItemBuilder; /** * @brief XML interface that reads data into a tree structure */ -class XMLTreeSlimString : public XMLTree +class XMLTreeSlimString : public XMLTreeSlim { public: /** diff --git a/libs/xmltreeslim/src/XMLTreeSlim.cpp b/libs/xmltreeslim/src/XMLTreeSlim.cpp index dc12c448d..da9fd537a 100644 --- a/libs/xmltreeslim/src/XMLTreeSlim.cpp +++ b/libs/xmltreeslim/src/XMLTreeSlim.cpp @@ -1,7 +1,7 @@ /******************************************************************************/ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. - * + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 */ /******************************************************************************/ @@ -13,9 +13,17 @@ #include "ErrLog.h" XMLTreeSlim::XMLTreeSlim(IXmlItemBuilder* itemBuilder, bool bRedirectErrLog, bool bIgnoreAttributePrefixes) : - XMLTree(itemBuilder) + XMLTree(itemBuilder), + m_bRedirectErrLog(bRedirectErrLog), + m_bIgnoreAttributePrefixes(bIgnoreAttributePrefixes) { - m_p = new XMLTreeSlimInterface(this, bRedirectErrLog, bIgnoreAttributePrefixes, + //immediately create the parser interface + m_p = XMLTreeSlim::CreateParserInterface(); +} + +XMLTreeParserInterface* XMLTreeSlim::CreateParserInterface() +{ + return new XMLTreeSlimInterface(this, m_bRedirectErrLog, m_bIgnoreAttributePrefixes, new XML_InputSourceReaderFile()); } diff --git a/libs/xmltreeslim/src/XMLTreeSlimString.cpp b/libs/xmltreeslim/src/XMLTreeSlimString.cpp index a4e203804..cd0cda18c 100644 --- a/libs/xmltreeslim/src/XMLTreeSlimString.cpp +++ b/libs/xmltreeslim/src/XMLTreeSlimString.cpp @@ -1,7 +1,7 @@ /******************************************************************************/ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. - * + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 */ /******************************************************************************/ @@ -12,7 +12,7 @@ #include "ErrLog.h" XMLTreeSlimString::XMLTreeSlimString(IXmlItemBuilder* itemBuilder, bool bRedirectErrLog, bool bIgnoreAttributePrefixes) : - XMLTree(itemBuilder) + XMLTreeSlim(itemBuilder, bRedirectErrLog, bIgnoreAttributePrefixes) { m_p = new XMLTreeSlimInterface(this, bRedirectErrLog, bIgnoreAttributePrefixes); } diff --git a/libs/xmltreeslim/src/XmlTreeSlimInterface.cpp b/libs/xmltreeslim/src/XmlTreeSlimInterface.cpp index 9b06993c5..4de753223 100644 --- a/libs/xmltreeslim/src/XmlTreeSlimInterface.cpp +++ b/libs/xmltreeslim/src/XmlTreeSlimInterface.cpp @@ -86,7 +86,7 @@ XMLTreeSlimInterface::~XMLTreeSlimInterface() bool XMLTreeSlimInterface::Init() { - // does nothing for undelying XML_Parser + // does nothing for underlying XML_Parser return true; } diff --git a/libs/xmltreeslim/test/XmlTreeSlimTest.cpp b/libs/xmltreeslim/test/XmlTreeSlimTest.cpp index 9a4d81944..02cdbc931 100644 --- a/libs/xmltreeslim/test/XmlTreeSlimTest.cpp +++ b/libs/xmltreeslim/test/XmlTreeSlimTest.cpp @@ -118,7 +118,7 @@ TEST_F(XmlTreeSlimTest, ReadFileXmlns) { TEST_F(XmlTreeSlimTest, ReadFileStringXmlns) { XMLTreeSlim tree(nullptr, true, false); // default builder, redirect errors, do not ignore attribute prefixes - bool success = tree.ParseXmlString(theXmlString); + bool success = tree.ParseString(theXmlString); EXPECT_TRUE(success); EXPECT_TRUE(tree.GetRoot()); XMLTreeElement* root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; @@ -136,7 +136,7 @@ TEST_F(XmlTreeSlimTest, ReadFileStringXmlns) { TEST_F(XmlTreeSlimTest, ReadStringXmlns) { XMLTreeSlimString tree(nullptr, true, false); // default builder, redirect errors, do not ignore attribute prefixes - bool success = tree.ParseXmlString(theXmlString); + bool success = tree.ParseString(theXmlString); EXPECT_TRUE(success); EXPECT_TRUE(tree.GetRoot()); XMLTreeElement* root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; diff --git a/libs/ymltree/include/YmlTree.h b/libs/ymltree/include/YmlTree.h index 254b3ffc1..0f1ca724b 100644 --- a/libs/ymltree/include/YmlTree.h +++ b/libs/ymltree/include/YmlTree.h @@ -11,7 +11,7 @@ */ /******************************************************************************/ /* - * Copyright (c) 2020-2023 Arm Limited. All rights reserved. + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,6 +21,7 @@ class IXmlItemBuilder; class ISchemaChecker; +class YmlTreeParserInterface; /** * @brief a simple YAML interface that reads data into a tree structure */ @@ -34,6 +35,24 @@ class YmlTree : public XMLTree * @param bIgnoreAttributePrefixes true to ignore attribute prefixes otherwise false */ YmlTree(IXmlItemBuilder* itemBuilder = nullptr); + +protected: + /** + * @brief creates underling YML parser interface + * @return XMLTreeParserInterface; + */ + XMLTreeParserInterface* CreateParserInterface() override; + + /** + * @brief return underling YAML parser interface + * @return YmlTreeParserInterface + */ + YmlTreeParserInterface* GetYmlParserInterface() const { return m_pYmlInterface; } + + /** + * @brief to provide direct access to YAML data is needed + */ + YmlTreeParserInterface* m_pYmlInterface; }; #endif // YMLTree_H diff --git a/libs/ymltree/src/YmlTree.cpp b/libs/ymltree/src/YmlTree.cpp index 1eeccbbf2..aecf1d182 100644 --- a/libs/ymltree/src/YmlTree.cpp +++ b/libs/ymltree/src/YmlTree.cpp @@ -1,6 +1,6 @@ /******************************************************************************/ /* - * Copyright (c) 2020-2023 Arm Limited. All rights reserved. + * Copyright (c) 2020-2024 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,9 +11,17 @@ YmlTree::YmlTree(IXmlItemBuilder* itemBuilder) : - XMLTree(itemBuilder) + XMLTree(itemBuilder), + m_pYmlInterface(nullptr) { - m_p = new YmlTreeParserInterface(this); +} + +XMLTreeParserInterface* YmlTree::CreateParserInterface() +{ + if(!m_pYmlInterface) { + m_pYmlInterface = new YmlTreeParserInterface(this); + } + return m_pYmlInterface; } // End of YmlTree.cpp diff --git a/libs/ymltree/src/YmlTreeParserInterface.cpp b/libs/ymltree/src/YmlTreeParserInterface.cpp index c9cac4824..b57835eac 100644 --- a/libs/ymltree/src/YmlTreeParserInterface.cpp +++ b/libs/ymltree/src/YmlTreeParserInterface.cpp @@ -33,7 +33,11 @@ bool YmlTreeParserInterface::Init() void YmlTreeParserInterface::Clear() // does not destroy YAML parser! { - // does nothing for underlying YAML Parser + try { + m_root.reset(); + } catch(YAML::Exception& e) { + // do nothing + } } @@ -46,13 +50,12 @@ bool YmlTreeParserInterface::Parse(const std::string& fileName, const std::strin m_xmlFile = RteFsUtils::MakePathCanonical(fileName); try { - YAML::Node root; if (!inputString.empty()) { - root = YAML::Load(inputString); + m_root = YAML::Load(inputString); } else { - root = YAML::LoadFile(m_xmlFile); + m_root = YAML::LoadFile(m_xmlFile); } - success = ParseNode(root, RteUtils::EMPTY_STRING); + success = ParseNode(m_root, RteUtils::EMPTY_STRING); } catch (YAML::Exception& e) { stringstream ss; @@ -61,7 +64,7 @@ bool YmlTreeParserInterface::Parse(const std::string& fileName, const std::strin m_nErrors++; success = false; } - m_xmlFile = ""; + m_xmlFile.clear(); return success; } diff --git a/libs/ymltree/src/YmlTreeParserInterface.h b/libs/ymltree/src/YmlTreeParserInterface.h index e1ae98421..284065299 100644 --- a/libs/ymltree/src/YmlTreeParserInterface.h +++ b/libs/ymltree/src/YmlTreeParserInterface.h @@ -49,6 +49,12 @@ class YmlTreeParserInterface : public XMLTreeParserInterface */ bool Parse(const std::string& fileName, const std::string& inputString) override; + /** + * @brief return root node corresponding currently parsed file + * @return valid YAML::Node if parsing was successful + */ + const YAML::Node& GetRootNode() const { return m_root; } + protected: virtual bool ParseNode(const YAML::Node& node, const std::string& tag); virtual bool DoParseNode(const YAML::Node& node, const std::string& tag); @@ -56,6 +62,8 @@ class YmlTreeParserInterface : public XMLTreeParserInterface virtual bool ParseSequenceNode(const YAML::Node& node); virtual bool ParseScalarNode(const YAML::Node& node); virtual bool CreateItem(const std::string& tag, int line); + + YAML::Node m_root; // current root node }; #endif //YML_TREE_PARSER_INTERFACE_H diff --git a/libs/ymltree/test/YmlTreeTest.cpp b/libs/ymltree/test/YmlTreeTest.cpp index 6d7e2ab4f..310b0e69e 100644 --- a/libs/ymltree/test/YmlTreeTest.cpp +++ b/libs/ymltree/test/YmlTreeTest.cpp @@ -41,7 +41,7 @@ static string theYmlString = "build-idx:\n\ project: project\n\ configuration: .Release+TEST_TARGET"; -class YmlTreeTest :public ::testing::Test { +class YmlTreeTestF :public ::testing::Test { protected: void SetUp() override { @@ -55,7 +55,26 @@ class YmlTreeTest :public ::testing::Test { }; -TEST_F(YmlTreeTest, Sequence) { +TEST(YmlTreeTest, InvalidInput) { + const string yaml_input ="invalid: 1 : 2"; + + YmlTree tree; + EXPECT_FALSE(tree.ParseString(yaml_input)); + auto& errs = tree.GetErrorStrings(); + ASSERT_EQ(errs.size(), 1); + EXPECT_EQ("(1,12):illegal map value", *errs.begin()); +} + +TEST(YmlTreeTest, InvalidFile) { + YmlTree tree; + EXPECT_FALSE(tree.ParseFile("BadFood")); + auto& errs = tree.GetErrorStrings(); + ASSERT_EQ(errs.size(), 1); + EXPECT_EQ((*errs.begin()).find("BadFood(0,0):bad file:"), 0); +} + + +TEST(YmlTreeTest, Sequence) { const string yaml_input = "prime:\n\ - two\n\ @@ -70,7 +89,7 @@ TEST_F(YmlTreeTest, Sequence) { \n"; YmlTree tree; - EXPECT_TRUE(tree.ParseXmlString(yaml_input)); + EXPECT_TRUE(tree.ParseString(yaml_input)); EXPECT_TRUE(tree.GetRoot()); XMLTreeElement* root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; EXPECT_TRUE(root); @@ -85,12 +104,12 @@ TEST_F(YmlTreeTest, Sequence) { } -TEST_F(YmlTreeTest, KeyVal) { +TEST(YmlTreeTest, KeyVal) { const string yaml_input = "key: val"; const string expected_output = XML_HEADER + "val\n"; YmlTree tree; - EXPECT_TRUE(tree.ParseXmlString(yaml_input)); + EXPECT_TRUE(tree.ParseString(yaml_input)); EXPECT_TRUE(tree.GetRoot()); XMLTreeElement* root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; EXPECT_TRUE(root); @@ -102,9 +121,21 @@ TEST_F(YmlTreeTest, KeyVal) { YmlFormatter ymlFormatter; string ymlContent = ymlFormatter.FormatElement(root); EXPECT_EQ(ymlContent, yaml_input); + + const string yaml_input1 = "key1: val1"; + const string expected_output1 = XML_HEADER + "val1\n"; + + tree.Clear(); + EXPECT_TRUE(tree.ParseString(yaml_input1)); + EXPECT_TRUE(tree.GetRoot()); + root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; + EXPECT_TRUE(root); + + xmlContent = xmlFormatter.FormatElement(root); + EXPECT_EQ(xmlContent, expected_output1); } -TEST_F(YmlTreeTest, Map) { +TEST(YmlTreeTest, Map) { const string yaml_input = "map:\n\ one: 1\n\ @@ -115,7 +146,7 @@ TEST_F(YmlTreeTest, Map) { const string expected_output = XML_HEADER + "\n"; YmlTree tree; - EXPECT_TRUE(tree.ParseXmlString(yaml_input)); + EXPECT_TRUE(tree.ParseString(yaml_input)); EXPECT_TRUE(tree.GetRoot()); XMLTreeElement* root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; EXPECT_TRUE(root); @@ -125,7 +156,7 @@ TEST_F(YmlTreeTest, Map) { EXPECT_EQ(xmlContent, expected_output); tree.Clear(); - EXPECT_TRUE(tree.ParseXmlString(json_input)); + EXPECT_TRUE(tree.ParseString(json_input)); EXPECT_TRUE(tree.GetRoot()); root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; EXPECT_TRUE(root); @@ -138,7 +169,7 @@ TEST_F(YmlTreeTest, Map) { EXPECT_EQ(ymlContent, yaml_input); } -TEST_F(YmlTreeTest, Nested) { +TEST(YmlTreeTest, Nested) { const string yaml_input = "nested:\n\ one: 1\n\ @@ -160,7 +191,7 @@ TEST_F(YmlTreeTest, Nested) { \n"; YmlTree tree; - EXPECT_TRUE(tree.ParseXmlString(yaml_input)); + EXPECT_TRUE(tree.ParseString(yaml_input)); EXPECT_TRUE(tree.GetRoot()); XMLTreeElement* root = tree.GetRoot() ? tree.GetRoot()->GetFirstChild() : nullptr; EXPECT_TRUE(root); @@ -175,7 +206,7 @@ TEST_F(YmlTreeTest, Nested) { } -TEST_F(YmlTreeTest, ReadFileDefault) { +TEST_F(YmlTreeTestF, ReadFileDefault) { bool success = RteFsUtils::CopyBufferToFile(ymlIn, theYmlString, false); EXPECT_TRUE(success); diff --git a/tools/projmgr/include/ProjMgrYamlSchemaChecker.h b/tools/projmgr/include/ProjMgrYamlSchemaChecker.h index 995ec6358..cf9f815a1 100644 --- a/tools/projmgr/include/ProjMgrYamlSchemaChecker.h +++ b/tools/projmgr/include/ProjMgrYamlSchemaChecker.h @@ -14,42 +14,20 @@ */ class ProjMgrYamlSchemaChecker : public YmlSchemaChecker { public: - enum class FileType - { - DEFAULT = 0, - SOLUTION, - PROJECT, - LAYER, - BUILD, - BUILD_PACK, - BUILDIDX, - BUILDSET, - GENERATOR, - BUILDGEN, - BUILDGENIDX, - GENERATOR_IMPORT - }; - /** - * @brief class constructor - */ - ProjMgrYamlSchemaChecker(void); /** - * @brief class destructor + * @brief Validates a file against schema obtained by FindSchema() method + * @param fileName file to validate + * @return true if successful */ - ~ProjMgrYamlSchemaChecker(void); + bool Validate(const std::string& file) override; - /** - * @brief Validate file data with schemas - * @param input data to be validated - * @param type File type - * @return true if the validation pass otherwise false + /** + * @brief Finds schema for given file to validate + * @param fileName file to validate + * @return schema file name if found, empty string otherwise */ - bool Validate(const std::string& input, ProjMgrYamlSchemaChecker::FileType type); - -protected: - - bool GetSchemaFile(std::string& schemaFile, const ProjMgrYamlSchemaChecker::FileType& type); + std::string FindSchema(const std::string& file) const override; }; #endif // PROJMGRYAMLSCHEMACHECKER_H diff --git a/tools/projmgr/src/ProjMgrKernel.cpp b/tools/projmgr/src/ProjMgrKernel.cpp index a2458341b..e0844f4f9 100644 --- a/tools/projmgr/src/ProjMgrKernel.cpp +++ b/tools/projmgr/src/ProjMgrKernel.cpp @@ -12,6 +12,8 @@ #include "RteFsUtils.h" #include "RteKernel.h" +#include "CrossPlatformUtils.h" + #include using namespace std; @@ -30,6 +32,13 @@ ProjMgrKernel::ProjMgrKernel() : attributes.AddAttribute("name", ORIGINAL_FILENAME); attributes.AddAttribute("version", VERSION_STRING); SetToolInfo(attributes); + std::error_code ec; + string exePath = RteUtils::ExtractFilePath( CrossPlatformUtils::GetExecutablePath(ec), true); + if (!ec) { + string cmsisToolboxDir = RteFsUtils::MakePathCanonical(exePath + ".."); + SetCmsisToolboxDir(cmsisToolboxDir); + } + } ProjMgrKernel::~ProjMgrKernel() { diff --git a/tools/projmgr/src/ProjMgrYamlParser.cpp b/tools/projmgr/src/ProjMgrYamlParser.cpp index 7e9affc61..f64e5845d 100644 --- a/tools/projmgr/src/ProjMgrYamlParser.cpp +++ b/tools/projmgr/src/ProjMgrYamlParser.cpp @@ -28,8 +28,7 @@ bool ProjMgrYamlParser::ParseCdefault(const string& input, try { // Validate file schema if (checkSchema && - !ProjMgrYamlSchemaChecker().Validate( - input, ProjMgrYamlSchemaChecker::FileType::DEFAULT)) { + !ProjMgrYamlSchemaChecker().Validate(input)) { return false; } @@ -67,8 +66,7 @@ bool ProjMgrYamlParser::ParseCsolution(const string& input, try { // Validate file schema if (checkSchema && - !ProjMgrYamlSchemaChecker().Validate( - input, ProjMgrYamlSchemaChecker::FileType::SOLUTION)) { + !ProjMgrYamlSchemaChecker().Validate(input)) { return false; } @@ -118,8 +116,7 @@ bool ProjMgrYamlParser::ParseCbuildPack(const string& input, try { // Validate file schema if (checkSchema && - !ProjMgrYamlSchemaChecker().Validate( - input, ProjMgrYamlSchemaChecker::FileType::BUILD_PACK)) { + !ProjMgrYamlSchemaChecker().Validate(input)) { return false; } @@ -150,8 +147,7 @@ bool ProjMgrYamlParser::ParseCproject(const string& input, try { // Validate file schema if (checkSchema && - !ProjMgrYamlSchemaChecker().Validate( - input, ProjMgrYamlSchemaChecker::FileType::PROJECT)) { + !ProjMgrYamlSchemaChecker().Validate(input)) { return false; } @@ -216,16 +212,14 @@ bool ProjMgrYamlParser::ParseClayer(const string& input, ClayerItem clayer; try { // Validate file schema - const bool cgen = fs::path(input).stem().extension().generic_string() == ".cgen"; if (checkSchema) { - if (!ProjMgrYamlSchemaChecker().Validate(input, cgen ? - ProjMgrYamlSchemaChecker::FileType::GENERATOR_IMPORT : - ProjMgrYamlSchemaChecker::FileType::LAYER)) { + if (!ProjMgrYamlSchemaChecker().Validate(input)) { return false; } } const YAML::Node& root = YAML::LoadFile(input); + const bool cgen = fs::path(input).stem().extension().generic_string() == ".cgen"; if (!cgen && !ValidateClayer(input, root)) { return false; } @@ -271,8 +265,7 @@ bool ProjMgrYamlParser::ParseClayer(const string& input, bool ProjMgrYamlParser::ParseCbuildSet(const string& input, CbuildSetItem& cbuildSet, bool checkSchema) { // Validate file schema - if (!ProjMgrYamlSchemaChecker().Validate( - input, ProjMgrYamlSchemaChecker::FileType::BUILDSET)) { + if (!ProjMgrYamlSchemaChecker().Validate(input)) { return false; } @@ -306,8 +299,7 @@ bool ProjMgrYamlParser::ParseGlobalGenerator(const string& input, try { // Validate file schema - if (checkSchema && !ProjMgrYamlSchemaChecker().Validate( - input, ProjMgrYamlSchemaChecker::FileType::GENERATOR)) { + if (checkSchema && !ProjMgrYamlSchemaChecker().Validate(input)) { return false; } diff --git a/tools/projmgr/src/ProjMgrYamlSchemaChecker.cpp b/tools/projmgr/src/ProjMgrYamlSchemaChecker.cpp index c0ab084b0..0dc4ec44c 100644 --- a/tools/projmgr/src/ProjMgrYamlSchemaChecker.cpp +++ b/tools/projmgr/src/ProjMgrYamlSchemaChecker.cpp @@ -14,111 +14,46 @@ using namespace std; -ProjMgrYamlSchemaChecker::ProjMgrYamlSchemaChecker(void) { - // Reserved -} - -ProjMgrYamlSchemaChecker::~ProjMgrYamlSchemaChecker(void) { - // Reserved -} -bool ProjMgrYamlSchemaChecker::Validate(const string& input, - ProjMgrYamlSchemaChecker::FileType type) +bool ProjMgrYamlSchemaChecker::Validate(const std::string& file) { // Check if the input file exist - if (!RteFsUtils::Exists(input)) { - ProjMgrLogger::Error(input, " file doesn't exist"); + if (!RteFsUtils::Exists(file)) { + ProjMgrLogger::Error(file, " file doesn't exist"); return false; } - // Get schema file path - string schemaFile; - if(!GetSchemaFile(schemaFile, type)) { - ProjMgrLogger::Warn(input, "yaml schemas were not found, file cannot be validated"); + string schemaFile = FindSchema(file); + if(schemaFile.empty()) { + ProjMgrLogger::Warn(file, "yaml schemas were not found, file cannot be validated"); return true; } ClearErrors(); // Validate schema - bool result = ValidateFile(input, schemaFile); + bool result = ValidateFile(file, schemaFile); for (auto& err : GetErrors()) { ProjMgrLogger::Error(err.m_file, err.m_line, err.m_col, err.m_msg); } - - return result; + return result; } -bool ProjMgrYamlSchemaChecker::GetSchemaFile(string& schemaFile, const ProjMgrYamlSchemaChecker::FileType& type) { - schemaFile = RteUtils::EMPTY_STRING; - - // Get the schema file name - string schemaFileName; - switch (type) - { - case ProjMgrYamlSchemaChecker::FileType::DEFAULT: - schemaFileName = "cdefault.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::SOLUTION: - schemaFileName = "csolution.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::PROJECT: - schemaFileName = "cproject.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::LAYER: - schemaFileName = "clayer.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::BUILD: - schemaFileName = "cbuild.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::BUILDIDX: - schemaFileName = "cbuild-idx.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::BUILD_PACK: - schemaFileName = "cbuild-pack.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::BUILDSET: - schemaFileName = "cbuild-set.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::GENERATOR: - schemaFileName = "generator.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::BUILDGEN: - schemaFileName = "cbuild-gen.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::BUILDGENIDX: - schemaFileName = "cbuild-gen-idx.schema.json"; - break; - case ProjMgrYamlSchemaChecker::FileType::GENERATOR_IMPORT: - schemaFileName = "cgen.schema.json"; - break; - default: - ProjMgrLogger::Error("Unknown file type"); - return false; - } - +std::string ProjMgrYamlSchemaChecker::FindSchema(const std::string& file) const +{ // Get current exe path std::error_code ec; - string exePath = RteUtils::ExtractFilePath( - CrossPlatformUtils::GetExecutablePath(ec), true); + string exePath = RteUtils::ExtractFilePath( CrossPlatformUtils::GetExecutablePath(ec), true); if (ec) { ProjMgrLogger::Error(ec.message()); - return false; + return RteUtils::EMPTY_STRING; } - - // Search schema in priority order - vector relSearchOrder = { "./", "../etc/", "../../etc/" }; - string schemaFilePath; - for (auto& relPath : relSearchOrder) { - schemaFilePath = exePath + relPath + schemaFileName; - if (RteFsUtils::Exists(schemaFilePath)) { - schemaFile = fs::canonical(schemaFilePath, ec).generic_string(); - if (ec) { - ProjMgrLogger::Error(ec.message()); - return false; - } - return true; - } + string baseFileName = RteUtils::ExtractFileBaseName(file); // remove .yml + string schemaFileName = RteUtils::ExtractFileExtension(baseFileName); // remove prefix + if(schemaFileName.empty()) { // cdefault.yml case + schemaFileName = baseFileName; } - return false; + schemaFileName += ".schema.json"; + return RteFsUtils::FindFileInEtc(schemaFileName, exePath); } + // end of ProjMgrYamlSchemaChecker diff --git a/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp b/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp index fee3684e6..fe6618e70 100644 --- a/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp @@ -26,14 +26,14 @@ class ProjMgrSchemaCheckerUnitTests : TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Pass) { const string& filename = testinput_folder + "/TestProject/test.cproject.yml"; - EXPECT_TRUE(Validate(filename, FileType::PROJECT)); + EXPECT_TRUE(Validate(filename)); EXPECT_TRUE(GetErrors().empty()); } TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Empty_Object) { const string& filename = testinput_folder + "/TestProject/test_empty_object.cproject.yml"; - EXPECT_TRUE(Validate(filename, FileType::PROJECT)); + EXPECT_TRUE(Validate(filename)); EXPECT_TRUE(GetErrors().empty()); } @@ -45,7 +45,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Fail) { const string& filename = testinput_folder + "/TestProject/test_schema_validation_failed.cproject.yml"; - EXPECT_FALSE(Validate(filename, FileType::PROJECT)); + EXPECT_FALSE(Validate(filename)); // Check errors auto errList = GetErrors(); @@ -60,7 +60,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Fail) { } TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Yaml_File_Not_Found) { - EXPECT_FALSE(Validate("UNKNOWN.yml", FileType::PROJECT)); + EXPECT_FALSE(Validate("UNKNOWN.yml")); } TEST_F(ProjMgrSchemaCheckerUnitTests, Schema_Not_Available) { @@ -72,7 +72,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, Schema_Not_Available) { StdStreamRedirect streamRedirect; const string& expected = "yaml schemas were not found, file cannot be validated"; const string& filename = testinput_folder + "/TestProject/test.cproject.yml"; - EXPECT_TRUE(Validate(filename, FileType::PROJECT)); + EXPECT_TRUE(Validate(filename)); auto outStr = streamRedirect.GetOutString(); EXPECT_NE(0, outStr.find(expected)); @@ -90,7 +90,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, Schema_Search_Path_1) { // Test schema check StdStreamRedirect streamRedirect; const string& filename = testinput_folder + "/TestProject/test.cproject.yml"; - EXPECT_TRUE(Validate(filename, FileType::PROJECT)); + EXPECT_TRUE(Validate(filename)); EXPECT_EQ(GetErrors().size(), 0); // restoring schema file @@ -108,7 +108,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, Schema_Search_Path_2) { // Test schema check StdStreamRedirect streamRedirect; const string& filename = testinput_folder + "/TestProject/test.cproject.yml"; - EXPECT_TRUE(Validate(filename, FileType::PROJECT)); + EXPECT_TRUE(Validate(filename)); EXPECT_EQ(GetErrors().size(), 0); // restoring schema file @@ -120,7 +120,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, Schema_Search_Path_2) { TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Pack_Selection) { const string& filename = testinput_folder + "/TestSolution/test_pack_selection.csolution.yml"; - EXPECT_TRUE(Validate(filename, FileType::SOLUTION)); + EXPECT_TRUE(Validate(filename)); EXPECT_TRUE(GetErrors().empty()); } @@ -230,10 +230,10 @@ vector expectedErrPos = { }; const string& filename = testoutput_folder + - "/test.csolution_schema_validation.yml"; + "/test_schema_validation.csolution.yml"; for (auto [data, expectRetVal, errorPos] : vecTestData) { writeFile(filename, data); - EXPECT_EQ(expectRetVal, Validate(filename, FileType::SOLUTION)) << "failed for: " << data; + EXPECT_EQ(expectRetVal, Validate(filename)) << "failed for: " << data; // Check errors auto errList = GetErrors(); @@ -258,7 +258,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_define) { const string& filename = testinput_folder + "/TestSolution/test_validate_define_syntax.csolution.yml"; - EXPECT_FALSE(Validate(filename, FileType::SOLUTION)); + EXPECT_FALSE(Validate(filename)); // Check errors auto errList = GetErrors(); @@ -279,7 +279,7 @@ TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Output_Type) { { 6 , 7 } }; const string& filename = testinput_folder + "/TestProject/incomplete_output_type.cproject.yml"; - EXPECT_FALSE(Validate(filename, FileType::PROJECT)); + EXPECT_FALSE(Validate(filename)); // Check errors auto errList = GetErrors(); diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index c8979f175..56e56df4e 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -585,18 +585,12 @@ TEST_F(ProjMgrUnitTests, RunProjMgrSolution) { testinput_folder + "/TestSolution/ref/cbuild/test2.Debug+CM3.cbuild.yml"); // Check schema - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test.cbuild-idx.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDIDX)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test1.Debug+CM0.cbuild.yml", - ProjMgrYamlSchemaChecker::FileType::BUILD)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test1.Release+CM0.cbuild.yml", - ProjMgrYamlSchemaChecker::FileType::BUILD)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test1.Debug+CM0.cbuild.yml", - ProjMgrYamlSchemaChecker::FileType::BUILD)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test2.Debug+CM0.cbuild.yml", - ProjMgrYamlSchemaChecker::FileType::BUILD)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test2.Debug+CM3.cbuild.yml", - ProjMgrYamlSchemaChecker::FileType::BUILD)); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test.cbuild-idx.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test1.Debug+CM0.cbuild.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test1.Release+CM0.cbuild.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test1.Debug+CM0.cbuild.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test2.Debug+CM0.cbuild.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test2.Debug+CM3.cbuild.yml")); // Check generated cbuild-pack file ProjMgrTestEnv::CompareFile(testinput_folder + "/TestSolution/test.cbuild-pack.yml", @@ -1998,7 +1992,7 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_Generator) { testinput_folder + "/TestGenerator/ref/test-gpdsc.Debug+CM0.cbuild.yml"); // Check cbuild.yml schema - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test-gpdsc.Debug+CM0.cbuild.yml", ProjMgrYamlSchemaChecker::FileType::BUILD)); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testoutput_folder + "/test-gpdsc.Debug+CM0.cbuild.yml")); } TEST_F(ProjMgrUnitTests, RunProjMgr_GeneratorLayer) { @@ -4652,12 +4646,9 @@ TEST_F(ProjMgrUnitTests, ExternalGenerator) { argv[6] = (char*)"core0.Debug+MultiCore"; EXPECT_EQ(0, RunProjMgr(7, argv, 0)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/core0/MultiCore/Debug/extgen.cbuild-gen-idx.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGENIDX)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/core0/MultiCore/Debug/core0.Debug+MultiCore.cbuild-gen.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGEN)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/core1/MultiCore/Debug/core1.Debug+MultiCore.cbuild-gen.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGEN)); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/core0/MultiCore/Debug/extgen.cbuild-gen-idx.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/core0/MultiCore/Debug/core0.Debug+MultiCore.cbuild-gen.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/core1/MultiCore/Debug/core1.Debug+MultiCore.cbuild-gen.yml")); auto stripAbsoluteFunc = [](const std::string& in) { std::string str = in; @@ -4677,10 +4668,8 @@ TEST_F(ProjMgrUnitTests, ExternalGenerator) { argv[6] = (char*)"single-core.Debug+CM0"; EXPECT_EQ(0, RunProjMgr(7, argv, 0)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/single-core/CM0/Debug/extgen.cbuild-gen-idx.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGENIDX)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/single-core/CM0/Debug/single-core.Debug+CM0.cbuild-gen.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGEN)); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/single-core/CM0/Debug/extgen.cbuild-gen-idx.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/single-core/CM0/Debug/single-core.Debug+CM0.cbuild-gen.yml")); ProjMgrTestEnv::CompareFile(testinput_folder + "/ExternalGenerator/ref/SingleCore/extgen.cbuild-gen-idx.yml", testinput_folder + "/ExternalGenerator/tmp/single-core/CM0/Debug/extgen.cbuild-gen-idx.yml", stripAbsoluteFunc); @@ -4691,12 +4680,9 @@ TEST_F(ProjMgrUnitTests, ExternalGenerator) { argv[6] = (char*)"ns.Debug+CM0"; EXPECT_EQ(0, RunProjMgr(7, argv, 0)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/ns/CM0/Debug/extgen.cbuild-gen-idx.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGENIDX)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/ns/CM0/Debug/ns.Debug+CM0.cbuild-gen.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGEN)); - EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/s/CM0/Debug/s.Debug+CM0.cbuild-gen.yml", - ProjMgrYamlSchemaChecker::FileType::BUILDGEN)); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/ns/CM0/Debug/extgen.cbuild-gen-idx.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/ns/CM0/Debug/ns.Debug+CM0.cbuild-gen.yml")); + EXPECT_TRUE(ProjMgrYamlSchemaChecker().Validate(testinput_folder + "/ExternalGenerator/tmp/s/CM0/Debug/s.Debug+CM0.cbuild-gen.yml")); ProjMgrTestEnv::CompareFile(testinput_folder + "/ExternalGenerator/ref/TrustZone/extgen.cbuild-gen-idx.yml", testinput_folder + "/ExternalGenerator/tmp/ns/CM0/Debug/extgen.cbuild-gen-idx.yml", stripAbsoluteFunc);