Skip to content

Commit 90a1f0a

Browse files
authored
feature - ability to specify additional source/include folders to add to project (#248)
* adding ability to specify additional source/include folders to add to the project * added include search paths for additional directories * fixes to allow adding a single folder with no subfolders to an xcode project * frontend changes to support adding additional source paths - hidden as advanced by default * allow files inside of the OF_ROOT to be relative * added suppport for saving/loading external source files to appropriate variable in config.make
1 parent da2db02 commit 90a1f0a

File tree

9 files changed

+283
-19
lines changed

9 files changed

+283
-19
lines changed

commandLine/src/main.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "ofMain.h"
22
#include "optionparser.h"
33
#include "defines.h"
4-
enum optionIndex { UNKNOWN, HELP, PLUS, RECURSIVE, LISTTEMPLATES, PLATFORMS, ADDONS, OFPATH, VERBOSE, TEMPLATE, DRYRUN, VERSION };
4+
enum optionIndex { UNKNOWN, HELP, PLUS, RECURSIVE, LISTTEMPLATES, PLATFORMS, ADDONS, OFPATH, VERBOSE, TEMPLATE, DRYRUN, SRCEXTERNAL, VERSION};
5+
56
constexpr option::Descriptor usage[] =
67
{
78
{UNKNOWN, 0, "", "",option::Arg::None, "Options:\n" },
@@ -14,7 +15,8 @@ constexpr option::Descriptor usage[] =
1415
{VERBOSE, 0,"v","verbose",option::Arg::None, " --verbose, -v \trun verbose" },
1516
{TEMPLATE, 0,"t","template",option::Arg::Optional, " --template, -t \tproject template" },
1617
{DRYRUN, 0,"d","dryrun",option::Arg::None, " --dryrun, -d \tdry run, don't change files" },
17-
{VERSION, 0, "w", "version", option::Arg::None, " --version, -d \treturn the current version"},
18+
{SRCEXTERNAL, 0,"s","source",option::Arg::Optional, " --source, -s \trelative or absolute path to source or include folders external to the project (such as ../../../../common_utils/" },
19+
{VERSION, 0, "w", "version", option::Arg::None, " --version, -w \treturn the current version"},
1820
{0,0,0,0,0,0}
1921
};
2022

@@ -58,6 +60,7 @@ std::string directoryForRecursion;
5860
std::string projectPath;
5961
std::string ofPath;
6062
std::vector <std::string> addons;
63+
std::vector <std::string> srcPaths;
6164
std::vector <ofTargetPlatform> targets;
6265
std::string ofPathEnv;
6366
std::string currentWorkingDirectory;
@@ -263,6 +266,12 @@ void updateProject(std::string path, ofTargetPlatform target, bool bConsiderPara
263266
ofLogNotice() << "parsing addons.make";
264267
project->parseAddons();
265268
}
269+
270+
if(!bDryRun){
271+
for(auto & srcPath : srcPaths){
272+
project->addSrcRecursively(srcPath);
273+
}
274+
}
266275

267276
if (!bDryRun) project->save();
268277
}
@@ -415,7 +424,12 @@ int main(int argc, char* argv[]){
415424
}
416425
}
417426

418-
427+
if (options[SRCEXTERNAL].count() > 0){
428+
if (options[SRCEXTERNAL].arg != NULL){
429+
std::string srcString(options[SRCEXTERNAL].arg);
430+
srcPaths = ofSplitString(srcString, ",", true, true);
431+
}
432+
}
419433

