Skip to content

Commit 824848d

Browse files
Extracting GetTargetPath
1 parent b78fb00 commit 824848d

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

Include/runcpp2/runcpp2.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ namespace runcpp2
134134
const std::string& buildOutputDir,
135135
const std::unordered_map<CmdOptions, std::string>& currentOptions);
136136

137+
PipelineResult GetTargetPath( const ghc::filesystem::path& buildDir,
138+
const std::string& scriptName,
139+
const Data::Profile& profile,
140+
const std::unordered_map<CmdOptions, std::string>& currentOptions,
141+
ghc::filesystem::path& outTarget);
142+
137143
PipelineResult StartPipeline( const std::string& scriptPath,
138144
const std::vector<Data::Profile>& profiles,
139145
const std::string& configPreferredProfile,

Src/runcpp2/runcpp2.cpp

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,50 @@ runcpp2::HandleBuildOutput( const ghc::filesystem::path& target,
11751175
return PipelineResult::SUCCESS;
11761176
}
11771177

1178+
runcpp2::PipelineResult
1179+
runcpp2::GetTargetPath( const ghc::filesystem::path& buildDir,
1180+
const std::string& scriptName,
1181+
const Data::Profile& profile,
1182+
const std::unordered_map<CmdOptions, std::string>& currentOptions,
1183+
ghc::filesystem::path& outTarget)
1184+
{
1185+
std::string exeExt = "";
1186+
#ifdef _WIN32
1187+
exeExt = ".exe";
1188+
#endif
1189+
1190+
std::error_code _;
1191+
outTarget = buildDir;
1192+
1193+
const std::string* targetSharedLibExt =
1194+
runcpp2::GetValueFromPlatformMap(profile.FilesTypes.SharedLibraryFile.Extension);
1195+
1196+
const std::string* targetSharedLibPrefix =
1197+
runcpp2::GetValueFromPlatformMap(profile.FilesTypes.SharedLibraryFile.Prefix);
1198+
1199+
if(currentOptions.find(CmdOptions::EXECUTABLE) != currentOptions.end())
1200+
outTarget = (outTarget / scriptName).concat(exeExt);
1201+
else
1202+
{
1203+
if(targetSharedLibExt == nullptr || targetSharedLibPrefix == nullptr)
1204+
{
1205+
ssLOG_ERROR("Shared library extension or prefix not found in compiler profile");
1206+
return PipelineResult::INVALID_PROFILE;
1207+
}
1208+
1209+
outTarget = (outTarget / *targetSharedLibPrefix).concat(scriptName)
1210+
.concat(*targetSharedLibExt);
1211+
}
1212+
1213+
if(!ghc::filesystem::exists(outTarget, _))
1214+
{
1215+
ssLOG_ERROR("Failed to find the compiled file: " << outTarget.string());
1216+
return PipelineResult::COMPILE_LINK_FAILED;
1217+
}
1218+
1219+
return PipelineResult::SUCCESS;
1220+
}
1221+
11781222
runcpp2::PipelineResult
11791223
runcpp2::StartPipeline( const std::string& scriptPath,
11801224
const std::vector<Data::Profile>& profiles,
@@ -1418,43 +1462,15 @@ runcpp2::StartPipeline( const std::string& scriptPath,
14181462

14191463
//Run the compiled file at script directory
14201464
{
1421-
std::string exeExt = "";
1422-
#ifdef _WIN32
1423-
exeExt = ".exe";
1424-
#endif
1425-
1426-
std::error_code _;
1427-
ghc::filesystem::path target = buildDir;
1428-
1429-
const std::string* targetSharedLibExt =
1430-
runcpp2::GetValueFromPlatformMap(profiles.at(profileIndex) .FilesTypes
1431-
.SharedLibraryFile
1432-
.Extension);
1433-
1434-
const std::string* targetSharedLibPrefix =
1435-
runcpp2::GetValueFromPlatformMap(profiles.at(profileIndex) .FilesTypes
1436-
.SharedLibraryFile
1437-
.Prefix);
1438-
1439-
if(currentOptions.find(CmdOptions::EXECUTABLE) != currentOptions.end())
1440-
target = (target / scriptName).concat(exeExt);
1441-
else
1442-
{
1443-
if(targetSharedLibExt == nullptr || targetSharedLibPrefix == nullptr)
1444-
{
1445-
ssLOG_ERROR("Shared library extension or prefix not found in compiler profile");
1446-
return PipelineResult::INVALID_PROFILE;
1447-
}
1448-
1449-
target = (target / *targetSharedLibPrefix) .concat(scriptName)
1450-
.concat(*targetSharedLibExt);
1451-
}
1452-
1453-
if(!ghc::filesystem::exists(target, _))
1454-
{
1455-
ssLOG_ERROR("Failed to find the compiled file: " << target.string());
1456-
return PipelineResult::COMPILE_LINK_FAILED;
1457-
}
1465+
ghc::filesystem::path target;
1466+
result = GetTargetPath( buildDir,
1467+
scriptName,
1468+
profiles.at(profileIndex),
1469+
currentOptions,
1470+
target);
1471+
1472+
if(result != PipelineResult::SUCCESS)
1473+
return result;
14581474

14591475
if(currentOptions.count(CmdOptions::BUILD) == 0)
14601476
{

0 commit comments

Comments
 (0)