Address #151 at the same time

This commit is contained in:
Dane Springmeyer
2014-05-23 17:14:19 -07:00
parent 9e7ee02fcd
commit 7f592ac2e7
4 changed files with 127 additions and 17 deletions

View File

@@ -3,7 +3,7 @@
var fs = require('fs');
var path = require('path');
var lazy_update = require('./lazy-update');
var mkdirp = require('./mkdirp');
try { var glsl = require('glsl-optimizer'); } catch(err) {}
@@ -117,9 +117,13 @@ module.exports = function(shader_type, prefix, suffix) {
code += '\n};\n';
code += suffix + '\n';
var file_path = path.join(process.argv[2], 'include/llmr/shader/shaders.hpp');
mkdirp.sync(path.dirname(file_path));
fs.writeFileSync(file_path, header);
var header_path = path.join(process.argv[2], 'src/shader/shaders_' + shader_type + '.cpp');
mkdirp.sync(path.dirname(header_path));
fs.writeFileSync(header_path, code);
lazy_update('include/llmr/shader/shaders.hpp', header);
lazy_update('src/shader/shaders_' + shader_type + '.cpp', code);
};
module.exports('gl', '#ifndef GL_ES_VERSION_2_0', '#endif');

View File

@@ -2,9 +2,8 @@
'use strict';
var path = require('path');
var lazy_update = require('./lazy-update');
var fs = require('fs');
var mkdirp = require('./mkdirp');
var name = 'style';
var data = JSON.stringify(require(path.join(process.cwd(), process.argv[2])));
@@ -26,7 +25,9 @@ header += '}\n';
header += '\n';
header += '#endif\n';
lazy_update('include/llmr/style/resources.hpp', header);
var header_path = path.join(process.argv[3], 'include/llmr/style/resources.hpp');
mkdirp.sync(path.dirname(header_path));
fs.writeFileSync(header_path, header);
var code = '// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n';
code += '#include <llmr/style/resources.hpp>\n';
@@ -36,5 +37,6 @@ code += '\n';
code += 'const unsigned char resources::' + name + '[] = R"JSON(' + data + ')JSON";\n';
code += 'const unsigned long resources::' + name + '_size = sizeof(resources::' + name + ');\n';
lazy_update('src/style/resources.cpp', code);
var file_path = path.join(process.argv[3], 'src/style/resources.cpp');
mkdirp.sync(path.dirname(file_path));
fs.writeFileSync(file_path, code);

97
bin/mkdirp.js Normal file
View File

@@ -0,0 +1,97 @@
var path = require('path');
var fs = require('fs');
module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
function mkdirP (p, opts, f, made) {
if (typeof opts === 'function') {
f = opts;
opts = {};
}
else if (!opts || typeof opts !== 'object') {
opts = { mode: opts };
}
var mode = opts.mode;
var xfs = opts.fs || fs;
if (mode === undefined) {
mode = 0777 & (~process.umask());
}
if (!made) made = null;
var cb = f || function () {};
p = path.resolve(p);
xfs.mkdir(p, mode, function (er) {
if (!er) {
made = made || p;
return cb(null, made);
}
switch (er.code) {
case 'ENOENT':
mkdirP(path.dirname(p), opts, function (er, made) {
if (er) cb(er, made);
else mkdirP(p, opts, cb, made);
});
break;
// In the case of any other error, just see if there's a dir
// there already. If so, then hooray! If not, then something
// is borked.
default:
xfs.stat(p, function (er2, stat) {
// if the stat fails, then that's super weird.
// let the original error be the failure reason.
if (er2 || !stat.isDirectory()) cb(er, made)
else cb(null, made);
});
break;
}
});
}
mkdirP.sync = function sync (p, opts, made) {
if (!opts || typeof opts !== 'object') {
opts = { mode: opts };
}
var mode = opts.mode;
var xfs = opts.fs || fs;
if (mode === undefined) {
mode = 0777 & (~process.umask());
}
if (!made) made = null;
p = path.resolve(p);
try {
xfs.mkdirSync(p, mode);
made = made || p;
}
catch (err0) {
switch (err0.code) {
case 'ENOENT' :
made = sync(path.dirname(p), opts, made);
sync(p, opts, made);
break;
// In the case of any other error, just see if there's a dir
// there already. If so, then hooray! If not, then something
// is borked.
default:
var stat;
try {
stat = xfs.statSync(p);
}
catch (err1) {
throw err0;
}
if (!stat.isDirectory()) throw err0;
break;
}
}
return made;
};

View File

@@ -19,14 +19,17 @@
'src/shader/shaders_gl.cpp',
'src/shader/shaders_gles2.cpp',
],
'action': ['<@(node)', 'bin/build-shaders.js'],
'action': ['<@(node)', 'bin/build-shaders.js', '<(SHARED_INTERMEDIATE_DIR)'],
}
],
'direct_dependent_settings': {
'sources': [
'include/llmr/shader/shaders.hpp',
'src/shader/shaders_gl.cpp',
'src/shader/shaders_gles2.cpp'
'<(SHARED_INTERMEDIATE_DIR)/include/llmr/shader/shaders.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp'
],
'include_dirs':[
'<(SHARED_INTERMEDIATE_DIR)/include/',
]
}
},
@@ -41,15 +44,19 @@
'bin/style.js',
],
'outputs': [
'include/llmr/style/resources.hpp',
'src/style/resources.cpp'
'<(SHARED_INTERMEDIATE_DIR)/include/llmr/style/resources.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/style/resources.cpp'
],
'action': ['<@(node)', 'bin/build-style.js', '<@(_inputs)']
'action': ['<@(node)', 'bin/build-style.js', '<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)']
}
],
'direct_dependent_settings': {
'sources': [
'src/style/resources.cpp'
'<(SHARED_INTERMEDIATE_DIR)/include/llmr/style/resources.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/style/resources.cpp'
],
'include_dirs':[
'<(SHARED_INTERMEDIATE_DIR)/include/',
]
}
},