Skip to content

Commit

Permalink
[projmgr] Generate RTE directory in project tree (#1564)
Browse files Browse the repository at this point in the history
Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson authored Jun 17, 2024
1 parent 8ed0c78 commit 0f1bfe8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/rtefsutils/include/RteFsUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ class RteFsUtils
* @return absolute path of the current working directory
*/
static std::string GetCurrentFolder(bool withTrailingSlash = true);

/**
* @brief change current working directory to path
* @param path path to use as current working directory
*/
static void SetCurrentFolder(const std::string &path);

/**
* @brief determine first file owning the given extension in given folder
* @param folder name of path where first file with given extension is to be found
Expand Down
5 changes: 5 additions & 0 deletions libs/rtefsutils/src/RteFsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ string RteFsUtils::GetCurrentFolder(bool withTrailingSlash) {
return f;
}

void RteFsUtils::SetCurrentFolder(const string& path) {
error_code ec;
fs::current_path(path, ec);
}

bool RteFsUtils::MakeSureFilePath(const string &filePath) {
fs::path path(filePath);
path.remove_filename();
Expand Down
9 changes: 9 additions & 0 deletions tools/projmgr/test/src/ProjMgrTestEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ StdStreamRedirect::~StdStreamRedirect() {
std::cerr.rdbuf(m_stdcerrStreamBuf);
}

TempSwitchCwd::TempSwitchCwd(const string& path) {
m_oldPath = RteFsUtils::GetCurrentFolder();
RteFsUtils::SetCurrentFolder(path);
}

TempSwitchCwd::~TempSwitchCwd() {
RteFsUtils::SetCurrentFolder(m_oldPath);
}

void ProjMgrTestEnv::SetUp() {
error_code ec;
schema_folder = string(TEST_FOLDER) + "../schemas";
Expand Down
8 changes: 8 additions & 0 deletions tools/projmgr/test/src/ProjMgrTestEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class StdStreamRedirect {
std::streambuf* m_stdcerrStreamBuf;
};

class TempSwitchCwd {
public:
TempSwitchCwd(const std::string &path);
~TempSwitchCwd();
private:
std::string m_oldPath;
};

typedef std::string (*LineReplaceFunc_t)(const std::string&);

/**
Expand Down
34 changes: 34 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5798,3 +5798,37 @@ TEST_F(ProjMgrUnitTests, FailCreatedFor) {
auto errMsg = streamRedirect.GetErrorString();
EXPECT_NE(string::npos, errMsg.find(expectedErrMsg));
}

TEST_F(ProjMgrUnitTests, RunProjMgr_FailedConvertShouldCreateRteDirInProjectFolder) {
char* argv[4];
const string& app = testoutput_folder + "/app";
const string& csolution = app + "/app.csolution.yml";
const string& work = testoutput_folder + "/work";

ASSERT_TRUE(RteFsUtils::CreateDirectories(work));

ASSERT_TRUE(RteFsUtils::CreateTextFile(csolution, "# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/csolution.schema.json\n"
"solution:\n"
" build-types:\n"
" - type: debug\n"
" target-types:\n"
" - type: main\n"
" projects:\n"
" - project: test.cproject.yml\n"));

ASSERT_TRUE(RteFsUtils::CreateTextFile(app + "/test.cproject.yml", "# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/cproject.schema.json\n"
"project:\n"));

TempSwitchCwd cwdSwitcher(work);

ASSERT_FALSE(RteFsUtils::IsDirectory(work + "/RTE"));
ASSERT_FALSE(RteFsUtils::IsDirectory(app + "/RTE"));

argv[1] = (char*)"convert";
argv[2] = (char*)"--solution";
argv[3] = (char*)csolution.c_str();
EXPECT_EQ(1, RunProjMgr(4, argv, 0));

ASSERT_FALSE(RteFsUtils::IsDirectory(work + "/RTE"));
ASSERT_FALSE(RteFsUtils::IsDirectory(app + "/RTE"));
}

0 comments on commit 0f1bfe8

Please sign in to comment.