Skip to content

Commit e320c2f

Browse files
committed
Opt in ability to generate structs
1 parent c4a17ff commit e320c2f

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

generate/descriptor.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@
375375
},
376376

377377
"filter": {
378+
"forwardDeclare": true,
379+
"fields": []
378380
},
379381

380382
"graph": {
@@ -420,6 +422,8 @@
420422
},
421423

422424
"oid": {
425+
"fields": [],
426+
423427
"functions": {
424428
"git_oid_fromstr": {
425429
"isAsync": false,

generate/setup.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ var version = require("../package.json").libgit2.version;
55
var descriptor = require("./descriptor.json");
66
var libgit2 = require("./v" + version + ".json");
77

8+
var structs = libgit2.types.reduce(function(memo, current) {
9+
return memo[current[0]] = current[1], memo;
10+
}, {});
11+
812
// Extracted types.
913
var typeMap = require("./types.json");
1014

@@ -29,7 +33,15 @@ typeMap.__proto__ = {
2933
"git_branch_iterator **": { cpp: "BranchIterator", js: "Iterator" },
3034
"git_branch_t *": { cpp: "GitBranch", js: "Branch" },
3135
"const git_commit *[]": { cpp: "Array", js: "Array" },
32-
"git_diff_file": { cpp: "GitDiffFile", js: "DiffFile" }
36+
"git_diff_file": { cpp: "GitDiffFile", js: "DiffFile" },
37+
"git_strarray": { cpp: "Array", js: "Array" },
38+
"git_diff_notify_cb": { cpp: "GitDiffNotifyCb", js: "DiffNotifyCb" },
39+
"unsigned char [20]": { cpp: "Array", js: "Array" },
40+
"git_filter_init_fn": { cpp: "Function", js: "Function" },
41+
"git_filter_shutdown_fn": { cpp: "Function", js: "Function" },
42+
"git_filter_check_fn": { cpp: "Function", js: "Function" },
43+
"git_filter_apply_fn": { cpp: "Function", js: "Function" },
44+
"git_filter_cleanup_fn": { cpp: "Function", js: "Function" },
3345
};
3446

3547
var files = [];
@@ -58,6 +70,7 @@ var fileNames = Object.keys(descriptor);
5870

5971
fileNames.forEach(function(fileName, index) {
6072
var file = descriptor[fileName];
73+
var structFile = structs["git_" + fileName];
6174

6275
// Constants.
6376
file.filename = fileName + ".h";
@@ -90,6 +103,7 @@ fileNames.forEach(function(fileName, index) {
90103
// No functions.
91104
cFile = Object.create(file);
92105
cFile.functions = [];
106+
cFile.fields = descriptor[fileName].fields || structFile.fields;
93107
}
94108

95109
// Doesn't actually exist.
@@ -146,17 +160,18 @@ fileNames.forEach(function(fileName, index) {
146160
js: file.jsClassName
147161
};
148162

149-
var fields = file.fields || [];
163+
var fields = file.fields || cFile.fields || (structFile ? structFile.fields || [] : []);
150164

151165
// Decorate fields.
152166
file.fields = fields.map(function(field) {
153167
try {
168+
field.cType = field.cType || field.type;
154169
field.cppFunctionName = titleCase(field.name);
155170
field.jsFunctionName = camelCase(field.name);
156171
field.cppClassName = typeMap[field.cType].cpp;
157172
field.jsClassName = typeMap[field.cType].js;
158173
} catch (ex) {
159-
console.error(field.name + " is missing a definition.");
174+
console.error(file.filename, field.cType + " is missing a definition.");
160175
}
161176

162177
return field;

0 commit comments

Comments
 (0)