Skip to content

Commit 1018392

Browse files
Adding ExecutableShared option for profile...
Adding ExecutableShared option for profile, Fixing ConstructCommand not working for executable type
1 parent 03b8dfe commit 1018392

File tree

6 files changed

+257
-33
lines changed

6 files changed

+257
-33
lines changed

DefaultYAMLs/DefaultUserConfig.yaml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ Profiles:
172172
# (Optional) The commands to run in **shell** AFTER compiling
173173
# This is run inside the .runcpp2 directory where the build happens.
174174
# Cleanup: []
175+
ExecutableShared:
176+
DefaultPlatform:
177+
Flags: "-std=c++17 -Wall -g -fpic"
178+
Executable: "g++"
179+
RunParts: *g++_CompileRunParts
180+
# Setup: []
181+
# Cleanup: []
175182
Static:
176183
DefaultPlatform:
177184
Flags: "-std=c++17 -Wall -g"
@@ -227,14 +234,15 @@ Profiles:
227234
# {OutputFilePath}: (Similar to previous)
228235
LinkTypes:
229236
Executable:
230-
Unix:
237+
DefaultPlatform:
231238
Flags: "-Wl,-rpath,\\$ORIGIN"
232239
Executable: "g++"
233240
RunParts: *g++_LinkRunParts
234241
# Setup: []
235242
# Cleanup: []
236-
Windows:
237-
Flags: "-Wl,-rpath,\\$ORIGIN"
243+
ExecutableShared:
244+
DefaultPlatform:
245+
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
238246
Executable: "g++"
239247
RunParts: *g++_LinkRunParts
240248
# Setup: []
@@ -247,13 +255,7 @@ Profiles:
247255
# Setup: []
248256
# Cleanup: []
249257
Shared:
250-
Unix:
251-
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
252-
Executable: "g++"
253-
RunParts: *g++_LinkRunParts
254-
# Setup: []
255-
# Cleanup: []
256-
Windows:
258+
DefaultPlatform:
257259
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
258260
Executable: "g++"
259261
RunParts: *g++_LinkRunParts
@@ -286,6 +288,11 @@ Profiles:
286288
<<: *MSVC_CompileFlags
287289
Executable: "CL.exe"
288290
RunParts: *vs2022_v17+_CompileRunParts
291+
ExecutableShared:
292+
Windows:
293+
<<: *MSVC_CompileFlags
294+
Executable: "CL.exe"
295+
RunParts: *vs2022_v17+_CompileRunParts
289296
Static:
290297
Windows:
291298
<<: *MSVC_CompileFlags
@@ -296,7 +303,6 @@ Profiles:
296303
<<: *MSVC_CompileFlags
297304
Executable: "CL.exe"
298305
RunParts: *vs2022_v17+_CompileRunParts
299-
# Specify the linker settings
300306
Linker:
301307
PreRun:
302308
Windows: ".\\prerun.bat"
@@ -310,12 +316,7 @@ Profiles:
310316
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /manifest:embed /SUBSYSTEM:CONSOLE
311317
Executable: "link.exe"
312318
RunParts: *vs2022_v17+_LinkRunParts
313-
Static:
314-
Windows:
315-
Flags: "/NOLOGO"
316-
Executable: "lib.exe"
317-
RunParts: *vs2022_v17+_LinkRunParts
318-
Shared:
319+
ExecutableShared:
319320
Windows:
320321
Flags: >-
321322
/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
@@ -329,3 +330,17 @@ Profiles:
329330
CommandPart: " \"{LinkFilePath}\""
330331
Setup: [ "echo EXPORTS > .\\temp.def", "echo. main @1 >> .\\temp.def" ]
331332
Cleanup: [ "del .\\temp.def" ]
333+
Static:
334+
Windows:
335+
Flags: "/NOLOGO"
336+
Executable: "lib.exe"
337+
RunParts: *vs2022_v17+_LinkRunParts
338+
Shared:
339+
Windows:
340+
Flags: >-
341+
/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib
342+
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /manifest:embed /SUBSYSTEM:CONSOLE
343+
/DLL
344+
Executable: "link.exe"
345+
RunParts: *vs2022_v17+_LinkRunParts
346+

Include/runcpp2/Data/StageInfo.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace runcpp2
4545
struct
4646
{
4747
std::unordered_map<PlatformName, OutputTypeInfo> Executable;
48+
std::unordered_map<PlatformName, OutputTypeInfo> ExecutableShared;
4849
std::unordered_map<PlatformName, OutputTypeInfo> Static;
4950
std::unordered_map<PlatformName, OutputTypeInfo> Shared;
5051
} OutputTypes;

