Skip to content

Commit 379ada7

Browse files
Merge pull request #58 from Neko-Box-Coder/SourceFilesRename
Renaming OtherFilesToBeCompiled to SourceFiles for yaml & misc changes
2 parents 898d5a6 + fce65e9 commit 379ada7

File tree

7 files changed

+96
-50
lines changed

7 files changed

+96
-50
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ OverrideLinkFlags:
6464
Append: ""
6565

6666
# (Optional) Other source files (relative to script file path) to be compiled.
67-
OtherFilesToBeCompiled:
67+
SourceFiles:
6868
# Target Platform
6969
DefaultPlatform:
7070
# Target Profile

Examples/InteractiveTutorial.cpp

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ bool Chapter2_BuildConfig()
565565

566566
DELAYED_OUTPUT("");
567567
DELAYED_OUTPUT("A common build config is to specify other source files.");
568-
DELAYED_OUTPUT("This can be done by adding the paths to the `OtherFilesToBeCompiled` field.");
568+
DELAYED_OUTPUT("This can be done by adding the paths to the `SourceFiles` field.");
569+
DELAYED_OUTPUT("The script file is implicitly added to this field so you don't need to specify it.");
569570
DELAYED_OUTPUT("Let me add a second C++ file (\"tutorial/Hello.cpp\").");
570571
DELAYED_OUTPUT("Press enter to continue...");
571572
GetInput(true);
@@ -596,33 +597,7 @@ void CallHello();
596597
WriteFile("tutorial/Hello.hpp", fileContent);
597598
}
598599

599-
DELAYED_OUTPUT("Turns out I still need to edit tutorial/main.cpp to call the function.");
600-
DELAYED_OUTPUT("Let me do that now.");
601-
DELAYED_OUTPUT("Press enter to continue...");
602-
GetInput(true);
603-
604-
{
605-
std::string fileContent = ReadFile("tutorial/main.cpp");
606-
if(fileContent.empty())
607-
{
608-
ssLOG_ERROR("Failed to read tutorial/main.cpp");
609-
return false;
610-
}
611-
612-
size_t returnPos = fileContent.find("return 0;");
613-
if(returnPos == std::string::npos)
614-
{
615-
ssLOG_ERROR("Failed to find return 0; in tutorial/main.cpp");
616-
return false;
617-
}
618-
fileContent.replace(returnPos,
619-
std::string("return 0;").size(),
620-
"CallHello();\n return 0;");
621-
622-
WriteFile("tutorial/main.cpp", std::string("#include \"Hello.hpp\"\n") + fileContent);
623-
}
624-
625-
DELAYED_OUTPUT("Now let me add the second C++ file to `OtherFilesToBeCompiled` in the YAML file.");
600+
DELAYED_OUTPUT("Now let me add the second C++ file to `SourceFiles` in the tutorial/main.yaml file.");
626601
DELAYED_OUTPUT("Press enter to continue...");
627602
GetInput(true);
628603

@@ -631,15 +606,15 @@ void CallHello();
631606
DefaultPlatform:
632607
DefaultProfile: ["WORLD=42"]
633608
634-
OtherFilesToBeCompiled:
609+
SourceFiles:
635610
DefaultPlatform:
636611
DefaultProfile: ["./Hello.cpp"]
637612
)";
638613

639614
WriteFile("tutorial/main.yaml", yamlContent);
640615
}
641616

642-
DELAYED_OUTPUT("The path to the other file is always **relative to the script file**.");
617+
DELAYED_OUTPUT("The paths to the files are always __relative to the script file__.");
643618
DELAYED_OUTPUT("You can also add include paths for the script to the `IncludePaths` field");
644619
DELAYED_OUTPUT("Although unnecessary in this case, let me add \"./\" to the include paths.");
645620
DELAYED_OUTPUT("Press enter to continue...");
@@ -650,7 +625,7 @@ void CallHello();
650625
DefaultPlatform:
651626
DefaultProfile: ["WORLD=42"]
652627
653-
OtherFilesToBeCompiled:
628+
SourceFiles:
654629
DefaultPlatform:
655630
DefaultProfile: ["./Hello.cpp"]
656631
@@ -662,23 +637,49 @@ void CallHello();
662637
WriteFile("tutorial/main.yaml", yamlContent);
663638
}
664639

