Skip to content

Commit 141b0a3

Browse files
Merge pull request #28 from Neko-Box-Coder/LocalConfig
Ability to specify local config
2 parents fd2fcb1 + f649e22 commit 141b0a3

File tree

12 files changed

+170
-36
lines changed

12 files changed

+170
-36
lines changed

Build.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pushd Build || goto :error
88

99
cmake .. || goto :error
1010
cmake --build . --target Embed2C || goto :error
11-
cmake .. %* || goto :error
12-
cmake --build . -j 16 || goto :error
11+
cmake .. -DssLOG_LEVEL=DEBUG "%*" || goto :error
12+
cmake --build . -j 16 --config Debug || goto :error
1313

1414
popd
1515

Build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pushd ./Build
66

77
cmake ..
88
cmake --build . --target Embed2C
9-
cmake .. "$@"
9+
cmake .. -DssLOG_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=Debug "$@"
1010
cmake --build . -j 16
1111

1212
popd

DefaultYAMLs/DefaultUserConfig.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# List of anchors that will be aliased later
22
Templates:
33
MSVC_CompileFlags: &MSVC_CompileFlags
4-
Flags: "/NOLOGO /W4 /diagnostics:caret /D NDEBUG /utf-8 /Gm- /MD /EHa /TP /std:c++17 /GR /TP"
4+
Flags: "/nologo /W4 /diagnostics:caret /D NDEBUG /utf-8 /Gm- /MD /EHa /TP /std:c++17 /GR /TP"
55

66
"g++_CompileRunParts": &g++_CompileRunParts
77
- Type: Once
@@ -135,8 +135,7 @@ Profiles:
135135

136136
# Specify the compiler settings
137137
Compiler:
138-
# (Optional) The command to run together before running each compile command
139-
# in **shell** for each platform
138+
# (Optional) The command to be prepend for each compile command in **shell** for each platform
140139
# PreRun:
141140
# Default: ""
142141

@@ -190,8 +189,7 @@ Profiles:
190189

191190
# Specify the linker settings
192191
Linker:
193-
# (Optional) The command to run together before running each link command
194-
# in **shell** for each platform
192+
# (Optional) The command to be prepend for each link command in **shell** for each platform
195193
# PreRun:
196194
# Default: ""
197195