Src/Tests/Data/ProfileTest.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ int main(int argc, char** argv)
6969
CommandPart: " -I\"{IncludeDirectoryPath}\""
7070
- Type: Once
7171
CommandPart: " \"{InputFilePath}\" -o \"{OutputFilePath}\""
72+
ExecutableShared:
73+
DefaultPlatform:
74+
Flags: "-std=c++17 -Wall -g -fpic"
75+
Executable: "g++"
76+
RunParts:
77+
- Type: Once
78+
CommandPart: "{Executable} -c {CompileFlags}"
79+
- Type: Repeats
80+
CommandPart: " -I\"{IncludeDirectoryPath}\""
81+
- Type: Once
82+
CommandPart: " \"{InputFilePath}\" -o \"{OutputFilePath}\""
7283
Static:
7384
DefaultPlatform:
7485
Flags: "-std=c++17 -Wall -g"
@@ -116,6 +127,13 @@ int main(int argc, char** argv)
116127
RunParts:
117128
- Type: Once
118129
CommandPart: "{Executable} {LinkFlags} -o \"{OutputFilePath}\""
130+
ExecutableShared:
131+
Unix:
132+
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
133+
Executable: "g++"
134+
RunParts:
135+
- Type: Once
136+
CommandPart: "{Executable} {LinkFlags} -o \"{OutputFilePath}\""
119137
)";
120138

121139
ssTEST_OUTPUT_SETUP
@@ -196,6 +214,22 @@ int main(int argc, char** argv)
196214
ssTEST_OUTPUT_ASSERT( "Compiler Executable RunParts size",
197215
executableCompile.RunParts.size() == 3);
198216

217+
//Verify Compiler ExecutableShared
218+
ssTEST_OUTPUT_SETUP
219+
(
220+
const auto& executableSharedCompile =
221+
profile.Compiler.OutputTypes.ExecutableShared.at("DefaultPlatform");
222+
);
223+
ssTEST_OUTPUT_ASSERT( "Compiler ExecutableShared flags",
224+
executableSharedCompile.Flags,
225+
"-std=c++17 -Wall -g -fpic");
226+
ssTEST_OUTPUT_ASSERT( "Compiler ExecutableShared executable",
227+
executableSharedCompile.Executable,
228+
"g++");
229+
ssTEST_OUTPUT_ASSERT( "Compiler ExecutableShared RunParts size",
230+
executableSharedCompile.RunParts.size(),
231+
3);
232+
199233
//Verify Linker
200234
ssTEST_OUTPUT_ASSERT( "Linker CheckExistence DefaultPlatform",
201235
profile.Linker.CheckExistence.at("DefaultPlatform") == "g++ -v");
@@ -210,6 +244,22 @@ int main(int argc, char** argv)
210244
ssTEST_OUTPUT_ASSERT( "Linker Executable RunParts size",
211245
executableLink.RunParts.size() == 1);
212246