420434
if (options[OFPATH].count() > 0){
421435
if (options[OFPATH].arg != NULL){
@@ -571,6 +585,9 @@ int main(int argc, char* argv[]){
571585
for(auto & addon: addons){
572586
project->addAddon(addon);
573587
}
588+
for(auto & srcPath : srcPaths){
589+
project->addSrcRecursively(srcPath);
590+
}
574591
}
575592
if (!bDryRun) project->save();
576593

frontend/app.js

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var isFirstTimeSierra = false;
2828
var bVerbose = false;
2929
var localAddons = [];
3030

31-
31+
var numAddedSrcPaths = 1;
3232

3333
//-----------------------------------------------------------------------------------
3434
// IPC
@@ -92,6 +92,12 @@ ipc.on('setProjectPath', function(arg) {
9292
$("#projectName").trigger('change'); // checks if we need to be in update or generate mode
9393
});
9494

95+
//-------------------------------------------
96+
ipc.on('setSourceExtraPath', function(arg, index) {
97+
checkAddSourcePath(index);
98+
$("#sourceExtra-"+index).val(arg);
99+
});
100+
95101
//-------------------------------------------
96102
ipc.on('setGenerateMode', function(arg) {
97103
switchGenerateMode(arg);
@@ -914,12 +920,23 @@ function generate() {
914920
addonValueArray.push(localAddons[i]);
915921
}
916922

923+
// extra source locations
924+
var srcExtraArr = "";
925+
for(var i = 0; i < numAddedSrcPaths; i++){
926+
var srcExtra = $("#sourceExtra-"+i).val();
927+
if( srcExtra != '' ){
928+
srcExtraArr += ", " + srcExtra;
929+
}
930+
}
931+
932+
917933
var lengthOfPlatforms = platformValueArray.length;
918934

919935
var gen = {};
920936

921937
gen['projectName'] = $("#projectName").val();
922938
gen['projectPath'] = $("#projectPath").val();
939+
gen['sourcePath'] = srcExtraArr;
923940
gen['platformList'] = platformValueArray;
924941
gen['templateList'] = templateValueArray;
925942
gen['addonList'] = addonValueArray; //$("#addonsDropdown").val();
@@ -997,12 +1014,16 @@ function switchGenerateMode(mode) {
9971014
console.log('Switching GenerateMode to Update...');
9981015

9991016
clearAddonSelection();
1017+
clearExtraSourceList();
10001018

10011019
}
10021020
// [default]: switch to createMode (generate new projects)
10031021
else {
10041022
// if previously in update mode, deselect Addons
1005-
if( $("#updateButton").is(":visible") ){ clearAddonSelection(); }
1023+
if( $("#updateButton").is(":visible") ){
1024+
clearAddonSelection();
1025+
clearExtraSourceList();
1026+
}
10061027

10071028
$("#generateButton").show();
10081029
$("#updateButton").hide();
@@ -1032,14 +1053,14 @@ function enableAdvancedMode(isAdvanced) {
10321053
$('#platformsDropdown').removeClass("disabled");
10331054
$("body").addClass('advanced');
10341055
$('a.updateMultiMenuOption').show();
1035-
1056+
$('#sourceExtraSection').show();
10361057
$('#templateSection').show();
10371058
$('#templateSectionMulti').show();
10381059

10391060
} else {
10401061
$('#platformsDropdown').addClass("disabled");
10411062
$('#platformsDropdown').dropdown('set exactly', defaultSettings['defaultPlatform']);
1042-
1063+
$('#sourceExtraSection').hide();
10431064
$('#templateSection').hide();
10441065
$('#templateSectionMulti').hide();
10451066
$('#templateDropdown').dropdown('set exactly', '');
@@ -1114,14 +1135,44 @@ function browseOfPath() {
11141135
}
11151136

11161137
function browseProjectPath() {
1117-
11181138
var path = $("#projectPath").val();
11191139
if (path === ''){
11201140
path = $("#ofPath").val();
11211141
}
11221142
ipc.send('pickProjectPath', path); // current path could go here
11231143
}
11241144

1145+
function clearExtraSourceList(){
1146+
$("#sourceExtraSection").empty();
1147+
$("#sourceExtraSection").append("<label>Additional source folders:</label>");
1148+
1149+
checkAddSourcePath(-1);
1150+
numAddedSrcPaths = 1;
1151+
}
1152+
1153+
function checkAddSourcePath(index){
1154+
//if we don't have another field below us - add one
1155+
var nextFieldId = '#sourceExtra-'+(index+1);
1156+
if( $(nextFieldId).length == 0 ){
1157+
var nextIndex = index+1;
1158+
var extrafield = '<div class="field"> \
1159+
<div class="ui icon input fluid"> \
1160+
<input type="text" placeholder="Extra source path..." id="sourceExtra-'+nextIndex+'"> \
1161+
<i class="search link icon" onclick="browseSourcePath('+nextIndex+')"></i> \
1162+
</div> \
1163+
</div>';
1164+
1165+
$("#sourceExtraSection").append(extrafield);
1166+
numAddedSrcPaths++;
1167+
}
1168+
}
1169+
1170+
function browseSourcePath(index) {
1171+
var path = $("#ofPath").val();
1172+
ipc.send('pickSourcePath', path, index); // current path could go here
1173+
}
1174+
1175+
11251176
function browseImportProject() {
11261177
var path = $("#projectPath").val();
11271178
if (path === ''){

frontend/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@
150150
<i class="search link icon" onclick="browseProjectPath()"></i>
151151
</div>
152152
</div>
153+
<div id="sourceExtraSection" class="field">
154+
<label>Additional source folders:</label>
155+
<div class="field">
156+
<div class="ui icon input fluid">
157+
<input type="text" placeholder="Extra source path..." id="sourceExtra-0">
158+
<i class="search link icon" onclick="browseSourcePath(0)"></i>
159+
</div>
160+
</div>
161+
</div>
153162
<div class="field">
154163
<label>
155164
<a class="tooltip" href="http://www.ofxaddons.com/" data-toggle="external_target" data-content="Get more addons at ofxAddons.com" data-position="right center" id="ofx-addons-link">Addons</a>: &nbsp;

frontend/index.js

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,17 @@ ipc.on('isOFProjectFolder', function(event, project) {
497497
// todo: also check for config.make & addons.make ?
498498
var foundSrcFolder = false;
499499
var foundAddons = false;
500+
var foundConfig = false;
500501
tmpFiles.forEach(function(el, i) {
501502
if (el == 'src') {
502503
foundSrcFolder = true;
503504
}
504505
if (el == 'addons.make') {
505506
foundAddons = true;
506507
}
508+
if(el == 'config.make'){
509+
foundConfig = true;
510+
}
507511
});
508512

509513
if (foundSrcFolder) {
@@ -532,6 +536,57 @@ ipc.on('isOFProjectFolder', function(event, project) {
532536
} else {
533537
event.sender.send('selectAddons', {});
534538
}
539+
540+
if(foundConfig){
541+
var projectExtra = fsTemp.readFileSync(pathTemp.resolve(folder, 'config.make')).toString().split("\n");
542+
projectExtra = projectExtra.filter(function(el) {
543+
if (el === '' || el[0] === '#') {
544+
return false;
545+
} // eleminates these items
546+
else {
547+
console.log("got a good element " + el );
548+
return true;
549+
}
550+
});
551+
552+
//read the valid lines
553+
var extraSrcPathsCount = 0;
554+
555+
projectExtra.forEach(function(el, i) {
556+
//remove spaces
557+
var line = el.replace(/ /g, '');
558+
559+
//split either on = or +=
560+
var splitter = "+=";
561+
var n = line.indexOf(splitter);
562+
var macro, value;
563+
564+
if( n != -1 ){
565+
var macro = line.substr(0, n);
566+
var value = line.substr(n + splitter.length);
567+
}else{
568+
splitter = "=";
569+
n = line.indexOf(splitter);
570+
if( n != -1 ){
571+
macro = line.substr(0, n);
572+
value = line.substr(n + splitter.length);
573+
}
574+
}
575+
576+
if( macro.length && value.length){
577+
// this is where you can do things with the macro/values from the config.make file
578+
579+
console.log("Reading config pair. Macro: " + macro + " Value: " + value);
580+
581+
if(macro.startsWith('PROJECT_EXTERNAL_SOURCE_PATHS')){
582+
event.sender.send('setSourceExtraPath', value, extraSrcPathsCount);
583+
extraSrcPathsCount++;
584+
}
585+
}
586+
});
587+
588+
}
589+
535590
} else {
536591
event.sender.send('setGenerateMode', 'createMode');
537592
}
@@ -740,7 +795,7 @@ ipc.on('generate', function(event, arg) {
740795
var templateString = "";
741796
var verboseString = "";
742797
var rootPath = defaultOfPath;
743-
798+
var sourceExtraString = "";
744799

745800
if (generate['platformList'] !== null) {
746801
platformString = "-p\"" + generate['platformList'].join(",") + "\"";
@@ -761,6 +816,10 @@ ipc.on('generate', function(event, arg) {
761816
pathString = "-o\"" + generate['ofPath'] + "\"";
762817
rootPath = generate['ofPath'];
763818
}
819+
820+
if( generate['sourcePath'] != null && generate['sourcePath'].length >0 ){
821+
sourceExtraString = " -s\"" + generate['sourcePath'] + "\"";
822+
}
764823

765824
if (generate['verbose'] === true) {
766825
verboseString = "-v";
@@ -785,7 +844,7 @@ ipc.on('generate', function(event, arg) {
785844
pgApp = pgApp = "\"" + pgApp + "\"";
786845
}
787846

788-
var wholeString = pgApp + " " + verboseString + " " + pathString + " " + addonString + " " + platformString + " " + templateString + " " + projectString;
847+
var wholeString = pgApp + " " + verboseString + " " + pathString + " " + addonString + " " + platformString + sourceExtraString + " " + templateString + " " + projectString;
789848

790849
exec(wholeString, {maxBuffer : Infinity}, function callback(error, stdout, stderr) {
791850

@@ -885,6 +944,19 @@ ipc.on('pickProjectPath', function(event, arg) {
885944
});
886945
});
887946

947+
ipc.on('pickSourcePath', function(event, arg, index) {
948+
path = dialog.showOpenDialog({
949+
title: 'select extra source or include folder paths to add to project',
950+
properties: ['openDirectory'],
951+
filters: [],
952+
defaultPath: arg
953+
}, function(filenames) {
954+
if (filenames !== undefined && filenames.length > 0) {
955+
event.sender.send('setSourceExtraPath', filenames[0], index);
956+
}
957+
});
958+
});
959+
888960
ipc.on('checkMultiUpdatePath', function(event, arg) {
889961

890962

0 commit comments

Comments
 (0)