summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn58
-rw-r--r--proto_library.gni50
2 files changed, 106 insertions, 2 deletions
diff --git a/BUILD.gn b/BUILD.gn
index e6b0031..695c0a3 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/sanitizers/sanitizers.gni")
+import("//third_party/closure_compiler/compile_js.gni")
config("protobuf_config") {
include_dirs = [ "src" ]
@@ -676,3 +677,60 @@ group("py_proto_runtime") {
data += get_target_outputs(":copy_google_protobuf")
data += get_target_outputs(":copy_google_protobuf_internal")
}
+
+# JS protobuf library.
+js_library("js_proto") {
+ sources = [
+ "//third_party/google-closure-library/closure/goog/array/array.js",
+ "//third_party/google-closure-library/closure/goog/asserts/asserts.js",
+ "//third_party/google-closure-library/closure/goog/base.js",
+ "//third_party/google-closure-library/closure/goog/crypt/base64.js",
+ "//third_party/google-closure-library/closure/goog/crypt/crypt.js",
+ "//third_party/google-closure-library/closure/goog/debug/error.js",
+ "//third_party/google-closure-library/closure/goog/dom/asserts.js",
+ "//third_party/google-closure-library/closure/goog/dom/browserfeature.js",
+ "//third_party/google-closure-library/closure/goog/dom/dom.js",
+ "//third_party/google-closure-library/closure/goog/dom/htmlelement.js",
+ "//third_party/google-closure-library/closure/goog/dom/nodetype.js",
+ "//third_party/google-closure-library/closure/goog/dom/safe.js",
+ "//third_party/google-closure-library/closure/goog/dom/tagname.js",
+ "//third_party/google-closure-library/closure/goog/dom/tags.js",
+ "//third_party/google-closure-library/closure/goog/fs/url.js",
+ "//third_party/google-closure-library/closure/goog/functions/functions.js",
+ "//third_party/google-closure-library/closure/goog/goog.js",
+ "//third_party/google-closure-library/closure/goog/html/safehtml.js",
+ "//third_party/google-closure-library/closure/goog/html/safescript.js",
+ "//third_party/google-closure-library/closure/goog/html/safestyle.js",
+ "//third_party/google-closure-library/closure/goog/html/safestylesheet.js",
+ "//third_party/google-closure-library/closure/goog/html/safeurl.js",
+ "//third_party/google-closure-library/closure/goog/html/trustedresourceurl.js",
+ "//third_party/google-closure-library/closure/goog/html/trustedtypes.js",
+ "//third_party/google-closure-library/closure/goog/html/uncheckedconversions.js",
+ "//third_party/google-closure-library/closure/goog/i18n/bidi.js",
+ "//third_party/google-closure-library/closure/goog/labs/useragent/browser.js",
+ "//third_party/google-closure-library/closure/goog/labs/useragent/engine.js",
+ "//third_party/google-closure-library/closure/goog/labs/useragent/platform.js",
+ "//third_party/google-closure-library/closure/goog/labs/useragent/util.js",
+ "//third_party/google-closure-library/closure/goog/math/coordinate.js",
+ "//third_party/google-closure-library/closure/goog/math/math.js",
+ "//third_party/google-closure-library/closure/goog/math/size.js",
+ "//third_party/google-closure-library/closure/goog/memoize/memoize.js",
+ "//third_party/google-closure-library/closure/goog/object/object.js",
+ "//third_party/google-closure-library/closure/goog/reflect/reflect.js",
+ "//third_party/google-closure-library/closure/goog/string/const.js",
+ "//third_party/google-closure-library/closure/goog/string/internal.js",
+ "//third_party/google-closure-library/closure/goog/string/string.js",
+ "//third_party/google-closure-library/closure/goog/string/typedstring.js",
+ "//third_party/google-closure-library/closure/goog/useragent/product.js",
+ "//third_party/google-closure-library/closure/goog/useragent/useragent.js",
+ "js/binary/arith.js",
+ "js/binary/constants.js",
+ "js/binary/decoder.js",
+ "js/binary/encoder.js",
+ "js/binary/reader.js",
+ "js/binary/utils.js",
+ "js/binary/writer.js",
+ "js/map.js",
+ "js/message.js",
+ ]
+}
diff --git a/proto_library.gni b/proto_library.gni
index 87a94d3..71b264c 100644
--- a/proto_library.gni
+++ b/proto_library.gni
@@ -25,6 +25,9 @@
# generate_cc (optional, default true)
# Generate C++ protobuf stubs.
#
+# generate_javascript (optional, default false)
+# Generate Javascript protobuf stubs.
+#
# cc_generator_options (optional)
# List of extra flags passed to the protocol compiler. If you need to
# add an EXPORT macro to a protobuf's C++ header, set the
@@ -117,6 +120,7 @@
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/kythe.gni")
+import("//third_party/closure_compiler/compile_js.gni")
if (host_os == "win") {
_host_executable_suffix = ".exe"
@@ -150,6 +154,12 @@ template("proto_library") {
generate_python = true
}
+ if (defined(invoker.generate_javascript)) {
+ generate_javascript = invoker.generate_javascript
+ } else {
+ generate_javascript = false
+ }
+
if (defined(invoker.generator_plugin_label)) {
# Straightforward way to get the name of executable doesn't work because
# |root_out_dir| and |root_build_dir| may differ in cross-compilation and
@@ -221,10 +231,15 @@ template("proto_library") {
py_out_dir = "$root_out_dir/pyproto/" + proto_out_dir
rel_py_out_dir = rebase_path(py_out_dir, root_build_dir)
}
+ if (generate_javascript) {
+ js_out_dir = "$root_out_dir/jsproto/" + proto_out_dir
+ rel_js_out_dir = rebase_path(js_out_dir, root_build_dir)
+ }
protos = rebase_path(invoker.sources, proto_in_dir)
protogens = []
protogens_cc = []
+ protogens_js = []
# List output files.
foreach(proto, protos) {
@@ -246,17 +261,24 @@ template("proto_library") {
protogens_cc += [ "$cc_out_dir/${proto_path}${suffix}" ]
}
}
+ if (generate_javascript) {
+ protogens_js += [ "$js_out_dir/${proto_path}.js" ]
+ }
}
action_name = "${target_name}_gen"
source_set_name = target_name
+ javascript_name = "${target_name}_js"
# Generate protobuf stubs.
action(action_name) {
- visibility = [ ":$source_set_name" ]
+ visibility = [
+ ":$source_set_name",
+ ":$javascript_name",
+ ]
script = "//tools/protoc_wrapper/protoc_wrapper.py"
sources = proto_sources
- outputs = get_path_info(protogens + protogens_cc, "abspath")
+ outputs = get_path_info(protogens + protogens_cc + protogens_js, "abspath")
args = protos
if (defined(invoker.testonly)) {
@@ -302,6 +324,13 @@ template("proto_library") {
]
}
+ if (generate_javascript) {
+ args += [
+ "--js-out-dir",
+ rel_js_out_dir,
+ ]
+ }
+
if (generate_with_plugin) {
args += [
"--plugin",
@@ -373,6 +402,23 @@ template("proto_library") {
}
}
+ # Build generated javascript stubs.
+ if (generate_javascript) {
+ js_library(javascript_name) {
+ forward_variables_from(invoker,
+ [
+ "testonly",
+ "visibility",
+ ])
+
+ sources = protogens_js
+
+ deps = [ "//third_party/protobuf:js_proto" ]
+
+ extra_deps = [ ":$action_name" ]
+ }
+ }
+
# Build generated protobuf stubs as libary or source set.
target(link_target_type, target_name) {
forward_variables_from(invoker,