Commit 05c06a8a authored by Maximiliano Korp's avatar Maximiliano Korp

clean up the contents of the generate folder

parent 483151c0
......@@ -16,7 +16,10 @@
/vendor/*.filters
/vendor/*.sln
/generate/idefs.json
/generate/output
/generate/**/*.json
!/generate/input/*.json
/generate/missing-tests.json
/binding.gyp
......
const path = require("path");
const combyne = require("combyne");
const file = require("./util/file");
const idefs = require("./idefs");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const js_beautify = require('js-beautify').js_beautify;
const beautify = function (input) {
return js_beautify(input, {
"brace_style": "end-expand",
"max_preserve_newlines": 2,
"preserve_newlines": true,
"indent_size": 2,
"indent_char": " "
});
}
var exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});
// Customize the delimiters so as to not process `{{{` or `}}}`.
combyne.settings.delimiters = {
START_RAW: "{{=",
END_RAW: "=}}"
};
var partials = {
asyncFunction: file.read("partials/async_function.cc"),
convertFromV8: file.read("partials/convert_from_v8.cc"),
convertToV8: file.read("partials/convert_to_v8.cc"),
doc: file.read("partials/doc.cc"),
fields: file.read("partials/fields.cc"),
guardArguments: file.read("partials/guard_arguments.cc"),
syncFunction: file.read("partials/sync_function.cc"),
fieldAccessors: file.read("partials/field_accessors.cc")
};
var templates = {
class_content: file.read("templates/class_content.cc"),
struct_content: file.read("templates/struct_content.cc"),
class_header: file.read("templates/class_header.h"),
struct_header: file.read("templates/struct_header.h"),
binding: file.read("templates/binding.gyp"),
nodegit: file.read("templates/nodegit.cc"),
enums: file.read("templates/enums.js")
};
var filters = {
upper: require("./filters/upper"),
replace: require("./filters/replace"),
titleCase: require("./filters/title_case"),
or: require("./filters/or"),
and: require("./filters/and"),
defaultValue: require("./filters/default_value"),
argsInfo: require("./filters/args_info"),
cppToV8: require("./filters/cpp_to_v8"),
jsArgsCount: require("./filters/js_args_count"),
isV8Value: require("./filters/is_v8_value"),
isPointer: require("./filters/is_pointer"),
isDoublePointer: require("./filters/is_double_pointer"),
unPointer: require("./filters/un_pointer"),
payloadFor: require("./filters/payload_for"),
hasReturnType: require("./filters/has_return_type"),
hasReturns: require("./filters/has_returns"),
returnsCount: require("./filters/returns_count"),
returnsInfo: require("./filters/returns_info"),
fieldsInfo: require("./filters/fields_info")
};
// Convert Buffers to Combyne templates.
Object.keys(templates).forEach(function(template) {
templates[template] = combyne(templates[template]);
// Attach all filters to all templates.
Object.keys(filters).forEach(function(filter) {
templates[template].registerFilter(filter, filters[filter]);
});
});
// Attach all partials to select templates.
Object.keys(partials).forEach(function(partial) {
templates.class_content.registerPartial(partial, combyne(partials[partial]));
templates.struct_content.registerPartial(partial, combyne(partials[partial]));
});
// Determine which definitions to actually include in the source code.
// This might not be needed anymore but to be frank I'm not totally positive
var enabled = idefs.filter(function(idef) {
return !idef.ignore;
});
fse.remove(path.resolve(__dirname, "../src")).then(function() {
return fse.remove(path.resolve(__dirname, "../include"));
}).then(function() {
return fse.copy(path.resolve(__dirname, "./manual/"), path.resolve(__dirname, "../"));
}).then(function() {
// Write out single purpose templates.
file.write("../binding.gyp", beautify(templates.binding.render(enabled)));
file.write("../src/nodegit.cc", templates.nodegit.render(enabled));
// Write out all the classes.
enabled.forEach(function(idef) {
try {
if (idef.type == "struct") {
file.write("../src/" + idef.filename + ".cc", templates.struct_content.render(idef));
file.write("../include/" + idef.filename + ".h", templates.struct_header.render(idef));
}
else if (idef.type == "class") {
file.write("../src/" + idef.filename + ".cc", templates.class_content.render(idef));
file.write("../include/" + idef.filename + ".h", templates.class_header.render(idef));
}
}
catch (e) {
if (process.env.BUILD_ONLY) {
console.log(e);
}
}
});
file.write("../lib/enums.js", beautify(templates.enums.render(enabled)));
}).then(function() {
return exec('command -v astyle').then(function(astyle) {
if (astyle) {
return exec(
'astyle --options=\".astylerc\" '
+ path.resolve(__dirname, "../src") + "/*.cc "
+ path.resolve(__dirname, "../include") + "/*.h"
).then(function() {
return exec(
'rm '
+ path.resolve(__dirname, "../src") + "/*.cc.orig "
+ path.resolve(__dirname, "../include") + "/*.h.orig "
);
});
}
})
});
require("./scripts/generateJson")();
require("./scripts/generateNativeCode")();
require("./scripts/generateMissingTests")();
const path = require("path");
const idefs = require("./idefs");
const Promise = require("nodegit-promise");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const testFilesPath = path.resolve(__dirname, "../test/tests");
const missingFileIgnores = require("./missing-tests-ignore");
var output = {};
function findMissingTest(idef) {
var testFilePath = path.join(testFilesPath, idef.filename + ".js");
var result = {};
return fse.readFile(testFilePath, "utf8")
.then(function(file) {
var fieldsResult = [];
var functionsResult = [];
var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields;
var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions;
fieldIgnores = fieldIgnores || [];
functionIgnores = functionIgnores || [];
file = file || "";
idef.fields.forEach(function(field) {
if (file.indexOf(field.jsFunctionName) < 0
&& fieldIgnores.indexOf(field.jsFunctionName < 0)) {
fieldsResult.push(field.jsFunctionName);
}
});
result.fields = fieldsResult;
idef.functions.forEach(function(fn) {
if (file.indexOf(fn.jsFunctionName) < 0
&& functionIgnores.indexOf(fn.jsFunctionName) < 0) {
functionsResult.push(fn.jsFunctionName);
}
});
result.functions = functionsResult;
},
function() {
result.testFileMissing = false;
result.testFilePath = testFilePath;
}).then(function() {
output[idef.filename] = result;
});
};
var promises = [];
idefs.forEach(function(idef) {
promises.push(findMissingTest(idef));
});
Promise.all(promises)
.then(function() {
fse.writeFileSync(path.join(__dirname, "missing-tests.json"),
JSON.stringify(output, null, 2));
}, function(fail) {
console.log(fail);
});
const fs = require("fs");
const path = require("path");
const helpers = require("./helpers");
const utils = require("./utils");
const _ = require("lodash");
var version = require("../../package.json").libgit2.version;
var libgit2 = require("../input/v" + version + ".json");
var descriptor = require("../input/descriptor.json");
var supplement = require("../input/libgit2-supplement.json");
module.exports = function() {
libgit2.types.forEach(function(type) {
if (supplement.types[type[0]]){
_.merge(type[1], supplement.types[type[0]]);
}
});
// libgit2's docs aren't complete so we'll add in what they're missing here
Array.prototype.push.apply(libgit2.types, supplement.new.types);
Array.prototype.push.apply(libgit2.groups, supplement.new.groups);
var output = [];
var dependencyLookup = {};
var types = [];
var enums = [];
// reduce all of the groups into a hashmap and a name array for easy lookup
var groups = libgit2.groups.reduce(function(memo, group) {
var groupName = group[0];
// Some functions are in the wrong group so we can't just ignore them.
// We have to completely remove them from one group and manually add them
// into the other.
var functionNames = group[1].filter(function(fnName) {
return !supplement.remove[groupName] ||
!supplement.remove[groupName].functions ||
!~supplement.remove[groupName].functions.indexOf(fnName);
});
memo[groupName] = functionNames;
return memo;
}, {});
// Split each type from the array into classes/structs and enums
// each entry is of type ['name', {definingobject}]
libgit2.types.forEach(function(current) {
current[1].typeName = current[0];
// just log these out to a file for fun
if (current[1].type === "enum") {
enums.push(current[1]);
}
else {
types.push(current[1]);
}
});
var previous = "";
enums = _(enums).sortBy("name").reduce(function(enumMemo, enumerable) {
if (previous == enumerable.typeName) {
if (process.env.BUILD_ONLY) {
console.warn('Duplicate definition for enum ' + enumerable.typeName +
". skipped.");
}
}
else if (!enumerable.fields) {
if (process.env.BUILD_ONLY) {
console.warn('Incomplete definition for enum ' + enumerable.typeName +
". skipped.");
}
}
else {
enumMemo[enumerable.typeName] = {
typeName: enumerable.typeName.replace(/^git_/, "").replace(/_t$/, ""),
type: "enum",
cType: enumerable.typeName,
isMask: (/_t$/).test(enumerable.typeName),
values: enumerable.fields.map(function(field) {
return {
name: field.name,
value: field.value
}
})
};
}
previous = enumerable.typeName;
return enumMemo;
}, {}).valueOf();
// decorate the definitions with required data to build the C++ files
types.forEach(function(typeDef) {
var typeName = typeDef.typeName;
typeDef.cType = typeName;
typeName = typeName.replace("git_", "");
typeDef.typeName = typeName;
dependencyLookup[typeName] = typeName;
typeDef.functions = groups[typeName] || [];
helpers.decoratePrimaryType(typeDef, enums);
groups[typeName] = false;
typeDef.type = typeDef.hasConstructor ? "struct" : "class";
output.push(typeDef);
});
// Loop over the groups in case we missed anything (eg the types are missing in the docs);
for (var groupName in groups) {
var groupDef = groups[groupName];
if (groupDef === false) {
continue;
}
groupDef = {
functions: groupDef
};
groupDef.type = "class";
groupDef.cType = (descriptor.types[groupName] || {}).cType || groupDef.cType;
groupDef.typeName = groupName;
dependencyLookup[groupName] = groupName;
helpers.decoratePrimaryType(groupDef, enums);
output.push(groupDef);
}
// Calculate dependencies
output.forEach(function (def) {
if (def.ignore) {
return;
}
var dependencies = {};
var addDependencies = function (prop) {
if (prop.ignore) {
return;
}
var type = helpers.normalizeCtype(prop.type || prop.cType).replace("git_", "");
var dependencyFilename = dependencyLookup[type];
if (dependencyFilename) {
dependencies[dependencyFilename] = dependencyFilename;
}
(prop.args || []).forEach(addDependencies);
if (prop.return) {
addDependencies(prop.return);
}
};
def.fields.forEach(addDependencies);
def.functions.forEach(addDependencies);
Object.keys(dependencies).forEach(function (dependencyFilename) {
def.dependencies.push("../include/" + dependencyFilename + ".h");
});
// Additionally provide a friendly name to the actual filename.
def.name = path.basename(def.filename, ".h");
def.functions.forEach(function(fn) {
fn.cppClassName = def.cppClassName;
});
});
// Process enums
_(enums).forEach(function(enumerable) {
output.some(function(obj) {
if (enumerable.typeName.indexOf(obj.typeName) == 0) {
enumerable.owner = obj.jsClassName;
}
else if (enumerable.owner) {
return true;
}
});
var override = descriptor.enums[enumerable.typeName] || {};
enumerable.owner = override.owner || enumerable.owner || "Enums";
enumerable.JsName = enumerable.typeName
.replace(new RegExp("^" + enumerable.owner.toLowerCase()), "")
.replace(/^_/, "")
.toUpperCase();
enumerable.values.forEach(function(value) {
value.JsName = value.name
.replace(/^GIT_/, "")
.replace(override.removeString || "", "")
.replace(new RegExp("^" + enumerable.owner.toUpperCase()), "")
.replace(/^_/, "")
.replace(new RegExp("^" + enumerable.JsName), "")
.replace(/^_/, "")
.toUpperCase();
if (override.values && override.values[value.name]) {
_.merge(value, override.values[value.name]);
}
});
_.merge(enumerable, _.omit(override, ["values"]));
output.push(enumerable);
});
output = _.sortBy(output, "typeName");
if (process.argv[2] != "--documentation") {
helpers.filterDocumentation(output);
}
utils.writeFile("output/idefs.json", output);
}
const path = require("path");
const Promise = require("nodegit-promise");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const utils = require("./utils");
const testFilesPath = "../test/tests";
const idefs = require("../output/idefs");
const missingFileIgnores = require("../input/ignored-missing-tests");
module.exports = function() {
var output = {};
function findMissingTest(idef) {
return new Promise(function(resolve, reject) {
var testFilePath = path.join(testFilesPath, idef.filename + ".js");
var result = {};
var file = utils.readFile(testFilePath);
if (file) {
var fieldsResult = [];
var functionsResult = [];
var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields;
var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions;
fieldIgnores = fieldIgnores || [];
functionIgnores = functionIgnores || [];
file = file || "";
idef.fields.forEach(function(field) {
if (file.indexOf(field.jsFunctionName) < 0
&& fieldIgnores.indexOf(field.jsFunctionName < 0)) {
fieldsResult.push(field.jsFunctionName);
}
});
result.fields = fieldsResult;
idef.functions.forEach(function(fn) {
if (file.indexOf(fn.jsFunctionName) < 0
&& functionIgnores.indexOf(fn.jsFunctionName) < 0) {
functionsResult.push(fn.jsFunctionName);
}
});
result.functions = functionsResult;
}
else {
result.testFileMissing = false;
result.testFilePath = testFilePath;
}
output[idef.filename] = result;
resolve();
});
};
var promises = [];
idefs.forEach(function(idef) {
promises.push(findMissingTest(idef));
});
Promise.all(promises).then(
function() {
utils.writeFile("output/missing-tests.json", output);
},
function(fail) {
console.log(fail);
}
);
}
const path = require("path");
const combyne = require("combyne");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const js_beautify = require('js-beautify').js_beautify;
const beautify = function (input) {
return js_beautify(input, {
"brace_style": "end-expand",
"max_preserve_newlines": 2,
"preserve_newlines": true,
"indent_size": 2,
"indent_char": " "
});
}
const exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});
const utils = require("./utils");
const idefs = require("../output/idefs");
module.exports = function() {
// Customize the delimiters so as to not process `{{{` or `}}}`.
combyne.settings.delimiters = {
START_RAW: "{{=",
END_RAW: "=}}"
};
var partials = {
asyncFunction: utils.readFile("combyne/partials/async_function.cc"),
convertFromV8: utils.readFile("combyne/partials/convert_from_v8.cc"),
convertToV8: utils.readFile("combyne/partials/convert_to_v8.cc"),
doc: utils.readFile("combyne/partials/doc.cc"),
fields: utils.readFile("combyne/partials/fields.cc"),
guardArguments: utils.readFile("combyne/partials/guard_arguments.cc"),
syncFunction: utils.readFile("combyne/partials/sync_function.cc"),
fieldAccessors: utils.readFile("combyne/partials/field_accessors.cc")
};
var templates = {
class_content: utils.readFile("combyne/templates/class_content.cc"),
struct_content: utils.readFile("combyne/templates/struct_content.cc"),
class_header: utils.readFile("combyne/templates/class_header.h"),
struct_header: utils.readFile("combyne/templates/struct_header.h"),
binding: utils.readFile("combyne/templates/binding.gyp"),
nodegit: utils.readFile("combyne/templates/nodegit.cc"),
enums: utils.readFile("combyne/templates/enums.js")
};
var filters = {
upper: require("../combyne/filters/upper"),
replace: require("../combyne/filters/replace"),
titleCase: require("../combyne/filters/title_case"),
or: require("../combyne/filters/or"),
and: require("../combyne/filters/and"),
defaultValue: require("../combyne/filters/default_value"),
argsInfo: require("../combyne/filters/args_info"),
cppToV8: require("../combyne/filters/cpp_to_v8"),
jsArgsCount: require("../combyne/filters/js_args_count"),
isV8Value: require("../combyne/filters/is_v8_value"),
isPointer: require("../combyne/filters/is_pointer"),
isDoublePointer: require("../combyne/filters/is_double_pointer"),
unPointer: require("../combyne/filters/un_pointer"),
payloadFor: require("../combyne/filters/payload_for"),
hasReturnType: require("../combyne/filters/has_return_type"),
hasReturns: require("../combyne/filters/has_returns"),
returnsCount: require("../combyne/filters/returns_count"),
returnsInfo: require("../combyne/filters/returns_info"),
fieldsInfo: require("../combyne/filters/fields_info")
};
// Convert Buffers to Combyne templates.
Object.keys(templates).forEach(function(template) {
templates[template] = combyne(templates[template]);
// Attach all filters to all templates.
Object.keys(filters).forEach(function(filter) {
templates[template].registerFilter(filter, filters[filter]);
});
});
// Attach all partials to select templates.
Object.keys(partials).forEach(function(partial) {
templates.class_content.registerPartial(partial, combyne(partials[partial]));
templates.struct_content.registerPartial(partial, combyne(partials[partial