|
1 | | -const child_process = require('child_process'); |
2 | | -const util = require('util'); |
3 | | - |
4 | | -module.exports = function(grunt) { |
5 | | - 'use strict'; |
6 | | - |
7 | | - grunt.initConfig({ |
8 | | - pkg: grunt.file.readJSON('package.json'), |
9 | | - concat: { |
10 | | - components: { |
11 | | - src: [ |
12 | | - 'node_modules/long/dist/long.js', |
13 | | - 'node_modules/bytebuffer/dist/bytebuffer.js', |
14 | | - 'node_modules/protobufjs/dist/protobuf.js' |
15 | | - ], |
16 | | - dest: 'build/components_concat.js', |
17 | | - }, |
18 | | - curve25519: { |
19 | | - src: [ |
20 | | - 'build/curve25519_compiled.js', |
21 | | - 'src/curve25519_wrapper.js', |
22 | | - ], |
23 | | - dest: 'build/curve25519_concat.js' |
24 | | - }, |
25 | | - protos: { |
26 | | - src: [ |
27 | | - 'protos/WhisperTextProtocol.proto' |
28 | | - ], |
29 | | - dest: 'build/protoText.js', |
30 | | - options: { |
31 | | - banner: 'var Internal = Internal || {};\n\nInternal.protoText = function() {\n\tvar protoText = {};\n\n', |
32 | | - footer: '\n\treturn protoText;\n}();', |
33 | | - process: function(src, file) { |
34 | | - let res = "\tprotoText['" + file + "'] = \n"; |
35 | | - const lines = src.match(/[^\r\n]+/g); |
36 | | - for (const i in lines) { |
37 | | - res += "\t\t'" + lines[i] + "\\n' +\n"; |
38 | | - } |
39 | | - return res + "''\t;\n"; |
40 | | - } |
41 | | - } |
42 | | - }, |
43 | | - protos_concat: { |
44 | | - src: [ |
45 | | - 'build/protoText.js', |
46 | | - 'src/protobufs.js', |
47 | | - ], |
48 | | - dest: 'build/protobufs_concat.js' |
49 | | - }, |
50 | | - |
51 | | - worker: { |
52 | | - src: [ |
53 | | - 'build/curve25519_concat.js', |
54 | | - 'src/curve25519_worker.js', |
55 | | - ], |
56 | | - dest: 'dist/libsignal-protocol-worker.js', |
57 | | - options: { |
58 | | - banner: ';(function(){\nvar Internal = {};\nvar libsignal = {};\n', |
59 | | - footer: '\n})();' |
60 | | - } |
61 | | - |
62 | | - }, |
63 | | - libsignalprotocol: { |
64 | | - src: [ |
65 | | - 'build/curve25519_concat.js', |
66 | | - 'src/curve25519_worker_manager.js', |
67 | | - 'build/components_concat.js', |
68 | | - |
69 | | - 'src/Curve.js', |
70 | | - 'src/crypto.js', |
71 | | - 'src/helpers.js', |
72 | | - 'src/KeyHelper.js', |
73 | | - 'build/protobufs_concat.js', |
74 | | - 'src/SessionRecord.js', |
75 | | - 'src/SignalProtocolAddress.js', |
76 | | - 'src/SessionBuilder.js', |
77 | | - 'src/SessionCipher.js', |
78 | | - 'src/SessionLock.js', |
79 | | - 'src/NumericFingerprint.js' |
80 | | - ], |
81 | | - dest: 'dist/libsignal-protocol.js', |
82 | | - options: { |
83 | | - banner: ';(function(){\nvar Internal = {};\nwindow.libsignal = {};\n', |
84 | | - footer: '\n})();' |
85 | | - } |
86 | | - |
87 | | - }, |
88 | | - }, |
89 | | - compile: { |
90 | | - curve25519_compiled: { |
91 | | - src_files: [ |
92 | | - 'native/ed25519/*.c', |
93 | | - 'native/ed25519/additions/*.c', |
94 | | - 'native/ed25519/nacl_sha512/*.c', |
95 | | - 'native/curve25519-donna.c', |
96 | | - 'native/ed25519/sha512/sha2big.c' |
97 | | - ], |
98 | | - methods: [ |
99 | | - 'curve25519_donna', |
100 | | - 'curve25519_sign', |
101 | | - 'curve25519_verify', |
102 | | - 'crypto_sign_ed25519_ref10_ge_scalarmult_base', |
103 | | - 'sph_sha512_init', |
104 | | - 'malloc', |
105 | | - 'free', |
106 | | - 'xed25519_sign', |
107 | | - ] |
| 1 | +const child_process = require("child_process"); |
| 2 | +const util = require("util"); |
| 3 | + |
| 4 | +module.exports = function (grunt) { |
| 5 | + "use strict"; |
| 6 | + |
| 7 | + grunt.initConfig({ |
| 8 | + pkg: grunt.file.readJSON("package.json"), |
| 9 | + concat: { |
| 10 | + components: { |
| 11 | + src: [ |
| 12 | + "node_modules/long/dist/long.js", |
| 13 | + "node_modules/bytebuffer/dist/bytebuffer.js", |
| 14 | + "node_modules/protobufjs/dist/protobuf.js", |
| 15 | + ], |
| 16 | + dest: "build/components_concat.js", |
| 17 | + }, |
| 18 | + curve25519: { |
| 19 | + src: ["build/curve25519_compiled.js", "src/curve25519_wrapper.js"], |
| 20 | + dest: "build/curve25519_concat.js", |
| 21 | + }, |
| 22 | + protos: { |
| 23 | + src: ["protos/WhisperTextProtocol.proto"], |
| 24 | + dest: "build/protoText.js", |
| 25 | + options: { |
| 26 | + banner: "var Internal = Internal || {};\n\nInternal.protoText = function() {\n\tvar protoText = {};\n\n", |
| 27 | + footer: "\n\treturn protoText;\n}();", |
| 28 | + process: function (src, file) { |
| 29 | + let res = "\tprotoText['" + file + "'] = \n"; |
| 30 | + const lines = src.match(/[^\r\n]+/g); |
| 31 | + for (const i in lines) { |
| 32 | + res += "\t\t'" + lines[i] + "\\n' +\n"; |
| 33 | + } |
| 34 | + return res + "''\t;\n"; |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + protos_concat: { |
| 39 | + src: ["build/protoText.js", "src/protobufs.js"], |
| 40 | + dest: "build/protobufs_concat.js", |
| 41 | + }, |
| 42 | + |
| 43 | + worker: { |
| 44 | + src: ["build/curve25519_concat.js", "src/curve25519_worker.js"], |
| 45 | + dest: "dist/libsignal-protocol-worker.js", |
| 46 | + options: { |
| 47 | + banner: ";(function(){\nvar Internal = {};\nvar libsignal = {};\n", |
| 48 | + footer: "\n})();", |
| 49 | + }, |
| 50 | + }, |
| 51 | + libsignalprotocol: { |
| 52 | + src: [ |
| 53 | + "build/curve25519_concat.js", |
| 54 | + "src/curve25519_worker_manager.js", |
| 55 | + "build/components_concat.js", |
| 56 | + |
| 57 | + "src/Curve.js", |
| 58 | + "src/crypto.js", |
| 59 | + "src/helpers.js", |
| 60 | + "src/KeyHelper.js", |
| 61 | + "build/protobufs_concat.js", |
| 62 | + "src/SessionRecord.js", |
| 63 | + "src/SignalProtocolAddress.js", |
| 64 | + "src/SessionBuilder.js", |
| 65 | + "src/SessionCipher.js", |
| 66 | + "src/SessionLock.js", |
| 67 | + "src/NumericFingerprint.js", |
| 68 | + ], |
| 69 | + dest: "dist/libsignal-protocol.js", |
| 70 | + options: { |
| 71 | + banner: ";(function(){\nvar Internal = {};\nwindow.libsignal = {};\n", |
| 72 | + footer: "\n})();", |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + compile: { |
| 77 | + curve25519_compiled: { |
| 78 | + src_files: [ |
| 79 | + "native/ed25519/*.c", |
| 80 | + "native/ed25519/additions/*.c", |
| 81 | + "native/ed25519/nacl_sha512/*.c", |
| 82 | + "native/curve25519-donna.c", |
| 83 | + "native/ed25519/sha512/sha2big.c", |
| 84 | + ], |
| 85 | + methods: [ |
| 86 | + "curve25519_donna", |
| 87 | + "curve25519_sign", |
| 88 | + "curve25519_verify", |
| 89 | + "crypto_sign_ed25519_ref10_ge_scalarmult_base", |
| 90 | + "sph_sha512_init", |
| 91 | + "malloc", |
| 92 | + "free", |
| 93 | + "xed25519_sign", |
| 94 | + ], |
| 95 | + }, |
| 96 | + }, |
| 97 | + |
| 98 | + watch: { |
| 99 | + worker: { |
| 100 | + files: ["<%= concat.worker.src %>"], |
| 101 | + tasks: ["concat:worker"], |
| 102 | + }, |
| 103 | + libsignalprotocol: { |
| 104 | + files: ["<%= concat.libsignalprotocol.src %>"], |
| 105 | + tasks: ["concat:libsignalprotocol"], |
| 106 | + }, |
| 107 | + protos: { |
| 108 | + files: ["<%= concat.protos.src %>"], |
| 109 | + tasks: ["concat:protos_concat"], |
| 110 | + }, |
| 111 | + protos_concat: { |
| 112 | + files: ["<%= concat.protos_concat.src %>"], |
| 113 | + tasks: ["concat:protos_concat"], |
| 114 | + }, |
| 115 | + }, |
| 116 | + }); |
| 117 | + |
| 118 | + Object.keys(grunt.config.get("pkg").devDependencies).forEach(function (key) { |
| 119 | + if (/^grunt(?!(-cli)?$)/.test(key)) { |
| 120 | + // ignore grunt and grunt-cli |
| 121 | + grunt.loadNpmTasks(key); |
108 | 122 | } |
109 | | - }, |
110 | | - |
111 | | - watch: { |
112 | | - worker: { |
113 | | - files: ['<%= concat.worker.src %>'], |
114 | | - tasks: ['concat:worker'] |
115 | | - }, |
116 | | - libsignalprotocol: { |
117 | | - files: ['<%= concat.libsignalprotocol.src %>'], |
118 | | - tasks: ['concat:libsignalprotocol'] |
119 | | - }, |
120 | | - protos: { |
121 | | - files: ['<%= concat.protos.src %>'], |
122 | | - tasks: ['concat:protos_concat'] |
123 | | - }, |
124 | | - protos_concat: { |
125 | | - files: ['<%= concat.protos_concat.src %>'], |
126 | | - tasks: ['concat:protos_concat'] |
127 | | - } |
128 | | - }, |
129 | | - }); |
130 | | - |
131 | | - Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) { |
132 | | - if (/^grunt(?!(-cli)?$)/.test(key)) { // ignore grunt and grunt-cli |
133 | | - grunt.loadNpmTasks(key); |
134 | | - } |
135 | | - }); |
136 | | - |
137 | | - grunt.registerMultiTask('compile', 'Compile the C libraries with emscripten.', function() { |
138 | | - const callback = this.async(); |
139 | | - const outfile = 'build/' + this.target + '.js'; |
140 | | - |
141 | | - const exported_functions = this.data.methods.map(function(name) { |
142 | | - return "'_" + name + "'"; |
143 | | - }); |
144 | | - const flags = [ |
145 | | - '-O1', |
146 | | - '-Qunused-arguments', |
147 | | - '-o', outfile, |
148 | | - '-Inative/ed25519/nacl_includes -Inative/ed25519 -Inative/ed25519/sha512', |
149 | | - '-s', "EXPORTED_FUNCTIONS=\"[" + exported_functions.join(',') + "]\""]; |
150 | | - |
151 | | - const command = [].concat('emcc', this.data.src_files, flags).join(' '); |
152 | | - grunt.log.writeln('Compiling via emscripten to ' + outfile); |
153 | | - |
154 | | - const exitCode = 0; |
155 | | - grunt.verbose.subhead(command); |
156 | | - grunt.verbose.writeln(util.format('Expecting exit code %d', exitCode)); |
157 | | - |
158 | | - const child = child_process.exec(command); |
159 | | - child.stdout.on('data', function (d) { grunt.log.write(d); }); |
160 | | - child.stderr.on('data', function (d) { grunt.log.error(d); }); |
161 | | - child.on('exit', function(code) { |
162 | | - if (code !== exitCode) { |
163 | | - grunt.log.error(util.format('Exited with code: %d.', code)); |
164 | | - return callback(false); |
165 | | - } |
166 | | - |
167 | | - grunt.verbose.ok(util.format('Exited with code: %d.', code)); |
168 | | - callback(true); |
169 | | - }); |
170 | | - }); |
| 123 | + }); |
| 124 | + |
| 125 | + grunt.registerMultiTask("compile", "Compile the C libraries with emscripten.", function () { |
| 126 | + const callback = this.async(); |
| 127 | + const outfile = "build/" + this.target + ".js"; |
| 128 | + |
| 129 | + const exported_functions = this.data.methods.map(function (name) { |
| 130 | + return "'_" + name + "'"; |
| 131 | + }); |
| 132 | + const flags = [ |
| 133 | + "-O1", |
| 134 | + "-Qunused-arguments", |
| 135 | + "-o", |
| 136 | + outfile, |
| 137 | + "-Inative/ed25519/nacl_includes -Inative/ed25519 -Inative/ed25519/sha512", |
| 138 | + "-s", |
| 139 | + 'EXPORTED_FUNCTIONS="[' + exported_functions.join(",") + ']"', |
| 140 | + ]; |
| 141 | + |
| 142 | + const command = [].concat("emcc", this.data.src_files, flags).join(" "); |
| 143 | + grunt.log.writeln("Compiling via emscripten to " + outfile); |
| 144 | + |
| 145 | + const exitCode = 0; |
| 146 | + grunt.verbose.subhead(command); |
| 147 | + grunt.verbose.writeln(util.format("Expecting exit code %d", exitCode)); |
| 148 | + |
| 149 | + const child = child_process.exec(command); |
| 150 | + child.stdout.on("data", function (d) { |
| 151 | + grunt.log.write(d); |
| 152 | + }); |
| 153 | + child.stderr.on("data", function (d) { |
| 154 | + grunt.log.error(d); |
| 155 | + }); |
| 156 | + child.on("exit", function (code) { |
| 157 | + if (code !== exitCode) { |
| 158 | + grunt.log.error(util.format("Exited with code: %d.", code)); |
| 159 | + return callback(false); |
| 160 | + } |
171 | 161 |
|
172 | | - grunt.registerTask('dev', ['watch']); |
173 | | - grunt.registerTask('default', ['concat']); |
174 | | - grunt.registerTask('build', ['compile', 'concat']); |
| 162 | + grunt.verbose.ok(util.format("Exited with code: %d.", code)); |
| 163 | + callback(true); |
| 164 | + }); |
| 165 | + }); |
175 | 166 |
|
| 167 | + grunt.registerTask("dev", ["watch"]); |
| 168 | + grunt.registerTask("default", ["concat"]); |
| 169 | + grunt.registerTask("build", ["compile", "concat"]); |
176 | 170 | }; |
0 commit comments