640+
DELAYED_OUTPUT("Turns out, I still need to edit tutorial/main.cpp to call the function.");
641+
DELAYED_OUTPUT("Let me do that now.");
642+
DELAYED_OUTPUT("Press enter to continue...");
643+
GetInput(true);
644+
645+
{
646+
std::string fileContent = ReadFile("tutorial/main.cpp");
647+
if(fileContent.empty())
648+
{
649+
ssLOG_ERROR("Failed to read tutorial/main.cpp");
650+
return false;
651+
}
652+
653+
size_t returnPos = fileContent.find("return 0;");
654+
if(returnPos == std::string::npos)
655+
{
656+
ssLOG_ERROR("Failed to find return 0; in tutorial/main.cpp");
657+
return false;
658+
}
659+
fileContent.replace(returnPos,
660+
std::string("return 0;").size(),
661+
"CallHello();\n return 0;");
662+
663+
WriteFile("tutorial/main.cpp", std::string("#include \"Hello.hpp\"\n") + fileContent);
664+
}
665+
665666
DELAYED_OUTPUT("Let's run the script again.");
666667
if(!RunCommandWithPrompt("cd tutorial && " + runcpp2ExecutablePath + " main.cpp"))
667668
return false;
668669

669670
DELAYED_OUTPUT("You should see the output `Hello from another C++ file`.");
670671
DELAYED_OUTPUT("");
671672

672-
DELAYED_OUTPUT( "If you **only** have a setting that applies to all platforms and profiles like "
673+
DELAYED_OUTPUT( "If you **ONLY** have a setting that applies to all platforms and profiles like "
673674
"what we have,");
674675
DELAYED_OUTPUT("you can specify the settings directly.");
675-
DELAYED_OUTPUT("Let me update the YAML file and show you what I mean.");
676+
DELAYED_OUTPUT("Let me update the tutorial/main.yaml file and show you what I mean.");
676677
DELAYED_OUTPUT("Press enter to continue...");
677678
GetInput(true);
678679

679680
{
680681
const std::string yamlContent = R"(Defines: ["WORLD=42"]
681-
OtherFilesToBeCompiled: ["./Hello.cpp"]
682+
SourceFiles: ["./Hello.cpp"]
682683
IncludePaths: ["./"]
683684
)";
684685
WriteFile("tutorial/main.yaml", yamlContent);
@@ -700,7 +701,7 @@ IncludePaths: ["./"]
700701

701702
{
702703
const std::string yamlContent = R"(Defines: ["WORLD=42"]
703-
OtherFilesToBeCompiled: ["./Hello.cpp"]
704+
SourceFiles: ["./Hello.cpp"]
704705
IncludePaths: ["./"]
705706
706707
OverrideCompileFlags:
@@ -735,7 +736,7 @@ IncludePaths: ["./"]
735736

736737
{
737738
const std::string yamlContent = R"(Defines: ["WORLD=42"]
738-
OtherFilesToBeCompiled: ["./Hello.cpp"]
739+
SourceFiles: ["./Hello.cpp"]
739740
IncludePaths: ["./"]
740741
)";
741742
WriteFile("tutorial/main.yaml", yamlContent);
@@ -798,7 +799,7 @@ bool Chapter3_ExternalDependencies()
798799
DELAYED_OUTPUT("Press enter to continue...");
799800
GetInput(true);
800801

801-
DELAYED_OUTPUT("A dependency must contain a \"Source\" to determine where it is.");
802+
DELAYED_OUTPUT("A dependency must contain a \"Source\" to determine where it is from.");
802803
DELAYED_OUTPUT("In this case, it is coming from a \"Git\" repository.");
803804
DELAYED_OUTPUT( "If you have a git submodule, you can point it to a local directory with "
804805
"\"Local\" instead of \"Git\"");
@@ -807,7 +808,7 @@ bool Chapter3_ExternalDependencies()
807808

808809
DELAYED_OUTPUT( "Next, you have \"LibraryType\" which tells runcpp2 what type of dependency "
809810
"this is. Other options include \"Static\", \"Object\" and \"Shared\"");
810-
DELAYED_OUTPUT("That's pretty much it for a header only library. Let's run it shell we?");
811+
DELAYED_OUTPUT("That's pretty much it for a header only library. Let's run it shall we?");
811812
if(!RunCommandWithPrompt("cd tutorial && " + runcpp2ExecutablePath + " Logging.cpp"))
812813
return false;
813814

@@ -997,7 +998,7 @@ bool Chapter3_ExternalDependencies()
997998
return false;
998999
}
9991000

1000-
DELAYED_OUTPUT("I have extracted the SDL2 dependency block to a standalone YAML file.");
1001+
DELAYED_OUTPUT("I have extracted the SDL2 dependency block to tutorial/SDL2.yaml file.");
10011002
DELAYED_OUTPUT("Press enter to continue...");
10021003
GetInput(true);
10031004

Src/Tests/Data/ScriptInfoTest.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ int main(int argc, char** argv)
99

1010
ssTEST_INIT_TEST_GROUP();
1111

12+
ssTEST_PARSE_ARGS(argc, argv);
13+
1214
ssTEST("ScriptInfo Should Parse Valid YAML")
1315
{
1416
ssTEST_OUTPUT_SETUP
@@ -274,6 +276,41 @@ int main(int argc, char** argv)
274276
scriptInfo.Equals(parsedOutput));
275277
};
276278