247+
//Verify Linker ExecutableShared
248+
ssTEST_OUTPUT_SETUP
249+
(
250+
const auto& executableSharedLink =
251+
profile.Linker.OutputTypes.ExecutableShared.at("Unix");
252+
);
253+
ssTEST_OUTPUT_ASSERT( "Linker ExecutableShared flags",
254+
executableSharedLink.Flags,
255+
"-shared -Wl,-rpath,\\$ORIGIN");
256+
ssTEST_OUTPUT_ASSERT( "Linker ExecutableShared executable",
257+
executableSharedLink.Executable,
258+
"g++");
259+
ssTEST_OUTPUT_ASSERT( "Linker ExecutableShared RunParts size",
260+
executableSharedLink.RunParts.size(),
261+
1);
262+
213263
//Test ToString() and Equals()
214264
ssTEST_OUTPUT_EXECUTION
215265
(

Src/Tests/Data/StageInfoTest.cpp

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ int main(int argc, char** argv)
2828
CommandPart: "{Executable} {LinkFlags} -o \"{OutputFilePath}\""
2929
- Type: Repeats
3030
CommandPart: " \"{LinkFilePath}\""
31+
ExecutableShared:
32+
Unix:
33+
Flags: "-shared -Wl,-rpath,\\$ORIGIN"
34+
Executable: "g++"
35+
RunParts:
36+
- Type: Once
37+
CommandPart: "{Executable} {LinkFlags} -o \"{OutputFilePath}\""
38+
- Type: Repeats
39+
CommandPart: " \"{LinkFilePath}\""
3140
Static:
3241
Unix:
3342
Flags: "-Wl,-rpath,\\$ORIGIN"
@@ -72,17 +81,38 @@ int main(int argc, char** argv)
7281
(
7382
const auto& unixInfo = stageInfo.OutputTypes.Executable.at("Unix");
7483
);
75-
ssTEST_OUTPUT_ASSERT("Unix flags", unixInfo.Flags == "-Wl,-rpath,\\$ORIGIN");
76-
ssTEST_OUTPUT_ASSERT("Unix executable", unixInfo.Executable == "g++");
77-
ssTEST_OUTPUT_ASSERT("Unix setup count", unixInfo.Setup.size() == 1);
78-
ssTEST_OUTPUT_ASSERT("Unix cleanup count", unixInfo.Cleanup.size() == 1);
79-
ssTEST_OUTPUT_ASSERT("Unix run parts count", unixInfo.RunParts.size() == 2);
80-
ssTEST_OUTPUT_ASSERT( "Unix first run type",
84+
ssTEST_OUTPUT_ASSERT("Unix Executable flags", unixInfo.Flags, "-Wl,-rpath,\\$ORIGIN");
85+
ssTEST_OUTPUT_ASSERT("Unix Executable executable", unixInfo.Executable, "g++");
86+
ssTEST_OUTPUT_ASSERT("Unix Executable setup count", unixInfo.Setup.size(), 1);
87+
ssTEST_OUTPUT_ASSERT("Unix Executable cleanup count", unixInfo.Cleanup.size(), 1);
88+
ssTEST_OUTPUT_ASSERT("Unix Executable run parts count", unixInfo.RunParts.size(), 2);
89+
ssTEST_OUTPUT_ASSERT( "Unix Executable first run type",
8190
unixInfo.RunParts.at(0).Type ==
8291
runcpp2::Data::StageInfo::RunPart::RunType::ONCE);
83-
ssTEST_OUTPUT_ASSERT( "Unix second run command",
92+
ssTEST_OUTPUT_ASSERT( "Unix Executable second run command",
8493
unixInfo.RunParts.at(1).CommandPart, " \"{LinkFilePath}\"");
8594

95+
//Verify Unix OutputTypeInfo for ExecutableShared
96+
ssTEST_OUTPUT_SETUP
97+
(
98+
const auto& unixExecSharedInfo = stageInfo.OutputTypes.ExecutableShared.at("Unix");
99+
);
100+
ssTEST_OUTPUT_ASSERT( "Unix ExecutableShared flags",
101+
unixExecSharedInfo.Flags,
102+
"-shared -Wl,-rpath,\\$ORIGIN");
103+
ssTEST_OUTPUT_ASSERT( "Unix ExecutableShared executable",
104+
unixExecSharedInfo.Executable,
105+
"g++");
106+
ssTEST_OUTPUT_ASSERT( "Unix ExecutableShared run parts count",
107+
unixExecSharedInfo.RunParts.size(),
108+
2);
109+
ssTEST_OUTPUT_ASSERT( "Unix ExecutableShared first run type",
110+
unixExecSharedInfo.RunParts.at(0).Type ==
111+
runcpp2::Data::StageInfo::RunPart::RunType::ONCE);
112+
ssTEST_OUTPUT_ASSERT( "Unix ExecutableShared second run command",
113+
unixExecSharedInfo.RunParts.at(1).CommandPart,
114+
" \"{LinkFilePath}\"");
115+
86116
//Test ToString() and Equals()
87117
ssTEST_OUTPUT_EXECUTION
88118
(
@@ -97,6 +127,66 @@ int main(int argc, char** argv)
97127
ssTEST_OUTPUT_ASSERT("Parsed output should equal original", stageInfo.Equals(parsedOutput));
98128
};
99129

130+
ssTEST("StageInfo Should Handle Malformed YAML")
131+
{
132+
const char* malformedYamlStr = R"(
133+
LinkTypes:
134+
ExecutableShared: # Missing required fields
135+
Unix:
136+
Flags: "-shared"
137+
# Missing Executable
138+
# Missing RunParts
139+
)";
140+
141+
ssTEST_OUTPUT_SETUP
142+
(
143+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(malformedYamlStr));
144+
ryml::ConstNodeRef root = tree.rootref();
145+
146+
runcpp2::Data::StageInfo stageInfo;
147+
);
148+
149+
ssTEST_OUTPUT_EXECUTION
150+
(
151+
ryml::ConstNodeRef nodeRef = root;
152+
bool parseResult = stageInfo.ParseYAML_Node(nodeRef, "LinkTypes");
153+
);
154+
155+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail for malformed YAML", !parseResult);
156+
};
157+
158+
ssTEST("StageInfo Should Handle Missing ExecutableShared")
159+
{
160+
const char* yamlStr = R"(
161+
LinkTypes:
162+
Executable:
163+
Unix:
164+
Flags: "-Wl,-rpath,\\$ORIGIN"
165+
Executable: "g++"
166+
RunParts:
167+
- Type: Once
168+
CommandPart: "{Executable} {LinkFlags}"
169+
# Missing ExecutableShared section
170+
)";
171+
172+
ssTEST_OUTPUT_SETUP
173+
(
174+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
175+
ryml::ConstNodeRef root = tree.rootref();
176+
177+
runcpp2::Data::StageInfo stageInfo;
178+
);
179+
180+
ssTEST_OUTPUT_EXECUTION
181+
(
182+
ryml::ConstNodeRef nodeRef = root;
183+
bool parseResult = stageInfo.ParseYAML_Node(nodeRef, "LinkTypes");
184+
);
185+
186+
ssTEST_OUTPUT_ASSERT( "ParseYAML_Node should fail for missing ExecutableShared",
187+
!parseResult);
188+
};
189+
100190
ssTEST_END_TEST_GROUP();
101191
return 0;
102192
}

