Skip to content

Commit f704b22

Browse files
committed
Merge branch 'main' of github.com:protocolbuffers/protobuf-javascript
� Conflicts: � gulpfile.js
2 parents d936c51 + cb8c3ab commit f704b22

30 files changed

+159
-76
lines changed

BUILD

-29
This file was deleted.

BUILD.bazel

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Protobuf JS runtime
2+
#
3+
# See also code generation logic under generator/
4+
5+
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
6+
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
7+
load("//:protobuf_javascript_release.bzl", "package_naming")
8+
9+
package_naming(
10+
name = "protobuf_javascript_pkg_naming",
11+
)
12+
13+
pkg_files(
14+
name = "plugin_files",
15+
srcs = ["//generator:protoc-gen-js"],
16+
attributes = pkg_attributes(mode = "0555"),
17+
prefix = "bin/",
18+
)
19+
20+
pkg_files(
21+
name = "dist_files",
22+
srcs = glob([
23+
"google/protobuf/*.js",
24+
"google/protobuf/compiler/*.js"
25+
]) + [
26+
"google-protobuf.js",
27+
"package.json",
28+
"README.md",
29+
"LICENSE.md",
30+
],
31+
strip_prefix = strip_prefix.from_root(""),
32+
)
33+
34+
pkg_tar(
35+
name = "dist_tar",
36+
srcs = [
37+
":dist_files",
38+
":plugin_files",
39+
],
40+
extension = "tar.gz",
41+
package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz",
42+
package_variables = ":protobuf_javascript_pkg_naming",
43+
)
44+
45+
pkg_zip(
46+
name = "dist_zip",
47+
srcs = [
48+
":dist_files",
49+
":plugin_files",
50+
],
51+
package_file_name = "protobuf-javascript-{version}-{platform}.zip",
52+
package_variables = ":protobuf_javascript_pkg_naming",
53+
)
54+
55+
filegroup(
56+
name = "dist_all",
57+
srcs = [
58+
":dist_tar",
59+
":dist_zip",
60+
]
61+
)

LICENSE renamed to LICENSE.md

File renamed without changes.

