forked from bazelbuild/codelabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_build_files.sh
executable file
·141 lines (113 loc) · 3.15 KB
/
generate_build_files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# This file is used for Bazel CI to write the BUILD files for the project.
# You can use it to see the final solutions but note that it will delete your existing
# BUILD files if you started working.
# generate Go BUILD file
cat > go/cmd/server/BUILD <<EOF
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_binary(
name = "go-server",
srcs = ["server.go"],
deps = [
"//proto/logger:logger_go_proto",
"@com_github_golang_protobuf//jsonpb:go_default_library_gen",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//reflection:go_default_library",
],
visibility = ["//visibility:public"]
)
EOF
# generate java BUILD file
cat > java/src/main/java/bazel/bootcamp/BUILD <<EOF
java_binary(
name = "HelloBazelBootcamp",
srcs = ["HelloBazelBootcamp.java"],
)
java_library(
name = "JavaLoggingClientLibrary",
srcs = ["JavaLoggingClientLibrary.java"],
deps = [
"//proto/logger:logger_java_proto",
"//proto/logger:logger_java_grpc",
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//netty",
]
)
java_binary(
name = "JavaLoggingClient",
srcs = ["JavaLoggingClient.java"],
deps = [":JavaLoggingClientLibrary"],
visibility = ["//visibility:public"]
)
java_test(
name = "JavaLoggingClientLibraryTest",
srcs = ["JavaLoggingClientLibraryTest.java"],
deps = [":JavaLoggingClientLibrary"]
)
java_test(
name = "JavaLoggingClientTest",
srcs = ["JavaLoggingClientTest.java"],
deps = [":JavaLoggingClient"]
)
EOF
# generate proto BUILD file
cat > proto/logger/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@npm_bazel_typescript//:index.bzl", "ts_proto_library")
proto_library(
name = "logger_proto",
srcs = ["logger.proto"]
)
go_proto_library(
name = "logger_go_proto",
proto = ":logger_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "bootcamp/proto/logger"
)
java_proto_library(
name = "logger_java_proto",
deps = [":logger_proto"]
)
java_grpc_library(
name = "logger_java_grpc",
srcs = [":logger_proto"],
deps = [":logger_java_proto"],
)
ts_proto_library(
name = "logger_ts_proto",
deps = [":logger_proto"]
)
EOF
# write shell test
cat > tests/BUILD <<EOF
sh_test(
name = "integration_test",
srcs = ["integrationtest.sh"],
data = [
"//go/cmd/server:go-server",
"//java/src/main/java/bazel/bootcamp:JavaLoggingClient",
],
tags = ["exclusive"]
)
EOF
cat > typescript/BUILD <<EOF
load("@npm_bazel_typescript//:index.bzl", "ts_library", "ts_devserver")
ts_devserver(
name = "devserver",
bootstrap = ["@npm_bazel_typescript//:protobufjs_bootstrap_scripts"],
entry_module = "bootcamp/typescript/app",
port = 8088,
deps = [":app"],
)
ts_library(
name = "app",
srcs = ["app.ts"],
deps = [
"//proto/logger:logger_ts_proto",
],
)
exports_files(["tsconfig.json"])
EOF
# write WORKSPACE file
${SHELL} ./generate_workspace.sh