Skip to content

Commit a2292a0

Browse files
authored
[csolution] Handle cmd line option --active= (empty argument)
1 parent 527049f commit a2292a0

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

tools/projmgr/include/ProjMgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ProjMgr {
165165
std::string m_clayerSearchPath;
166166
std::string m_export;
167167
std::string m_selectedToolchain;
168-
std::string m_activeTargetSet;
168+
std::optional<std::string> m_activeTargetSet;
169169
bool m_checkSchema;
170170
bool m_missingPacks;
171171
bool m_updateRteFiles;

tools/projmgr/src/ProjMgr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ bool ProjMgr::PopulateContexts(void) {
549549
}
550550

551551
// Populate active target-set
552-
if (!m_activeTargetSet.empty() && !m_worker.PopulateActiveTargetSet(m_activeTargetSet)) {
552+
if (m_activeTargetSet.has_value() && !m_worker.PopulateActiveTargetSet(m_activeTargetSet.value())) {
553553
return false;
554554
}
555555

@@ -581,7 +581,7 @@ bool ProjMgr::GenerateYMLConfigurationFiles(bool previousResult) {
581581

582582
// Generate cbuild-run file
583583
if (previousResult && !m_processedContexts.empty() &&
584-
(m_contextSet || !m_activeTargetSet.empty())) {
584+
(m_contextSet || m_activeTargetSet.has_value())) {
585585
const auto& debugAdapters = GetDebugAdaptersFile();
586586
if (!debugAdapters.empty()) {
587587
if (!m_parser.ParseDebugAdapters(debugAdapters, m_checkSchema)) {

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5733,10 +5733,20 @@ bool ProjMgrWorker::ParseTargetSetContextSelection() {
57335733
}
57345734

57355735
bool ProjMgrWorker::PopulateActiveTargetSet(const string& activeTargetSet) {
5736+
const auto& targetTypes = m_parser->GetCsolution().targetTypes;
5737+
if (activeTargetSet.empty()) {
5738+
// cmd line option --active="" : take first target-type and first target-set
5739+
// target-type is mandatory, target-set is optional
5740+
m_activeTargetType = targetTypes.front().first;
5741+
if (!targetTypes.front().second.targetSet.empty()) {
5742+
m_activeTargetSet = targetTypes.front().second.targetSet.front();
5743+
}
5744+
return true;
5745+
}
57365746
const auto& targetType = RteUtils::GetPrefix(activeTargetSet, '@');
57375747
const auto& targetSet = RteUtils::GetSuffix(activeTargetSet, '@');
57385748
bool targetSetFound = false;
5739-
for (const auto& [name, type] : m_parser->GetCsolution().targetTypes) {
5749+
for (const auto& [name, type] : targetTypes) {
57405750
if (name == targetType) {
57415751
for (const auto& item : type.targetSet) {
57425752
if (item.set == targetSet) {

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7031,6 +7031,13 @@ TEST_F(ProjMgrUnitTests, ConvertActiveTargetSet) {
70317031
const YAML::Node& cbuildRun2 = YAML::LoadFile(testinput_folder + "/TestTargetSet/out/solution+Type1.cbuild-run.yml");
70327032
EXPECT_EQ("<default>", cbuildRun2["cbuild-run"]["target-set"].as<string>());
70337033

7034+
streamRedirect.ClearStringStreams();
7035+
argv[4] = (char*)"";
7036+
EXPECT_EQ(0, RunProjMgr(5, argv, 0));
7037+
const YAML::Node& cbuildRun3 = YAML::LoadFile(testinput_folder + "/TestTargetSet/out/solution+Type1.cbuild-run.yml");
7038+
EXPECT_EQ("Type1", cbuildRun3["cbuild-run"]["target-type"].as<string>());
7039+
EXPECT_EQ("<default>", cbuildRun3["cbuild-run"]["target-set"].as<string>());
7040+
70347041
streamRedirect.ClearStringStreams();
70357042
argv[4] = (char*)"Type1@Unknown";
70367043
EXPECT_EQ(1, RunProjMgr(5, argv, 0));

0 commit comments

Comments
 (0)