WORKSPACE

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ http_archive(
1111
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
1212

1313
protobuf_deps()
14+
15+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
16+
rules_pkg_dependencies()

binary/proto_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ goog.require('goog.testing.asserts');
3535
goog.require('jspb.BinaryWriter');
3636
goog.require('jspb.Message');
3737

38-
// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test
38+
// CommonJS-LoadFromFile: ../protos/testbinary_pb proto.jspb.test
3939
goog.require('proto.jspb.test.ExtendsWithMessage');
4040
goog.require('proto.jspb.test.ForeignEnum');
4141
goog.require('proto.jspb.test.ForeignMessage');

commonjs/strict_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var global = Function('return this')();
3939
// Bring asserts into the global namespace.
4040
googleProtobuf.object.extend(global, asserts);
4141

42-
var test9_pb = require('./test9_pb');
43-
var test10_pb = require('./test10_pb');
42+
var test9_pb = require('./protos/test9_pb');
43+
var test10_pb = require('./protos/test10_pb');
4444

4545
describe('Strict test suite', function() {
4646
it('testImportedMessage', function() {

generator/BUILD renamed to generator/BUILD.bazel

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ cc_binary(
99
],
1010
visibility = ["//visibility:public"],
1111
deps = [
12-
#"@com_google_absl//absl/base:core_headers",
13-
#"@com_google_absl//absl/container:flat_hash_map",
14-
#"@com_google_absl//absl/container:flat_hash_set",
15-
#"@com_google_absl//absl/strings",
1612
"@com_google_protobuf//:protobuf",
1713
"@com_google_protobuf//:protoc_lib",
1814
],
1915
)
16+

gulpfile.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ const wellKnownTypes = [
2828
wellKnownTypes.forEach((path) => protocInc + '/' + path);
2929

3030
const group1Protos = [
31-
'data.proto',
32-
'test3.proto',
33-
'test5.proto',
31+
'protos/data.proto',
32+
'protos/test3.proto',
33+
'protos/test5.proto',
3434
'commonjs/test6/test6.proto',
35-
'test8.proto',
36-
'test11.proto',
37-
'test12.proto',
38-
'test13.proto',
39-
'test14.proto',
40-
'test15.proto',
41-
'testbinary.proto',
42-
'testempty.proto',
43-
'test.proto',
44-
'testlargenumbers.proto',
35+
'protos/test8.proto',
36+
'protos/test11.proto',
37+
'protos/test12.proto',
38+
'protos/test13.proto',
39+
'protos/test14.proto',
40+
'protos/test15.proto',
41+
'protos/testbinary.proto',
42+
'protos/testempty.proto',
43+
'protos/test.proto',
44+
'protos/testlargenumbers.proto',
4545
];
4646

4747
const group2Protos = [
48-
'proto3_test.proto',
49-
'test2.proto',
50-
'test4.proto',
48+
'protos/proto3_test.proto',
49+
'protos/test2.proto',
50+
'protos/test4.proto',
5151
'commonjs/test7/test7.proto',
5252
];
5353

5454
const group3Protos = [
55-
'test9.proto',
56-
'test10.proto'
55+
'protos/test9.proto',
56+
'protos/test10.proto'
5757
];
5858

5959
function make_exec_logging_callback(cb) {

maps_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ goog.require('goog.testing.asserts');
3232
goog.require('goog.testing.TestCase');
3333
goog.require('goog.userAgent');
3434

35-
// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
35+
// CommonJS-LoadFromFile: protos/testbinary_pb proto.jspb.test
3636
goog.require('proto.jspb.test.MapValueEnum');
3737
goog.require('proto.jspb.test.MapValueMessage');
3838
goog.require('proto.jspb.test.TestMapFields');
@@ -50,7 +50,7 @@ goog.require('proto.jspb.test.MapEntryOptionalValuesDoubleValue');
5050
goog.require('proto.jspb.test.MapEntryOptionalValuesEnumValue');
5151
goog.require('proto.jspb.test.MapEntryOptionalValuesMessageValue');
5252

53-
// CommonJS-LoadFromFile: test_pb proto.jspb.test
53+
// CommonJS-LoadFromFile: protos/test_pb proto.jspb.test
5454
goog.require('proto.jspb.test.MapValueMessageNoBinary');
5555
goog.require('proto.jspb.test.TestMapFieldsNoBinary');
5656

message_test.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ goog.require('goog.testing.asserts');
3737
goog.require('goog.testing.TestCase');
3838
goog.require('goog.userAgent');
3939

40-
// CommonJS-LoadFromFile: google-protobuf jspb
40+
// CommonJS-LoadFromFile: protos/google-protobuf jspb
4141
goog.require('jspb.Message');
4242

43-
// CommonJS-LoadFromFile: test15_pb proto.jspb.filenametest.package1
43+
// CommonJS-LoadFromFile: protos/test15_pb proto.jspb.filenametest.package1
4444
goog.require('proto.jspb.filenametest.package1.b');
4545

46-
// CommonJS-LoadFromFile: test14_pb proto.jspb.filenametest.package2
46+
// CommonJS-LoadFromFile: protos/test14_pb proto.jspb.filenametest.package2
4747
goog.require('proto.jspb.filenametest.package2.TestMessage');
4848

49-
// CommonJS-LoadFromFile: test13_pb proto.jspb.filenametest.package1
49+
// CommonJS-LoadFromFile: protos/test13_pb proto.jspb.filenametest.package1
5050
goog.require('proto.jspb.filenametest.package1.a');
5151
goog.require('proto.jspb.filenametest.package1.TestMessage');
5252

53-
// CommonJS-LoadFromFile: test12_pb proto.jspb.circulartest
53+
// CommonJS-LoadFromFile: protos/test12_pb proto.jspb.circulartest
5454
goog.require('proto.jspb.circulartest.ExtensionContainingType1');
5555
goog.require('proto.jspb.circulartest.ExtensionContainingType2');
5656
goog.require('proto.jspb.circulartest.ExtensionField1');
@@ -67,25 +67,25 @@ goog.require('proto.jspb.circulartest.NestedMessage2');
6767
goog.require('proto.jspb.circulartest.RepeatedMessageField1');
6868
goog.require('proto.jspb.circulartest.RepeatedMessageField2');
6969

70-
// CommonJS-LoadFromFile: test11_pb proto.jspb.exttest.reverse
70+
// CommonJS-LoadFromFile: protos/test11_pb proto.jspb.exttest.reverse
7171
goog.require('proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1');
7272
goog.require('proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage2');
7373
goog.require('proto.jspb.exttest.reverse.c');
7474

75-
// CommonJS-LoadFromFile: test8_pb proto.jspb.exttest.nested
75+
// CommonJS-LoadFromFile: protos/test8_pb proto.jspb.exttest.nested
7676
goog.require('proto.jspb.exttest.nested.TestNestedExtensionsMessage');
7777
goog.require('proto.jspb.exttest.nested.TestOuterMessage');
7878

79-
// CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta
79+
// CommonJS-LoadFromFile: protos/test5_pb proto.jspb.exttest.beta
8080
goog.require('proto.jspb.exttest.beta.floatingStrField');
8181

82-
// CommonJS-LoadFromFile: test3_pb proto.jspb.exttest
82+
// CommonJS-LoadFromFile: protos/test3_pb proto.jspb.exttest
8383
goog.require('proto.jspb.exttest.floatingMsgField');
8484

85-
// CommonJS-LoadFromFile: test4_pb proto.jspb.exttest
85+
// CommonJS-LoadFromFile: protos/test4_pb proto.jspb.exttest
8686
goog.require('proto.jspb.exttest.floatingMsgFieldTwo');
8787

88-
// CommonJS-LoadFromFile: test_pb proto.jspb.test
88+
// CommonJS-LoadFromFile: protos/test_pb proto.jspb.test
8989
goog.require('proto.jspb.test.BooleanFields');
9090
goog.require('proto.jspb.test.CloneExtension');
9191
goog.require('proto.jspb.test.Complex');
@@ -114,12 +114,12 @@ goog.require('proto.jspb.test.TestMessageWithOneof');
114114
goog.require('proto.jspb.test.TestReservedNames');
115115
goog.require('proto.jspb.test.TestReservedNamesExtension');
116116

117-
// CommonJS-LoadFromFile: test2_pb proto.jspb.test
117+
// CommonJS-LoadFromFile: protos/test2_pb proto.jspb.test
118118
goog.require('proto.jspb.test.ExtensionMessage');
119119
goog.require('proto.jspb.test.TestExtensionsMessage');
120120

121121
goog.require('proto.jspb.test.TestAllowAliasEnum');
122-
// CommonJS-LoadFromFile: testlargenumbers_pb proto.jspb.test
122+
// CommonJS-LoadFromFile: protos/testlargenumbers_pb proto.jspb.test
123123
goog.require('proto.jspb.test.MessageWithLargeFieldNumbers');
124124

125125
goog.require('proto.jspb.test.simple1');

proto3_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
goog.require('goog.crypt.base64');
3232
goog.require('goog.testing.asserts');
33-
// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
33+
// CommonJS-LoadFromFile: protos/testbinary_pb proto.jspb.test
3434
goog.require('proto.jspb.test.ForeignMessage');
35-
// CommonJS-LoadFromFile: proto3_test_pb proto.jspb.test
35+
// CommonJS-LoadFromFile: protos/proto3_test_pb proto.jspb.test
3636
goog.require('proto.jspb.test.Proto3Enum');
3737
goog.require('proto.jspb.test.TestProto3');
3838
// CommonJS-LoadFromFile: google/protobuf/any_pb proto.google.protobuf

protobuf_javascript_release.bzl

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Generates package naming variables for use with rules_pkg.
3+
"""
4+
5+
load("@rules_pkg//:providers.bzl", "PackageVariablesInfo")
6+
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
7+
8+
_PROTOBUF_JAVASCRIPT_VERSION = '3.21.0'
9+
10+
def _package_naming_impl(ctx):
11+
values = {}
12+
values["version"] = _PROTOBUF_JAVASCRIPT_VERSION
13+
14+
# infer from the current cpp toolchain.
15+
toolchain = find_cpp_toolchain(ctx)
16+
cpu = toolchain.cpu
17+
system_name = toolchain.target_gnu_system_name
18+
19+
# rename cpus to match what we want artifacts to be
20+
if cpu == "systemz":
21+
cpu = "s390_64"
22+
elif cpu == "aarch64":
23+
cpu = "aarch_64"
24+
elif cpu == "ppc64":
25+
cpu = "ppcle_64"
26+
27+
# use the system name to determine the os and then create platform names
28+
if "apple" in system_name:
29+
values["platform"] = "osx-" + cpu
30+
elif "linux" in system_name:
31+
values["platform"] = "linux-" + cpu
32+
elif "mingw" in system_name:
33+
if cpu == "x86_64":
34+
values["platform"] = "win64"
35+
else:
36+
values["platform"] = "win32"
37+
else:
38+
values["platform"] = "unknown"
39+
40+
return PackageVariablesInfo(values = values)
41+
42+
43+
package_naming = rule(
44+
implementation = _package_naming_impl,
45+
attrs = {
46+
# Necessary data dependency for find_cpp_toolchain.
47+
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
48+
},
49+
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
50+
incompatible_use_toolchain_transition = True,
51+
)
File renamed without changes.

proto3_test.proto renamed to protos/proto3_test.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ syntax = "proto3";
3232

3333
package jspb.test;
3434

35-
import "testbinary.proto";
35+
import "protos/testbinary.proto";
3636

3737
message TestProto3 {
3838
int32 singular_int32 = 1;
File renamed without changes.

test10.proto renamed to protos/test10.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ syntax = "proto3";
3232

3333
package jspb.exttest.strict.ten;
3434

35-
import "test9.proto";
35+
import "protos/test9.proto";
3636

3737
message Simple10 {
3838
jspb.exttest.strict.nine.Simple9 a = 1;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test15.proto renamed to protos/test15.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ syntax = "proto2";
3232

3333
package jspb.filenametest.package1;
3434

35-
import "test13.proto";
35+
import "protos/test13.proto";
3636

3737
extend TestMessage {
3838
optional int32 b = 2;

test2.proto renamed to protos/test2.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ syntax = "proto2";
3232

3333
package jspb.test;
3434

35-
import "test.proto";
35+
import "protos/test.proto";
3636

3737
option java_package = "com.google.apps.jspb.proto";
3838
option java_multiple_files = true;
File renamed without changes.

test4.proto renamed to protos/test4.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ syntax = "proto2";
3232

3333
package jspb.exttest;
3434

35-
import "test3.proto";
35+
import "protos/test3.proto";
3636

3737
option java_package = "com.google.apps.jspb.proto";
3838
option java_multiple_files = true;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)