Skip to content

feature - ability to specify additional source/include folders to add to project #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 30, 2020
23 changes: 20 additions & 3 deletions commandLine/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "ofMain.h"
#include "optionparser.h"
#include "defines.h"
enum optionIndex { UNKNOWN, HELP, PLUS, RECURSIVE, LISTTEMPLATES, PLATFORMS, ADDONS, OFPATH, VERBOSE, TEMPLATE, DRYRUN, VERSION };
enum optionIndex { UNKNOWN, HELP, PLUS, RECURSIVE, LISTTEMPLATES, PLATFORMS, ADDONS, OFPATH, VERBOSE, TEMPLATE, DRYRUN, SRCEXTERNAL, VERSION};

constexpr option::Descriptor usage[] =
{
{UNKNOWN, 0, "", "",option::Arg::None, "Options:\n" },
Expand All @@ -14,7 +15,8 @@ constexpr option::Descriptor usage[] =
{VERBOSE, 0,"v","verbose",option::Arg::None, " --verbose, -v \trun verbose" },
{TEMPLATE, 0,"t","template",option::Arg::Optional, " --template, -t \tproject template" },
{DRYRUN, 0,"d","dryrun",option::Arg::None, " --dryrun, -d \tdry run, don't change files" },
{VERSION, 0, "w", "version", option::Arg::None, " --version, -d \treturn the current version"},
{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/" },
{VERSION, 0, "w", "version", option::Arg::None, " --version, -w \treturn the current version"},
{0,0,0,0,0,0}
};

Expand Down Expand Up @@ -58,6 +60,7 @@ std::string directoryForRecursion;
std::string projectPath;
std::string ofPath;
std::vector <std::string> addons;
std::vector <std::string> srcPaths;
std::vector <ofTargetPlatform> targets;
std::string ofPathEnv;
std::string currentWorkingDirectory;
Expand Down Expand Up @@ -263,6 +266,12 @@ void updateProject(std::string path, ofTargetPlatform target, bool bConsiderPara
ofLogNotice() << "parsing addons.make";
project->parseAddons();
}

if(!bDryRun){
for(auto & srcPath : srcPaths){
project->addSrcRecursively(srcPath);
}
}

if (!bDryRun) project->save();
}
Expand Down Expand Up @@ -415,7 +424,12 @@ int main(int argc, char* argv[]){
}
}


if (options[SRCEXTERNAL].count() > 0){
if (options[SRCEXTERNAL].arg != NULL){
std::string srcString(options[SRCEXTERNAL].arg);
srcPaths = ofSplitString(srcString, ",", true, true);
}
}

