From dd48f8095c3357e6ec0e66042141c4e342707da5 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 12 Jun 2018 05:16:41 +0200 Subject: Simplify pbjs build with hack. Just check in the generated files and create them using js/pbjs_hack.py. This allows vscode to be used and sane compilations. --- deno2/js/pbjs_hack.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 deno2/js/pbjs_hack.py (limited to 'deno2/js/pbjs_hack.py') diff --git a/deno2/js/pbjs_hack.py b/deno2/js/pbjs_hack.py new file mode 100755 index 000000000..f0cfa01a5 --- /dev/null +++ b/deno2/js/pbjs_hack.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +""" +gn can only run python scripts. +protobuf.js must generate some javascript files. +it's very difficult to get this into the gn build sanely. +therefore we write them into the source directory. +""" +import subprocess +import sys +import os + +js_path = os.path.dirname(os.path.realpath(__file__)) +bin_path = os.path.join(js_path, "node_modules", ".bin") +pbjs_bin = os.path.join(bin_path, "pbjs") +pbts_bin = os.path.join(bin_path, "pbts") +msg_pbjs_out = os.path.join(js_path, "msg.pb.js") +msg_pbts_out = os.path.join(js_path, "msg.pb.d.ts") +assert os.path.exists(pbjs_bin) +assert os.path.exists(pbts_bin) + +proto_in = sys.argv[1] +stamp_file = sys.argv[2] + +def touch(fname): + if os.path.exists(fname): + os.utime(fname, None) + else: + open(fname, 'a').close() + +subprocess.check_call([ + "node", + pbjs_bin, + "--target=static-module", + "--wraper=commonjs", + "--out=" + msg_pbjs_out, + proto_in +]) +assert os.path.exists(msg_pbjs_out) + +subprocess.check_call([ + "node", + pbts_bin, + "--out=" + msg_pbts_out, + msg_pbjs_out +]) +assert os.path.exists(msg_pbts_out) + + +touch(stamp_file) -- cgit v1.2.3 From 7784cc2c1537a23b8b8ffa634b1a9b1ddf88886a Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 12 Jun 2018 06:36:01 +0200 Subject: Fix protobufjs snapshotting. --- deno2/js/pbjs_hack.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'deno2/js/pbjs_hack.py') diff --git a/deno2/js/pbjs_hack.py b/deno2/js/pbjs_hack.py index f0cfa01a5..a4cc7dfb3 100755 --- a/deno2/js/pbjs_hack.py +++ b/deno2/js/pbjs_hack.py @@ -10,6 +10,7 @@ import sys import os js_path = os.path.dirname(os.path.realpath(__file__)) +#bin_path = os.path.join(js_path, "deno_protobufjs", "bin") bin_path = os.path.join(js_path, "node_modules", ".bin") pbjs_bin = os.path.join(bin_path, "pbjs") pbts_bin = os.path.join(bin_path, "pbts") @@ -28,8 +29,8 @@ def touch(fname): open(fname, 'a').close() subprocess.check_call([ - "node", pbjs_bin, + #"--dependency=./deno_protobufjs/minimal", "--target=static-module", "--wraper=commonjs", "--out=" + msg_pbjs_out, @@ -45,5 +46,4 @@ subprocess.check_call([ ]) assert os.path.exists(msg_pbts_out) - touch(stamp_file) -- cgit v1.2.3 From 1676822888ef6c75bb2afff3b7a93d030d63f2ea Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 12 Jun 2018 22:05:49 +0200 Subject: deno2: build on Windows --- deno2/js/pbjs_hack.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'deno2/js/pbjs_hack.py') diff --git a/deno2/js/pbjs_hack.py b/deno2/js/pbjs_hack.py index a4cc7dfb3..354f3a5a1 100755 --- a/deno2/js/pbjs_hack.py +++ b/deno2/js/pbjs_hack.py @@ -11,9 +11,9 @@ import os js_path = os.path.dirname(os.path.realpath(__file__)) #bin_path = os.path.join(js_path, "deno_protobufjs", "bin") -bin_path = os.path.join(js_path, "node_modules", ".bin") -pbjs_bin = os.path.join(bin_path, "pbjs") -pbts_bin = os.path.join(bin_path, "pbts") +pbjs_path = os.path.join(js_path, "node_modules", "protobufjs", "bin") +pbjs_bin = os.path.join(pbjs_path, "pbjs") +pbts_bin = os.path.join(pbjs_path, "pbts") msg_pbjs_out = os.path.join(js_path, "msg.pb.js") msg_pbts_out = os.path.join(js_path, "msg.pb.d.ts") assert os.path.exists(pbjs_bin) @@ -29,10 +29,11 @@ def touch(fname): open(fname, 'a').close() subprocess.check_call([ + "node", pbjs_bin, #"--dependency=./deno_protobufjs/minimal", "--target=static-module", - "--wraper=commonjs", + "--wrapper=commonjs", "--out=" + msg_pbjs_out, proto_in ]) -- cgit v1.2.3 From bb6222c91872695cbe98aa2a75166265f52cec2e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 13 Jun 2018 14:58:06 +0200 Subject: Clean up the build (replace browserify with parcel) --- deno2/js/pbjs_hack.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'deno2/js/pbjs_hack.py') diff --git a/deno2/js/pbjs_hack.py b/deno2/js/pbjs_hack.py index 354f3a5a1..e0e1ab06f 100755 --- a/deno2/js/pbjs_hack.py +++ b/deno2/js/pbjs_hack.py @@ -1,16 +1,21 @@ #!/usr/bin/env python """ gn can only run python scripts. -protobuf.js must generate some javascript files. -it's very difficult to get this into the gn build sanely. -therefore we write them into the source directory. + +Generates protobufjs code. """ import subprocess import sys import os +# TODO(ry) Ideally protobufjs output files should be written into +# target_gen_dir, but its difficult to get this working in a way that parcel can +# resolve their location. (Parcel does not support NODE_PATH.) Therefore this +# hack: write the generated msg.pb.js and msg.pb.d.ts outputs into the js/ +# folder, and we check them into the repo. Hopefully this hack can be removed at +# some point. If msg.proto is changed, commit changes to the generated JS +# files. js_path = os.path.dirname(os.path.realpath(__file__)) -#bin_path = os.path.join(js_path, "deno_protobufjs", "bin") pbjs_path = os.path.join(js_path, "node_modules", "protobufjs", "bin") pbjs_bin = os.path.join(pbjs_path, "pbjs") pbts_bin = os.path.join(pbjs_path, "pbts") @@ -31,7 +36,6 @@ def touch(fname): subprocess.check_call([ "node", pbjs_bin, - #"--dependency=./deno_protobufjs/minimal", "--target=static-module", "--wrapper=commonjs", "--out=" + msg_pbjs_out, -- cgit v1.2.3