Skip to content

Commit 80fcf10

Browse files
authored
VSCode as default for linux / msys2 (#422)
1 parent 73a60f5 commit 80fcf10

10 files changed

Lines changed: 68 additions & 78 deletions

File tree

commandLine/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,13 @@ int main(int argc, char** argv){
507507

508508
for (auto & t : targets) {
509509
ofLogNotice() << "-----------------------------------------------";
510+
ofLogNotice() << "target platform is: " << t;
510511
ofLogNotice() << "setting OF path to: " << ofPath;
511512
if(busingEnvVar){
512513
ofLogNotice() << "from PG_OF_PATH environment variable";
513514
}else{
514515
ofLogNotice() << "from -o option";
515516
}
516-
ofLogNotice() << "target platform is: " << t;
517517
ofLogNotice() << "project path is: " << projectPath;
518518
if(templateName != ""){
519519
ofLogNotice() << "using additional template " << templateName;

commandLine/src/projects/CBLinuxProject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "ofLog.h"
1111
#include "Utils.h"
1212

13-
std::string CBLinuxProject::LOG_NAME = "CBLinuxProject";
13+
std::string CBLinuxProject::LOG_NAME { "CBLinuxProject" };
1414

1515
bool CBLinuxProject::createProjectFile(){
1616
// FIXME: This only exists here, not other projects. I think it should be removed

commandLine/src/projects/VSCodeProject.cpp

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ struct fileJson {
1919

2020
// only works for workspace
2121
void addPath(fs::path folder) {
22-
json object;
2322
std::string path = folder.is_absolute() ? folder.string() : "${workspaceRoot}/../" + folder.string();
23+
json object;
2424
object["path"] = path;
2525
json::json_pointer p = json::json_pointer("/folders");
2626
data[p].emplace_back( object );
@@ -38,38 +38,29 @@ struct fileJson {
3838

3939
void load() {
4040
std::ifstream ifs(fileName);
41-
// this cause a bizarre issue. maybe it is reading after the end of the file
42-
// std::string contents = ofBufferFromFile(fileName).getData();
43-
// alert ("loading " + fileName.string(), 35);
4441
try {
4542
data = json::parse(ifs);
46-
// data = json::parse(contents);
4743
} catch (json::parse_error& ex) {
4844
ofLogError(VSCodeProject::LOG_NAME) << "JSON parse error at byte" << ex.byte;
4945
}
5046
}
5147

5248
void save() {
53-
alert ("saving now " + fileName.string(), 33);
54-
std::cout << data.dump(1, '\t') << std::endl;
55-
49+
// alert ("saving now " + fileName.string(), 33);
50+
// std::cout << data.dump(1, '\t') << std::endl;
5651
std::ofstream jsonFile(fileName);
5752
try {
5853
jsonFile << data.dump(1, '\t');
5954
} catch(std::exception & e) {
6055
ofLogError(VSCodeProject::LOG_NAME) << "Error saving json to " << fileName << ": " << e.what();
6156
}
62-
// catch(...) {
63-
// ofLogError(VSCodeProject::LOG_NAME) << "Error saving json to " << fileName;
64-
// }
6557
}
6658
};
6759

68-
6960
fileJson workspace;
7061
fileJson cppProperties;
71-
7262
std::string VSCodeProject::LOG_NAME = "VSCodeProject";
63+
7364
bool VSCodeProject::createProjectFile(){
7465
workspace.fileName = projectDir / (projectName + ".code-workspace");
7566
cppProperties.fileName = projectDir / ".vscode/c_cpp_properties.json";
@@ -101,13 +92,7 @@ bool VSCodeProject::loadProjectFile(){
10192

10293

10394
void VSCodeProject::addAddon(ofAddon & addon) {
104-
alert("VSCodeProject::addAddon() " + addon.name, 35);
105-
106-
// json object;
107-
// std::string path = addon.addonPath.is_absolute() ? addon.addonPath.string() : "${workspaceRoot}/../" + addon.addonPath.string();
108-
// object["path"] = path;
109-
// json::json_pointer p = json::json_pointer("/folders");
110-
// workspace.data[p].emplace_back( object );
95+
// alert("VSCodeProject::addAddon() " + addon.name, 35);
11196

11297
workspace.addPath(addon.addonPath);
11398
// examples of how to add entries to json arrays
@@ -118,33 +103,33 @@ void VSCodeProject::addAddon(ofAddon & addon) {
118103

119104

120105
bool VSCodeProject::saveProjectFile(){
121-
alert("VSCodeProject::saveProjectFile() ");
122-
123-
alert("--- VSCodeProject::extSrcPaths() ");
124-
// cout << extSrcPaths.size() << endl;
125-
for (auto & e : extSrcPaths) {
126-
cout << e << endl;
127-
workspace.addPath(e);
128-
129-
}
130-
alert("--- VSCodeProject::extSrcPaths() ");
106+
// alert("VSCodeProject::saveProjectFile() ");
107+
// alert("--- VSCodeProject::extSrcPaths() ");
108+
// for (auto & e : extSrcPaths) {
109+
// cout << e << endl;
110+
// workspace.addPath(e);
111+
//
112+
// }
113+
// alert("--- VSCodeProject::extSrcPaths() ");
131114

132115

116+
workspace.data["openFrameworksProjectGeneratorVersion"] = getPGVersion();
117+
133118
workspace.save();
134119
cppProperties.save();
135120
return true;
136121
}
137122

138123

139124
void VSCodeProject::addSrc(const fs::path & srcName, const fs::path & folder, SrcType type){
140-
alert ("addSrc " + srcName.string(), 33);
125+
// alert ("addSrc " + srcName.string(), 33);
141126
}
142127

143128
void VSCodeProject::addInclude(std::string includeName){
144-
alert ("addInclude " + includeName, 34);
129+
// alert ("addInclude " + includeName, 34);
145130
cppProperties.addToArray("/env/PROJECT_EXTRA_INCLUDES", fs::path(includeName));
146131
}
147132

148133
void VSCodeProject::addLibrary(const LibraryBinary & lib){
149-
alert ("addLibrary " + lib.path, 35);
134+
// alert ("addLibrary " + lib.path, 35);
150135
}

commandLine/src/projects/androidStudioProject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
#include "Utils.h"
55
#include <regex>
66

7-
using std::string;
87
std::string AndroidStudioProject::LOG_NAME = "AndroidStudioProject";
98

109
AndroidStudioProject::AndroidStudioProject(const std::string & target) : baseProject(target) {}
1110

1211
bool AndroidStudioProject::createProjectFile(){
1312
// Make sure project name doesn't include "-"
14-
std::string packageName = projectName;
13+
std::string packageName { projectName };
1514
ofStringReplace(packageName, "-", "");
1615

1716
if (!fs::exists(projectDir)) {
1817
fs::create_directory(projectDir);
1918
}
2019

21-
vector <string> fileNames = {
20+
std::vector <std::string> fileNames {
2221
"build.gradle",
2322
"settings.gradle",
2423
"AndroidManifest.xml",
@@ -33,7 +32,7 @@ bool AndroidStudioProject::createProjectFile(){
3332
fs::path from { templatePath / f };
3433
try {
3534
fs::copy(from, to);
36-
} catch(fs::filesystem_error& e) {
35+
} catch(fs::filesystem_error & e) {
3736
if (f == "AndroidManifest.xml") {
3837
findandreplaceInTexfile(to, "TEMPLATE_PACKAGE_NAME", packageName);
3938
} else {
@@ -49,8 +48,9 @@ bool AndroidStudioProject::createProjectFile(){
4948

5049
findandreplaceInTexfile( projectDir / "res/values/strings.xml", "TEMPLATE_APP_NAME", projectName);
5150

52-
fs::path from = projectDir / "srcJava/cc/openframeworks/APP_NAME";
53-
fs::path to = projectDir / ("srcJava/cc/openframeworks/"+projectName);
51+
fs::path from { projectDir / "srcJava/cc/openframeworks/APP_NAME" };
52+
fs::path to { projectDir / ("srcJava/cc/openframeworks/" + projectName) };
53+
// TODO: try catch
5454
fs::rename ( from, to );
5555
findandreplaceInTexfile(to / "OFActivity.java", "TEMPLATE_APP_NAME", projectName);
5656

commandLine/src/projects/baseProject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ bool baseProject::create(const fs::path & path, string templateName){
184184
vector < string > fileNames;
185185
getFilesRecursively(projectDir / "src", fileNames);
186186

187-
188187
std::sort (fileNames.begin(), fileNames.end());
189188

190189
// for (auto & f : fileNames) {

commandLine/src/projects/baseProject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#define PG_VERSION "23"
3+
#define PG_VERSION "25"
44

55
#include "ofAddon.h"
66
#include "ofFileUtils.h"

commandLine/src/projects/qtcreatorproject.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ bool QtCreatorProject::createProjectFile(){
1616

1717
fs::path qbsFile { fs::path { projectName + ".qbs" } };
1818
vector < std::pair <fs::path, fs::path > > fromTo {
19-
{ "qtcreator.qbs", qbsFile},
19+
{ "qtcreator.qbs", qbsFile },
2020
{ "Makefile", "Makefile" },
2121
{ "config.make", "config.make" },
2222
};
2323

2424
for (auto & p : fromTo) {
25-
fs::path src = templatePath / p.first;
26-
fs::path dst = projectDir / p.second;
25+
// FIXME: Wrong paths here. there are some more folders like "wizard" / "openFrameworks"
26+
fs::path src { templatePath / p.first };
27+
fs::path dst { projectDir / p.second };
2728
try {
2829
fs::copy_file(src, dst, fs::copy_options::overwrite_existing);
2930
} catch(fs::filesystem_error& e) {
30-
ofLogError(LOG_NAME) << "error copying template file " << p.first << " : " << p.second << e.what();
31+
ofLogError(LOG_NAME) << "error copying template file " << src << " : " << dst << " : " << e.what();
3132
return false;
3233
}
3334
}
@@ -36,7 +37,7 @@ bool QtCreatorProject::createProjectFile(){
3637
findandreplaceInTexfile(qbsFile, "emptyExample", projectName);
3738

3839
// Calculate OF Root in relation to each project (recursively);
39-
auto relRoot = fs::relative((fs::current_path() / getOFRoot()), projectDir);
40+
auto relRoot { fs::relative((fs::current_path() / getOFRoot()), projectDir) };
4041
if (!fs::equivalent(relRoot, "../../..")) {
4142
string root = relRoot.string();
4243
for (auto & p : fromTo) {
@@ -46,12 +47,13 @@ bool QtCreatorProject::createProjectFile(){
4647
return true;
4748
}
4849

50+
4951
void QtCreatorProject::addSrc(const fs::path & srcFile, const fs::path & folder, baseProject::SrcType type){
5052
qbsProjectFiles.insert(srcFile.string());
5153
}
5254

53-
bool QtCreatorProject::loadProjectFile(){
5455

56+
bool QtCreatorProject::loadProjectFile(){
5557
fs::path file { projectDir / (projectName + ".qbs") };
5658
if (!fs::exists(file)) {
5759
ofLogError(LOG_NAME) << "error loading" << file << "doesn't exist";
@@ -96,6 +98,7 @@ bool QtCreatorProject::loadProjectFile(){
9698
return ret;
9799
}
98100

101+
99102
bool QtCreatorProject::saveProjectFile(){
100103
auto qbsStr = qbs.getText();
101104

@@ -143,6 +146,7 @@ bool QtCreatorProject::saveProjectFile(){
143146
return true;
144147
}
145148

149+
146150
void QtCreatorProject::addAddon(ofAddon & addon){
147151
// FIXME: I think this is unneded since this function here is triggered by baseclass::addAddon(string) which already checked if exists.
148152
// for (auto & a : addons) {

commandLine/src/projects/visualStudioProject.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ bool visualStudioProject::createProjectFile(){
1111
// alert("visualStudioProject::createProjectFile");
1212

1313
solution = projectDir / (projectName + ".sln");
14-
fs::path project = projectDir / (projectName + ".vcxproj");
15-
fs::path user = projectDir / (projectName + ".vcxproj.user");
16-
fs::path filters = projectDir / (projectName + ".vcxproj.filters");
14+
fs::path project { projectDir / (projectName + ".vcxproj") };
15+
fs::path user { projectDir / (projectName + ".vcxproj.user") };
16+
fs::path filters { projectDir / (projectName + ".vcxproj.filters") };
1717

1818
fs::copy(templatePath / "emptyExample.vcxproj", project, fs::copy_options::overwrite_existing);
1919
fs::copy(templatePath / "emptyExample.vcxproj.user", user, fs::copy_options::overwrite_existing);
@@ -35,8 +35,8 @@ bool visualStudioProject::createProjectFile(){
3535

3636

3737
if (!fs::equivalent(getOFRoot(), fs::path{ "../../.." })) {
38-
string root = getOFRoot().string() ;
39-
string relRootWindows = convertStringToWindowsSeparator(root) + "\\";
38+
string root { getOFRoot().string() };
39+
string relRootWindows { convertStringToWindowsSeparator(root) + "\\" };
4040

4141
// sln has windows paths:
4242
// alert ("replacing root with " + relRootWindows, 36);
@@ -59,8 +59,8 @@ bool visualStudioProject::loadProjectFile(){
5959
ofLogError(LOG_NAME) << "error loading " << projectPath << " doesn't exist";
6060
return false;
6161
}
62-
pugi::xml_parse_result result = doc.load_file(projectPath.c_str());
63-
bLoaded = result.status==pugi::status_ok;
62+
pugi::xml_parse_result result { doc.load_file(projectPath.c_str()) };
63+
bLoaded = result.status == pugi::status_ok;
6464
// alert ("visualStudioProject::loadProjectFile() " + projectPath.string() + " : " + ofToString(bLoaded));
6565
return bLoaded;
6666
}
@@ -75,10 +75,10 @@ bool visualStudioProject::saveProjectFile(){
7575
add one entry for each additional, fixing slashes, generating new uuid.
7676
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}"
7777
EndProject
78-
*/
78+
*/
7979
if (!additionalvcxproj.empty()) {
8080
string additionalProjects;
81-
// string divider = "\r\n";
81+
// string divider = "\r\n";
8282
string divider = "\n";
8383
for (auto & a : additionalvcxproj) {
8484
string name = a.filename().stem().string();
@@ -89,42 +89,42 @@ bool visualStudioProject::saveProjectFile(){
8989
"Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""+name+"\", \""+aString+"\", \"{"+uuid+"}\"" +
9090
divider + "EndProject" + divider;
9191
}
92-
// string findString = "Global" + divider;
92+
// string findString = "Global" + divider;
9393
string findString = "Global";
9494

9595
additionalProjects += findString ;
9696

9797
solution = solution.lexically_normal();
98-
// findandreplaceInTexfile(solution, findString, additionalProjects);
99-
98+
// findandreplaceInTexfile(solution, findString, additionalProjects);
99+
100100
std::ifstream file(solution);
101101
std::stringstream buffer;
102102
buffer << file.rdbuf();
103103
string str = buffer.str();
104104
file.close();
105-
105+
106106
std::size_t pos = str.find(findString);
107107
if (pos != std::string::npos) {
108108
str.replace(pos, findString.length(), additionalProjects);
109109
}
110-
110+
111111
std::ofstream myfile(solution);
112112
myfile << str;
113113
myfile.close();
114114

115115

116-
// cout << fs::current_path() << endl;
117-
// cout << fs::absolute(solution) << endl;
118-
// cout << solution.lexically_normal() << endl;
116+
// cout << fs::current_path() << endl;
117+
// cout << fs::absolute(solution) << endl;
118+
// cout << solution.lexically_normal() << endl;
119119
}
120120

121-
122121

123-
auto filters = projectDir / (projectName + ".vcxproj.filters");
124-
// alert ("saving filters file : " + filters.string(), 35);
122+
123+
auto filters { projectDir / (projectName + ".vcxproj.filters") };
124+
// alert ("saving filters file : " + filters.string(), 35);
125125
bool ok1 = filterXmlDoc.save_file(filters.c_str());
126-
127-
auto vcxFile = projectDir / (projectName + ".vcxproj");
126+
127+
auto vcxFile { projectDir / (projectName + ".vcxproj") };
128128
// alert ("saving vcxFile file : " + vcxFile.string(), 35);
129129
bool ok2 = doc.save_file(vcxFile.c_str());
130130

@@ -134,8 +134,8 @@ bool visualStudioProject::saveProjectFile(){
134134

135135
void visualStudioProject::appendFilter(string folderName){
136136
fixSlashOrder(folderName);
137-
string uuid = generateUUID(folderName);
138-
string tag = "//ItemGroup[Filter]/Filter[@Include=\"" + folderName + "\"]";
137+
string uuid { generateUUID(folderName) };
138+
string tag { "//ItemGroup[Filter]/Filter[@Include=\"" + folderName + "\"]" };
139139
pugi::xpath_node_set set = filterXmlDoc.select_nodes(tag.c_str());
140140
if (set.size() > 0){
141141
//pugi::xml_node node = set[0].node();

0 commit comments

Comments
 (0)