if (options[OFPATH].count() > 0){
if (options[OFPATH].arg != NULL){
Expand Down Expand Up @@ -571,6 +585,9 @@ int main(int argc, char* argv[]){
for(auto & addon: addons){
project->addAddon(addon);
}
for(auto & srcPath : srcPaths){
project->addSrcRecursively(srcPath);
}
}
if (!bDryRun) project->save();

Expand Down
61 changes: 56 additions & 5 deletions frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var isFirstTimeSierra = false;
var bVerbose = false;
var localAddons = [];


var numAddedSrcPaths = 1;

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

//-------------------------------------------
ipc.on('setSourceExtraPath', function(arg, index) {
checkAddSourcePath(index);
$("#sourceExtra-"+index).val(arg);
});

//-------------------------------------------
ipc.on('setGenerateMode', function(arg) {
switchGenerateMode(arg);
Expand Down Expand Up @@ -914,12 +920,23 @@ function generate() {
addonValueArray.push(localAddons[i]);
}

// extra source locations
var srcExtraArr = "";
for(var i = 0; i < numAddedSrcPaths; i++){
var srcExtra = $("#sourceExtra-"+i).val();
if( srcExtra != '' ){
srcExtraArr += ", " + srcExtra;
}
}


var lengthOfPlatforms = platformValueArray.length;

var gen = {};

gen['projectName'] = $("#projectName").val();
gen['projectPath'] = $("#projectPath").val();
gen['sourcePath'] = srcExtraArr;
gen['platformList'] = platformValueArray;
gen['templateList'] = templateValueArray;
gen['addonList'] = addonValueArray; //$("#addonsDropdown").val();
Expand Down Expand Up @@ -997,12 +1014,16 @@ function switchGenerateMode(mode) {
console.log('Switching GenerateMode to Update...');

clearAddonSelection();
clearExtraSourceList();

}
// [default]: switch to createMode (generate new projects)
else {
// if previously in update mode, deselect Addons
if( $("#updateButton").is(":visible") ){ clearAddonSelection(); }
if( $("#updateButton").is(":visible") ){
clearAddonSelection();
clearExtraSourceList();
}

$("#generateButton").show();
$("#updateButton").hide();
Expand Down Expand Up @@ -1032,14 +1053,14 @@ function enableAdvancedMode(isAdvanced) {
$('#platformsDropdown').removeClass("disabled");
$("body").addClass('advanced');
$('a.updateMultiMenuOption').show();

$('#sourceExtraSection').show();
$('#templateSection').show();
$('#templateSectionMulti').show();

} else {
$('#platformsDropdown').addClass("disabled");
$('#platformsDropdown').dropdown('set exactly', defaultSettings['defaultPlatform']);

$('#sourceExtraSection').hide();
$('#templateSection').hide();
$('#templateSectionMulti').hide();
$('#templateDropdown').dropdown('set exactly', '');
Expand Down Expand Up @@ -1114,14 +1135,44 @@ function browseOfPath() {
}

function browseProjectPath() {

var path = $("#projectPath").val();
if (path === ''){
path = $("#ofPath").val();
}
ipc.send('pickProjectPath', path); // current path could go here
}

function clearExtraSourceList(){
$("#sourceExtraSection").empty();
$("#sourceExtraSection").append("<label>Additional source folders:</label>");

checkAddSourcePath(-1);
numAddedSrcPaths = 1;
}

function checkAddSourcePath(index){
//if we don't have another field below us - add one
var nextFieldId = '#sourceExtra-'+(index+1);
if( $(nextFieldId).length == 0 ){
var nextIndex = index+1;
var extrafield = '<div class="field"> \
<div class="ui icon input fluid"> \
<input type="text" placeholder="Extra source path..." id="sourceExtra-'+nextIndex+'"> \
<i class="search link icon" onclick="browseSourcePath('+nextIndex+')"></i> \
</div> \
</div>';

$("#sourceExtraSection").append(extrafield);
numAddedSrcPaths++;
}
}

function browseSourcePath(index) {
var path = $("#ofPath").val();
ipc.send('pickSourcePath', path, index); // current path could go here
}


function browseImportProject() {
var path = $("#projectPath").val();
if (path === ''){
Expand Down
9 changes: 9 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@
<i class="search link icon" onclick="browseProjectPath()"></i>
</div>
</div>
<div id="sourceExtraSection" class="field">
<label>Additional source folders:</label>
<div class="field">
<div class="ui icon input fluid">
<input type="text" placeholder="Extra source path..." id="sourceExtra-0">
<i class="search link icon" onclick="browseSourcePath(0)"></i>
</div>
</div>
</div>
<div class="field">
<label>
<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;
Expand Down
76 changes: 74 additions & 2 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,17 @@ ipc.on('isOFProjectFolder', function(event, project) {
// todo: also check for config.make & addons.make ?
var foundSrcFolder = false;
var foundAddons = false;
var foundConfig = false;
tmpFiles.forEach(function(el, i) {
if (el == 'src') {
foundSrcFolder = true;
}
if (el == 'addons.make') {
foundAddons = true;
}
if(el == 'config.make'){
foundConfig = true;
}
});

if (foundSrcFolder) {
Expand Down Expand Up @@ -532,6 +536,57 @@ ipc.on('isOFProjectFolder', function(event, project) {
} else {
event.sender.send('selectAddons', {});
}

if(foundConfig){
var projectExtra = fsTemp.readFileSync(pathTemp.resolve(folder, 'config.make')).toString().split("\n");
projectExtra = projectExtra.filter(function(el) {
if (el === '' || el[0] === '#') {
return false;
} // eleminates these items
else {
console.log("got a good element " + el );
return true;
}
});

//read the valid lines
var extraSrcPathsCount = 0;

projectExtra.forEach(function(el, i) {
//remove spaces
var line = el.replace(/ /g, '');

//split either on = or +=
var splitter = "+=";
var n = line.indexOf(splitter);
var macro, value;

if( n != -1 ){
var macro = line.substr(0, n);
var value = line.substr(n + splitter.length);
}else{
splitter = "=";
n = line.indexOf(splitter);
if( n != -1 ){
macro = line.substr(0, n);
value = line.substr(n + splitter.length);
}
}

if( macro.length && value.length){
// this is where you can do things with the macro/values from the config.make file

console.log("Reading config pair. Macro: " + macro + " Value: " + value);

if(macro.startsWith('PROJECT_EXTERNAL_SOURCE_PATHS')){
event.sender.send('setSourceExtraPath', value, extraSrcPathsCount);
extraSrcPathsCount++;
}
}
});

}

} else {
event.sender.send('setGenerateMode', 'createMode');
}
Expand Down Expand Up @@ -740,7 +795,7 @@ ipc.on('generate', function(event, arg) {
var templateString = "";
var verboseString = "";
var rootPath = defaultOfPath;

var sourceExtraString = "";

if (generate['platformList'] !== null) {
platformString = "-p\"" + generate['platformList'].join(",") + "\"";
Expand All @@ -761,6 +816,10 @@ ipc.on('generate', function(event, arg) {
pathString = "-o\"" + generate['ofPath'] + "\"";
rootPath = generate['ofPath'];
}

if( generate['sourcePath'] != null && generate['sourcePath'].length >0 ){
sourceExtraString = " -s\"" + generate['sourcePath'] + "\"";
}

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

var wholeString = pgApp + " " + verboseString + " " + pathString + " " + addonString + " " + platformString + " " + templateString + " " + projectString;
var wholeString = pgApp + " " + verboseString + " " + pathString + " " + addonString + " " + platformString + sourceExtraString + " " + templateString + " " + projectString;

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

Expand Down Expand Up @@ -885,6 +944,19 @@ ipc.on('pickProjectPath', function(event, arg) {
});
});

ipc.on('pickSourcePath', function(event, arg, index) {
path = dialog.showOpenDialog({
title: 'select extra source or include folder paths to add to project',
properties: ['openDirectory'],
filters: [],
defaultPath: arg
}, function(filenames) {
if (filenames !== undefined && filenames.length > 0) {
event.sender.send('setSourceExtraPath', filenames[0], index);
}
});
});

ipc.on('checkMultiUpdatePath', function(event, arg) {


Expand Down
Loading