Skip to content

Commit fc344ea

Browse files
committed
Auto generate the GYP binding
1 parent 7154b54 commit fc344ea

File tree

6 files changed

+64
-112
lines changed

6 files changed

+64
-112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
!/include/wrapper.h
1919

2020
/generate/idefs.json
21+
/binding.gyp

binding.gyp

Lines changed: 0 additions & 104 deletions
This file was deleted.

generate/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const ejs = require("ejs");
44
const path = require("path");
55
const idefs = require("./idefs");
66

7-
87
var local = path.join.bind(null, __dirname);
98

109
var classTemplate = ejs.compile(
@@ -17,16 +16,22 @@ var headerTemplate = ejs.compile(
1716
filename: "header.h"
1817
});
1918

20-
Object.keys(idefs).forEach(function(keyName) {
21-
var idef = idefs[keyName];
19+
var bindingTemplate = ejs.compile(
20+
"" + fs.readFileSync(local("templates/binding.gyp.ejs")), {});
2221

23-
if (idef.ignore) {
24-
return;
25-
}
22+
var enabled = idefs.filter(function(idef) {
23+
idef.name = path.basename(idef.filename, ".h");
24+
return !idef.ignore;
25+
});
2626

27+
enabled.forEach(function(idef) {
2728
fs.writeFileSync(local("../include/", idef.filename), headerTemplate(idef));
2829

2930
fs.writeFileSync(
3031
local("../src/", path.basename(idef.filename, ".h")) + ".cc",
3132
classTemplate(idef));
33+
34+
fs.writeFileSync(local("../binding.gyp"), bindingTemplate({
35+
idefs: idefs
36+
}));
3237
});

generate/templates/binding.gyp.ejs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "nodegit",
5+
6+
"dependencies": [
7+
"<(module_root_dir)/vendor/libgit2.gyp:libgit2"
8+
],
9+
10+
"sources": [
11+
# Maintained.
12+
"src/nodegit.cc",
13+
"src/wrapper.cc",
14+
"src/functions/copy.cc",
15+
16+
# Generated from libgit2 descriptor.
17+
<% idefs.forEach(function(idef) { -%>
18+
"src/<%- idef.name %>.cc",
19+
<% }); -%>
20+
],
21+
22+
"include_dirs": [
23+
"vendor/libv8-convert",
24+
"<!(node -e \"require('nan')\")"
25+
],
26+
27+
"cflags": [
28+
"-Wall",
29+
],
30+
31+
"conditions": [
32+
[
33+
"OS=='mac'", {
34+
"xcode_settings": {
35+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
36+
37+
"WARNING_CFLAGS": [
38+
"-Wno-unused-variable",
39+
],
40+
}
41+
}
42+
]
43+
]
44+
},
45+
]
46+
}

generate/templates/class.cc.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include <nan.h>
3030
#include <string.h>
3131

32-
#include "git2.h"
32+
extern "C" {
33+
#include <git2.h>
34+
}
3335

3436
#include "../include/functions/copy.h"
3537

generate/templates/header.h.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include <nan.h>
99
#include <string>
1010

11-
#include "git2.h"
11+
extern "C" {
12+
#include <git2.h>
13+
}
1214

1315
<% if (typeof dependencies != 'undefined') { -%>
1416
<% for (d in dependencies) { -%>

0 commit comments

Comments
 (0)