@@ -268,9 +266,18 @@ Profiles:
268266
Languages: ["c++"]
269267
FileExtensions: [.cpp, .cc, .cxx]
270268
FilesTypes: *CommonFilesTypes
269+
Setup:
270+
Windows:
271+
- >-
272+
for /f "usebackq tokens=*" %i in (`CALL "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
273+
-version "[17.0,18.0)" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
274+
echo "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 > .\prerun.bat
275+
)
276+
Cleanup:
277+
Windows: [ "del .\\prerun.bat" ]
271278
Compiler:
272279
PreRun:
273-
Windows: "\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat\" x64"
280+
Windows: ".\\prerun.bat"
274281
CheckExistence:
275282
Windows: "where.exe CL.exe"
276283
CompileTypes:
@@ -292,7 +299,7 @@ Profiles:
292299
# Specify the linker settings
293300
Linker:
294301
PreRun:
295-
Windows: "\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat\" x64"
302+
Windows: ".\\prerun.bat"
296303
CheckExistence:
297304
Windows: "where.exe link.exe"
298305
LinkTypes:

Examples/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PassScriptPath: true
5555
Type: Git
5656
Value: "https://github.com/Neko-Box-Coder/System2.cpp.git"
5757
LibraryType: Header
58-
IncludePaths: ["./", "./External/System2"]
58+
IncludePaths: [".", "./External/System2"]
5959
Setup:
6060
Default:
6161
Default:

Include/runcpp2/ConfigParsing.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace runcpp2
1212
bool WriteDefaultConfig(const std::string& userConfigPath);
1313

1414
bool ReadUserConfig(std::vector<Data::Profile>& outProfiles,
15-
std::string& outPreferredProfile);
15+
std::string& outPreferredProfile,
16+
const std::string& customConfigPath = "");
1617

1718
bool ParseScriptInfo( const std::string& scriptInfo,
1819
Data::ScriptInfo& outScriptInfo);

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace runcpp2
2424
BUILD,
2525
VERSION,
2626
LOG_LEVEL,
27+
CONFIG_FILE,
2728
COUNT
2829
};
2930

Jenkinsfile

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,20 @@ pipeline
199199
bat 'dir'
200200
unstash 'source'
201201
bat 'dir'
202-
bat 'Build.bat -DRUNCPP2_BUILD_TESTS=ON'
202+
script
203+
{
204+
try
205+
{
206+
bat 'Build.bat -DRUNCPP2_BUILD_TESTS=ON'
207+
}
208+
catch(error)
209+
{
210+
echo "Build failed. Maybe .pdb is locked? Retrying..."
211+
sleep 5
212+
bat 'Build.bat -DRUNCPP2_BUILD_TESTS=ON'
213+
}
214+
}
215+
203216
stash 'windows_build'
204217
}
205218
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
@@ -213,7 +226,7 @@ pipeline
213226
{
214227
parallel
215228
{
216-
stage('Linux Test')
229+
stage('Linux Unit Test')
217230
{
218231
agent { label 'linux' }
219232
steps
@@ -228,7 +241,24 @@ pipeline
228241
}
229242
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
230243
}
231-
stage('Windows Test')
244+
stage('Linux Integration Test')
245+
{
246+
agent { label 'linux' }
247+
steps
248+
{
249+
cleanWs()
250+
bash "ls -lah"
251+
unstash 'linux_build'
252+
bash "ls -lah"
253+
bash "ls -lah ./Build/Src/Tests"
254+
bash "cd ./Build && ./runcpp2 -l " +
255+
"-c ../DefaultYAMLs/DefaultUserConfig.yaml " +
256+
"--log-level info ../Examples/test.cpp"
257+
}
258+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
259+
}
260+
261+
stage('Windows Unit Test')
232262
{
233263
agent { label 'windows' }
234264
steps
@@ -239,6 +269,22 @@ pipeline
239269
bat 'dir'
240270
bat 'dir .\\Build\\Src\\Tests\\Debug'
241271
bat 'cd .\\Build\\Src\\Tests && .\\RunAllTests.bat -d'
272+
273+
}
274+
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
275+
}
276+
stage('Windows Integration Test')
277+
{
278+
agent { label 'windows' }
279+
steps
280+
{
281+
cleanWs()
282+
bat 'dir'
283+
unstash 'windows_build'
284+
bat 'dir'
285+
bat "cd .\\Build\\Debug && .\\runcpp2.exe -l " +
286+
"-c ..\\..\\DefaultYAMLs\\DefaultUserConfig.yaml " +
287+
"--log-level info ..\\..\\Examples\\test.cpp"
242288
}
243289
post { failure { script { FAILED_STAGE = env.STAGE_NAME } } }
244290
}

Src/runcpp2/ConfigParsing.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,37 @@ bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath)
177177

178178

179179
bool runcpp2::ReadUserConfig( std::vector<Data::Profile>& outProfiles,
180-
std::string& outPreferredProfile)
180+
std::string& outPreferredProfile,
181+
const std::string& customConfigPath)
181182
{
182183
INTERNAL_RUNCPP2_SAFE_START();
183184

184185
ssLOG_FUNC_DEBUG();
185186

186-
std::string configPath = GetConfigFilePath();
187+
std::string configPath = !customConfigPath.empty() ? customConfigPath : GetConfigFilePath();
187188
if(configPath.empty())
188189
return false;
189190

190-
if(!ghc::filesystem::exists(configPath))
191+
std::error_code e;
192+
if(!ghc::filesystem::exists(configPath, e))
191193
{
194+
if(!customConfigPath.empty())
195+
{
196+
ssLOG_ERROR("Config file doesn't exist: " << configPath);
197+
return false;
198+
}
199+
192200
ssLOG_INFO("Config file doesn't exist. Creating one at: " << configPath);
193201
if(!WriteDefaultConfig(configPath))
194202
return false;
195203
}
196204

205+
if(ghc::filesystem::is_directory(configPath, e))
206+
{
207+
ssLOG_ERROR("Config file path is a directory: " << configPath);
208+
return false;
209+
}
210+
197211
//Read compiler profiles
198212
std::string userConfigContent;
199213
{

Src/runcpp2/Data/StageInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ namespace
155155
}
156156
}
157157

158+
//NOTE: This extracts substitutions and also allow escapes to happen for substitution characters.
159+
// To escape a substitution character, just repeat it. (i.e. {{text}} will be escaped as {text})
158160
void GetEscapedStringAndExtractSubstitutions( const std::string& processString,
159161
std::string& outEscapedString,
160162
std::vector<std::string>& outFoundSubstitutions,

Src/runcpp2/ProfileHelper.cpp

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,60 @@ namespace
77
{
88
bool IsProfileAvailableOnSystem(const runcpp2::Data::Profile& profile)
99
{
10+
if(!runcpp2::HasValueFromPlatformMap(profile.Compiler.CheckExistence))
11+
{
12+
ssLOG_INFO( "Compiler for profile " << profile.Name <<
13+
" does not have CheckExistence for current platform");
14+
return false;
15+
}
16+
17+
if(!runcpp2::HasValueFromPlatformMap(profile.Linker.CheckExistence))
18+
{
19+
ssLOG_INFO( "Linker for profile " << profile.Name <<
20+
" does not have CheckExistence for current platform");
21+
return false;
22+
}
23+
24+
//Global cleanup
25+
auto runCleanup = [&profile]() -> bool
26+
{
27+
if(runcpp2::HasValueFromPlatformMap(profile.Cleanup))
28+
{
29+
const std::vector<std::string>& cleanupSteps =
30+
*runcpp2::GetValueFromPlatformMap(profile.Cleanup);
31+
32+
for(int i = 0; i < cleanupSteps.size(); ++i)
33+
{
34+
std::string output;
35+
if(!runcpp2::RunCommandAndGetOutput(cleanupSteps.at(i), output))
36+
{
37+
ssLOG_INFO("Failed to run cleanup for " << profile.Name);
38+
return false;
39+
}
40+
}
41+
}
42+
43+
return true;
44+
};
45+
46+
//Global setup
47+
if(runcpp2::HasValueFromPlatformMap(profile.Setup))
48+
{
49+
const std::vector<std::string>& setupSteps =
50+
*runcpp2::GetValueFromPlatformMap(profile.Setup);
51+
52+
for(int i = 0; i < setupSteps.size(); ++i)
53+
{
54+
std::string output;
55+
if(!runcpp2::RunCommandAndGetOutput(setupSteps.at(i), output))
56+
{
57+
ssLOG_INFO("Failed to run setup for " << profile.Name);
58+
runCleanup();
59+
return false;
60+
}
61+
}
62+
}
63+
1064
//Check compiler
1165
{
1266
//Getting PreRun command
@@ -19,18 +73,13 @@ namespace
1973
command += " && ";
2074
}
2175

22-
if(!runcpp2::HasValueFromPlatformMap(profile.Compiler.CheckExistence))
23-
{
24-
ssLOG_INFO( "Compiler for profile " << profile.Name <<
25-
" does not have CheckExistence for current platform");
26-
return false;
27-
}
2876
command += *runcpp2::GetValueFromPlatformMap(profile.Compiler.CheckExistence);
2977

3078
std::string output;
3179
if(!runcpp2::RunCommandAndGetOutput(command, output))
3280
{
3381
ssLOG_INFO("Failed to find compiler for profile " << profile.Name);
82+
runCleanup();
3483
return false;
3584
}
3685
}
@@ -47,22 +96,20 @@ namespace
4796
command += " && ";
4897
}
4998

50-
if(!runcpp2::HasValueFromPlatformMap(profile.Linker.CheckExistence))
51-
{
52-
ssLOG_INFO( "Linker for profile " << profile.Name <<
53-
" does not have CheckExistence for current platform");
54-
return false;
55-
}
5699
command += *runcpp2::GetValueFromPlatformMap(profile.Linker.CheckExistence);
57100

58101
std::string output;
59102
if(!runcpp2::RunCommandAndGetOutput(command, output))
60103
{
61104
ssLOG_INFO("Failed to find linker for profile " << profile.Name);
105+
runCleanup();
62106
return false;
63107
}
64108
}
65109

110+
if(!runCleanup())
111+
return false;
112+
66113
return true;
67114
}
68115

0 commit comments

Comments
 (0)