Src/runcpp2/CompilingLinking.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,50 @@ namespace
8181

8282
outObjectsFilesPaths.clear();
8383

84-
const runcpp2::Data::StageInfo::OutputTypeInfo* currentOutputTypeInfo =
85-
compileAsExecutable ?
86-
runcpp2::GetValueFromPlatformMap(profile.Compiler.OutputTypes.Executable) :
87-
runcpp2::GetValueFromPlatformMap(profile.Compiler.OutputTypes.Shared);
84+
using OutputTypeInfo = runcpp2::Data::StageInfo::OutputTypeInfo;
85+
OutputTypeInfo* tempOutputInfo = nullptr;
86+
static_assert( static_cast<int>(runcpp2::Data::BuildType::COUNT) == 4,
87+
"Add new type to be processed");
88+
switch(scriptInfo.CurrentBuildType)
89+
{
90+
case runcpp2::Data::BuildType::STATIC:
91+
tempOutputInfo = const_cast<OutputTypeInfo*>
92+
(
93+
runcpp2::GetValueFromPlatformMap(profile.Compiler.OutputTypes.Static)
94+
);
95+
break;
96+
case runcpp2::Data::BuildType::SHARED:
97+
tempOutputInfo = const_cast<OutputTypeInfo*>
98+
(
99+
runcpp2::GetValueFromPlatformMap(profile.Compiler.OutputTypes.Shared)
100+
);
101+
break;
102+
case runcpp2::Data::BuildType::EXECUTABLE:
103+
if(compileAsExecutable)
104+
{
105+
tempOutputInfo = const_cast<OutputTypeInfo*>
106+
(
107+
runcpp2::GetValueFromPlatformMap(profile.Compiler.OutputTypes.Executable)
108+
);
109+
}
110+
else
111+
{
112+
113+
tempOutputInfo = const_cast<OutputTypeInfo*>
114+
(
115+
runcpp2::GetValueFromPlatformMap(profile.Compiler
116+
.OutputTypes
117+
.ExecutableShared)
118+
);
119+
}
120+
break;
121+
default:
122+
ssLOG_ERROR("Unsupported build type for compiling: " <<
123+
runcpp2::Data::BuildTypeToString(scriptInfo.CurrentBuildType));
124+
return false;
125+
}
126+
127+
const OutputTypeInfo* currentOutputTypeInfo = tempOutputInfo;
88128

89129
if(currentOutputTypeInfo == nullptr)
90130
{
@@ -336,10 +376,15 @@ namespace
336376
runcpp2::GetValueFromPlatformMap(profile.Linker.OutputTypes.Static);
337377
break;
338378
case runcpp2::Data::BuildType::SHARED:
339-
case runcpp2::Data::BuildType::EXECUTABLE:
340379
currentOutputTypeInfo =
341380
runcpp2::GetValueFromPlatformMap(profile.Linker.OutputTypes.Shared);
342381
break;
382+
case runcpp2::Data::BuildType::EXECUTABLE:
383+
currentOutputTypeInfo =
384+
runcpp2::GetValueFromPlatformMap(profile.Linker
385+
.OutputTypes
386+
.ExecutableShared);
387+
break;
343388
default:
344389
ssLOG_ERROR("Unsupported build type for linking: " <<
345390
runcpp2::Data::BuildTypeToString(scriptInfo.CurrentBuildType));

0 commit comments

Comments
 (0)