diff --git a/bin/build-shaders.js b/bin/build-shaders.js index 445006633..b5072c370 100755 --- a/bin/build-shaders.js +++ b/bin/build-shaders.js @@ -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'); diff --git a/bin/build-style.js b/bin/build-style.js index bd86d5bda..932287b89 100755 --- a/bin/build-style.js +++ b/bin/build-style.js @@ -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 \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); diff --git a/bin/mkdirp.js b/bin/mkdirp.js new file mode 100644 index 000000000..a1742b206 --- /dev/null +++ b/bin/mkdirp.js @@ -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; +}; diff --git a/llmr.gyp b/llmr.gyp index a76ef225c..a32a598f5 100644 --- a/llmr.gyp +++ b/llmr.gyp @@ -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/', ] } },