279+
ssTEST("ScriptInfo Should Parse SourceFiles as OtherFilesToBeCompiled")
280+
{
281+
ssTEST_OUTPUT_SETUP
282+
(
283+
//NOTE: This is just a test YAML for validating parsing, don't use it for actual config
284+
const char* yamlStr = R"(
285+
SourceFiles:
286+
Windows:
287+
MSVC:
288+
- src/extra.cpp
289+
- src/debug.cpp
290+
)";
291+
292+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
293+
ryml::ConstNodeRef root = tree.rootref();
294+
runcpp2::Data::ScriptInfo scriptInfo;
295+
);
296+
297+
ssTEST_OUTPUT_EXECUTION
298+
(
299+
bool parseResult = scriptInfo.ParseYAML_Node(root);
300+
);
301+
302+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should succeed", parseResult);
303+
304+
//Verify SourceFiles
305+
ssTEST_OUTPUT_SETUP
306+
(
307+
const std::vector<ghc::filesystem::path>& msvcCompileFiles =
308+
scriptInfo.OtherFilesToBeCompiled.at("Windows").Paths.at("MSVC");
309+
);
310+
ssTEST_OUTPUT_ASSERT("MSVC files count", msvcCompileFiles.size() == 2);
311+
ssTEST_OUTPUT_ASSERT("MSVC first file", msvcCompileFiles.at(0) == "src/extra.cpp");
312+
};
313+
277314
ssTEST("ScriptInfo Should Parse Fields Without Platform And Profile As Default")
278315
{
279316
ssTEST_OUTPUT_SETUP

Src/runcpp2/Data/ScriptInfo.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ bool runcpp2::Data::ScriptInfo::ParseYAML_Node(ryml::ConstNodeRef node)
118118
return false;
119119
}
120120

