Skip to content

Commit

Permalink
Revert all of da2ce7's "style commits" which break actual functionali…
Browse files Browse the repository at this point in the history
…ty (no more compile warnings displayed on mac)
  • Loading branch information
cjdelisle committed Oct 11, 2015
1 parent 507858d commit 8f70691
Show file tree
Hide file tree
Showing 18 changed files with 989 additions and 1,286 deletions.
18 changes: 9 additions & 9 deletions node_build/CanCompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
var nThen = require("nthen");
var Fs = require("fs");

module.exports.check = function(builder, code, cflags, callback) {
module.exports.check = function (builder, code, cflags, callback) {

var codeFile = builder.tmpFile() + '.c';
var exeFile = builder.tmpFile() + builder.config.ext.exe;
var file = builder.tmpFile();
var outputFile = builder.tmpFile();

nThen(function(waitFor) {
nThen(function (waitFor) {

Fs.writeFile(codeFile, code, waitFor(function(err, ret) {
Fs.writeFile(file, code, waitFor(function (err, ret) {
if (err) {
waitFor.abort();
callback(err);
}
}));

}).nThen(function(waitFor) {
}).nThen(function (waitFor) {

var flags = [];
flags.push.apply(flags, cflags);
flags.push(builder.config.flag.outputExe + exeFile, codeFile);
flags.push.apply(flags, ["-o", outputFile, file]);

builder.cc(flags, waitFor(function(ret, out, err) {
builder.cc([cflags, "-o", outputFile, file], waitFor(function (ret, out, err) {
if (ret) {
callback(err, false);
} else {
callback(null, true);
callback(undefined, true);
}
}));

Expand Down
130 changes: 54 additions & 76 deletions node_build/Codestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var Fs = require('fs');
var nThen = require('nthen');
var Semaphore = require('./Semaphore');
var Spawn = require('child_process').spawn;
var Child = require('child_process');

var headerLines = [
'/* vim: set expandtab ts=4 sw=4: */',
Expand All @@ -35,12 +35,12 @@ var headerLines = [
' */'
];

var parseFile = function(fileName, fileContent) {
var parseFile = function (fileName, fileContent) {
var output = '';
var parenthCount = 0;
var functionParenthCount = 0;
var expectBracket = 0;
var name = fileName.replace(/^.*\//, '').replace(/\..*$/, '');
var name = fileName.replace(/^.*\//, '').replace(/\..*$/,'');

var lines = fileContent.split('\n');

Expand All @@ -57,7 +57,7 @@ var parseFile = function(fileName, fileContent) {
var line = lines[lineNum];

// switch to 1 indexing for human readability
lineInfo = fileName + ":" + (lineNum + 1);
lineInfo = fileName + ":" + (lineNum+1);
ignore = false;

if (lineNum < headerLines.length) {
Expand Down Expand Up @@ -88,17 +88,12 @@ var parseFile = function(fileName, fileContent) {
// implementations.. TUNConfigurator_Linux contains TUNConfigurator_doStuff...
var n = name.replace(/_.*/, '');
if ((/^\w+\s.*\(/).test(line)) {
switch (true) {
// exceptions
case /^int main\(/.test(line):
case /^[ ]?static /.test(line):
case /^typedef /.test(line):
case line.indexOf(' ' + n) !== -1:
break; // do nothing

default:
error("all globally visible functions must begin with the name of the file.");
break;
if (!(/^int main\(/.test(line)
|| line.indexOf(' '+n) > -1
|| /^[ ]?static /.test(line)
|| /^typedef /.test(line)))
{
error("all globally visible functions must begin with the name of the file.");
}
}

Expand All @@ -108,8 +103,8 @@ var parseFile = function(fileName, fileContent) {
}
if (functionParenthCount > 0 || matches) {
var txt = (functionParenthCount > 0) ? line : matches[1];
functionParenthCount += (txt.match(/\(/g) || []).length;
functionParenthCount -= (txt.match(/\)/g) || []).length;
functionParenthCount += (txt.match(/\(/g)||[]).length;
functionParenthCount -= (txt.match(/\)/g)||[]).length;
if (functionParenthCount === 0) {
txt = txt.substring(txt.lastIndexOf(')') + 1);
if (/{/.test(txt)) {
Expand Down Expand Up @@ -165,8 +160,8 @@ var parseFile = function(fileName, fileContent) {
}
if (parenthCount > 0 || matches) {
var txt1 = (parenthCount > 0) ? line : matches[2];
parenthCount += (txt1.match(/\(/g) || []).length;
parenthCount -= (txt1.match(/\)/g) || []).length;
parenthCount += (txt1.match(/\(/g)||[]).length;
parenthCount -= (txt1.match(/\)/g)||[]).length;
if (parenthCount === 0) {
txt1 = txt1.substring(txt1.lastIndexOf(')') + 1);
// for (x; y; z) ; <-- ok
Expand All @@ -188,108 +183,91 @@ var parseFile = function(fileName, fileContent) {
return output;
};

var checkFile = module.exports.checkFile = function(file, callback) {
Fs.readFile(file, function(err, ret) {
if (err) {
throw err;
}
var checkFile = module.exports.checkFile = function (file, callback) {
Fs.readFile(file, function (err, ret) {
if (err) { throw err; }
callback(parseFile(file, ret.toString()));
});
};

var lint = module.exports.lint = function(fileName, fileContent, callback) {
var lint = module.exports.lint = function (fileName, fileContent, callback) {
var out = parseFile(fileName, fileContent);
callback(out, !!out);
};

var checkFiles = module.exports.checkFiles = function(files, callback) {
var checkFiles = module.exports.checkFiles = function (files, callback) {
var sema = Semaphore.create(64);
var errors = '';
nThen(function(waitFor) {
files.forEach(function(file) {
sema.take(waitFor(function(returnAfter) {
checkFile(file, waitFor(returnAfter(function(err) {
nThen(function (waitFor) {
files.forEach(function (file) {
sema.take(waitFor(function (returnAfter) {
checkFile(file, waitFor(returnAfter(function (err) {
if (err) {
errors += file + '\n' + err + '\n';
}
})));
}));
});
}).nThen(function(waitFor) {
}).nThen(function (waitFor) {
callback(errors);
});
};

var checkDir = module.exports.checkDir = function(dir, runInFork, callback) {
var checkDir = module.exports.checkDir = function (dir, runInFork, callback) {

var gitIgnoreLines;

if (runInFork) {
var err = '';
var out = '';
var exe = Spawn(process.execPath, [__filename]);
exe.stdout.on('data', function(data) {
err += data.toString('utf8');
});
exe.stderr.on('data', function(data) {
err += data.toString('utf8');
});
exe.on('close', function(ret) {
var proc = Child.spawn(process.execPath, [__filename]);
proc.stdout.on('data', function (data) { err += data.toString('utf8'); });
proc.stderr.on('data', function (data) { err += data.toString('utf8'); });
proc.on('close', function (ret) {
out += err;
var error;
if (ret !== 0) {
error = new Error(out);
}
if (ret !== 0) { error = new Error(out); }
callback(error, out);
});
return;
}

var output = '';
nThen(function(waitFor) {
nThen(function (waitFor) {

Fs.readFile('.gitignore', waitFor(function(err, ret) {
if (err) {
throw err;
}
Fs.readFile('.gitignore', waitFor(function (err, ret) {
if (err) { throw err; }
gitIgnoreLines = ret.toString('utf8').split('\n');
}));

}).nThen(function(waitFor) {

var addDir = function(dir) {
Fs.readdir(dir, waitFor(function(err, files) {
if (err) {
throw err;
}
files.forEach(function(file) {
Fs.stat(dir + '/' + file, waitFor(function(err, stat) {
if (err) {
throw err;
}
switch (true) {
case file === '.git':
case file === 'contrib':
case file === 'dependencies':
case gitIgnoreLines.indexOf(file) !== -1:
break; // do nothing

default:
if (stat.isDirectory()) {
addDir(dir + '/' + file);
} else if (/.*\.[ch]$/.test(file)) {
checkFile(dir + '/' + file, waitFor(function(ret) {
output += ret;
}));
}
}).nThen(function (waitFor) {

var addDir = function (dir) {
Fs.readdir(dir, waitFor(function (err, files) {
if (err) { throw err; }
files.forEach(function (file) {
Fs.stat(dir + '/' + file, waitFor(function (err, stat) {
if (err) { throw err; }
if (file === '.git') {
} else if (file === 'contrib') {
} else if (file === 'dependencies') {
} else if (gitIgnoreLines.indexOf(file) !== -1) {
} else {
if (stat.isDirectory()) {
addDir(dir + '/' + file);
} else if (/.*\.[ch]$/.test(file)) {
checkFile(dir + '/' + file, waitFor(function (ret) {
output += ret;
}));
}
}
}));
});
}));
};
addDir(dir);

}).nThen(function(waitFor) {
}).nThen(function (waitFor) {

callback(output);

Expand Down
38 changes: 16 additions & 22 deletions node_build/Cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@ var Fs = require("fs");
var Semaphore = require('./Semaphore');
var nThen = require('nthen');

var throwIfErr = function(err) {
if (err) {
throw err;
}
};

var sema = Semaphore.create(64);
var cp = module.exports = function(src, dest, callback) {
Fs.stat(src, function(err, stat) {
throwIfErr(err);
var cp = module.exports = function (src, dest, callback) {
Fs.stat(src, function (err, stat) {
if (err) { throw err; }
if (stat.isDirectory()) {
var subFiles;
nThen(function(waitFor) {
Fs.mkdir(dest, waitFor(function(err) {
throwIfErr(err);
nThen(function (waitFor) {
Fs.mkdir(dest, waitFor(function (err) {
if (err) { throw err; }
}));
Fs.readdir(src, waitFor(function(err, list) {
throwIfErr(err);
Fs.readdir(src, waitFor(function (err, list) {
if (err) { throw err; }
subFiles = list;
}));
}).nThen(function(waitFor) {
subFiles.forEach(function(file) {
}).nThen(function (waitFor) {
subFiles.forEach(function (file) {
cp(src + '/' + file, dest + '/' + file, waitFor());
});
}).nThen(function(waitFor) {
}).nThen(function (waitFor) {
callback();
});
} else {
sema.take(function(returnAfter) {
Fs.readFile(src, function(err, content) {
throwIfErr(err);
Fs.writeFile(dest, content, returnAfter(function(err) {
throwIfErr(err);
sema.take(function (returnAfter) {
Fs.readFile(src, function (err, content) {
if (err) { throw err; }
Fs.writeFile(dest, content, returnAfter(function (err) {
if (err) { throw err; }
callback();
}));
});
Expand Down
31 changes: 11 additions & 20 deletions node_build/FindPython2.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,31 @@ var SCRIPT = [
'exit(sys.version_info[0] != 2 or sys.version_info[1] < 7);'
].join('\n');

var find = module.exports.find = function(tempFile, callback) {
var nt = nThen(function(waitFor) {
Fs.writeFile(tempFile, SCRIPT, waitFor(function(err) {
if (err) {
throw err;
}
}));
var find = module.exports.find = function (tempFile, callback) {
var nt = nThen(function (waitFor) {
Fs.writeFile(tempFile, SCRIPT, waitFor(function (err) { if (err) { throw err; } }));
}).nThen;
PYTHONS.forEach(function(python) {
nt = nt(function(waitFor) {
PYTHONS.forEach(function (python) {
nt = nt(function (waitFor) {
console.log("testing python " + python);

var exe = Spawn(python, [tempFile]);
var py = Spawn(python, [tempFile]);
var cont = waitFor();
exe.stdout.on('data', function(dat) {
console.log(dat.toString('utf8'));
});
exe.on('close', function(ret) {
py.stdout.on('data', function (dat) { console.log(dat.toString('utf8')); });
py.on('close', function(ret) {
if (ret === 0) {
callback(undefined, python);
waitFor.abort();
} else {
cont();
}
});
exe.on('error', function(err) {
if (err !== 'ENOENT') {
console.log('error starting python ' + err);
}
py.on('error', function (err) {
if (err !== 'ENOENT') { console.log('error starting python ' + err); }
});
// Don't worry about errors, try the next.
}).nThen;
});
nt(function(waitFor) {
nt(function (waitFor) {
callback(new Error("no sutible python2 executable found ( < 2.7 unsupported)"));
});
};
Loading

0 comments on commit 8f70691

Please sign in to comment.