121+
if(!ParsePlatformProfileMap<ProfilesProcessPaths>( node,
122+
"SourceFiles",
123+
OtherFilesToBeCompiled,
124+
"SourceFiles"))
125+
{
126+
return false;
127+
}
128+
121129
if(!ParsePlatformProfileMap<ProfilesProcessPaths>( node,
122130
"IncludePaths",
123131
IncludePaths,
@@ -213,7 +221,7 @@ std::string runcpp2::Data::ScriptInfo::ToString(std::string indentation) const
213221

214222
if(!OtherFilesToBeCompiled.empty())
215223
{
216-
out += indentation + "OtherFilesToBeCompiled:\n";
224+
out += indentation + "SourceFiles:\n";
217225
for(auto it = OtherFilesToBeCompiled.begin(); it != OtherFilesToBeCompiled.end(); ++it)
218226
{
219227
out += indentation + " " + it->first + ":\n";

mkdocs/docs/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Nightly
77
- Add version for default user config and prompt for update
8+
- Rename "OtherFilesToBeCompiled" to "SourceFiles"
89

910
### v0.3.1
1011
- Check last run is shared lib or executable. Reset cache when necessary if different type
@@ -35,7 +36,6 @@
3536

3637
## High Priority
3738

38-
- Rename "OtherFilesToBeCompiled" to "SourceFiles"
3939
- Expose/rename "InternalExecutableShared" and change BuildType to be platform map
4040
- This ties to the warning in `CompilingLinking.cpp:619`
4141
- Update `FileProperties.hpp` to use list of string for prefix and extension

mkdocs/docs/build_settings.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@
121121
Remove: "-flagA -flagB"
122122
Append: "-flagC -flagD"
123123
```
124-
### `OtherFilesToBeCompiled`
124+
### `SourceFiles`
125125
- Type: `Platform Profile Map` with `list` of `string`
126126
- Optional: `true`
127127
- Default: None
128-
- Description: The source files to be compiled for each platform and profile.
128+
- Description: The source files to be compiled for each platform and profile. The script file is added implicitly
129129
??? example
130130
```yaml
131-
OtherFilesToBeCompiled:
131+
SourceFiles:
132132
DefaultPlatform:
133133
DefaultProfile:
134134
- "./AnotherSourceFile.cpp"
@@ -532,7 +532,7 @@ OverrideLinkFlags:
532532
Append: ""
533533

534534
# (Optional) Other source files (relative to script file path) to be compiled.
535-
OtherFilesToBeCompiled:
535+
SourceFiles:
536536
# Target Platform
537537
DefaultPlatform:
538538
# Target Profile

mkdocs/docs/guides/building_project_sources.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Each setting supports two operations:
7272

7373
## Adding Source Files And Include Paths
7474

75-
You can add additional source files and include paths using `OtherFilesToBeCompiled` and `IncludePaths`.
75+
You can add additional source files and include paths using `SourceFiles` and `IncludePaths`.
7676
All paths are relative to the script file's location.
7777

7878
???+ example
@@ -88,7 +88,7 @@ All paths are relative to the script file's location.
8888
```
8989

9090
```yaml title="Build Settings"
91-
OtherFilesToBeCompiled:
91+
SourceFiles:
9292
- "./src/utils.cpp"
9393
- "./src/helper.cpp"
9494
IncludePaths:
@@ -98,7 +98,7 @@ All paths are relative to the script file's location.
9898
!!! note
9999
You can specify different source files for different platforms/profiles, same for IncludePaths:
100100
```yaml
101-
OtherFilesToBeCompiled:
101+
SourceFiles:
102102
Windows:
103103
"msvc":
104104
- "./src/windows_impl.cpp"
@@ -148,7 +148,7 @@ When building a project with a mixture of c and c++ files, the same profile will
148148
Language: "c"
149149
RequiredProfiles:
150150
DefaultPlatform: ["gcc"]
151-
OtherFilesToBeCompiled:
151+
SourceFiles:
152152
- "./math.c"
153153
IncludePaths:
154154
- "../include"

0 commit comments

Comments
 (0)