Skip to content

Commit 65009d4

Browse files
committed
Merging Coinbase changes selectively
1 parent dc4b8d7 commit 65009d4

File tree

13 files changed

+109
-93
lines changed

13 files changed

+109
-93
lines changed

.circleci/.bazelrc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
build --verbose_failures --spawn_strategy=standalone --strategy=Genrule=standalone --show_timestamps --show_progress --show_progress_rate_limit 0.5
2-
test --spawn_strategy=standalone
1+
# Common options
32
common --color=yes
4-
startup --max_idle_secs=1
5-
test --verbose_failures --test_output=errors --test_verbose_timeout_warnings --show_progress --show_progress_rate_limit 0.5
6-
run --verbose_failures --show_progress --show_progress_rate_limit 0.5
3+
common --verbose_failures
4+
common --show_progress
5+
common --show_progress_rate_limit=0.5
6+
7+
# Build options
8+
build --spawn_strategy=standalone
9+
build --strategy=Genrule=standalone
10+
build --show_timestamps
11+
build --curses=no
12+
build --jobs=10
13+
14+
# Test options
15+
test --spawn_strategy=standalone
16+
test --test_output=all
17+
test --test_verbose_timeout_warnings

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ container_pull(
9191
repository = "library/ruby",
9292
)
9393

94-
load("@bazelruby_ruby_rules//ruby:defs.bzl", "bundle_install")
94+
load("@bazelruby_ruby_rules//ruby:defs.bzl", "ruby_bundle")
9595

96-
bundle_install(
96+
ruby_bundle(
9797
name = "bundle",
9898
bundler_version = "2.1.2",
9999
excludes = {

examples/simple_script/BUILD.bazel

Lines changed: 26 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,43 @@
1-
package(default_visibility = ["//:__subpackages__"])
2-
31
load(
42
"@bazelruby_ruby_rules//ruby:defs.bzl",
53
"ruby_binary",
6-
"ruby_library",
74
"ruby_rspec",
5+
"ruby_rubocop",
86
"ruby_test",
97
)
108

11-
filegroup(
12-
name = "sources",
13-
srcs = glob([
14-
"script.rb",
15-
"lib/*.rb",
16-
]),
17-
)
18-
19-
filegroup(
20-
name = "spec_sources",
21-
srcs = glob([
22-
"spec/**/*.rb",
23-
]),
24-
)
25-
26-
ruby_library(
27-
name = "lib",
28-
srcs = [
29-
":sources",
30-
":spec_sources",
31-
],
32-
deps = [
33-
"@bundle//:awesome_print",
34-
"@bundle//:colored2",
35-
],
36-
)
9+
package(default_visibility = ["//:__subpackages__"])
3710

3811
ruby_binary(
3912
name = "bin",
4013
srcs = ["script.rb"],
4114
main = "script.rb",
4215
deps = [
43-
":lib",
4416
"//lib:foo",
4517
"@bundle//:awesome_print",
46-
"@bundle//:colored2",
47-
],
48-
)
49-
50-
ruby_binary(
51-
name = "bin-all",
52-
srcs = ["script.rb"],
53-
main = "script.rb",
54-
deps = [
55-
":lib",
56-
"//lib:foo",
57-
"@bundle//:bin",
5818
],
5919
)
6020

6121
# This is an example of the RSpec definition that uses autorun
6222
# and points to spec_helper as the main spec file. It specifies
6323
# which specs to run using the args.
24+
6425
ruby_test(
65-
name = "rspec-autorun",
26+
name = "all-specs",
6627
timeout = "short",
6728
srcs = [
68-
":sources",
69-
":spec_sources",
70-
],
71-
args = [
72-
"--format documentation",
73-
"--force-color",
29+
"script.rb",
30+
"//lib:foo",
7431
] + glob([
7532
"spec/**/*.rb",
7633
]),
77-
main = "spec/spec_helper.rb",
78-
rubyopt = ["-rrspec/autorun"],
79-
deps = [
80-
"@bundle//:gems",
81-
],
82-
)
83-
84-
# This is a similar example, except instead of using rubyopt to load
85-
# rspec, we execute rspec executable located in the bin folder under
86-
# the bundle, accessible via @bundle//:bin/rspec
87-
ruby_test(
88-
name = "rspec-binary",
89-
timeout = "short",
90-
srcs = [
91-
":sources",
92-
":spec_sources",
93-
"@bundle//:bin/rspec",
94-
],
9534
args = [
96-
"--format documentation",
97-
"--force-color",
9835
"spec",
9936
],
10037
main = "@bundle//:bin/rspec",
10138
deps = [
10239
"@bundle//:awesome_print",
10340
"@bundle//:bin",
104-
"@bundle//:colored2",
10541
"@bundle//:rspec",
10642
"@bundle//:rspec-its",
10743
],
@@ -115,8 +51,8 @@ ruby_test(
11551
ruby_rspec(
11652
name = "ruby-rspec-test",
11753
srcs = [
118-
":sources",
119-
":spec_sources",
54+
"script.rb",
55+
"//lib:foo",
12056
],
12157
rspec_args = {
12258
# NOTE: the output is only visible with --test_output=streamed flag
@@ -127,26 +63,34 @@ ruby_rspec(
12763
]),
12864
deps = [
12965
"@bundle//:awesome_print",
130-
"@bundle//:colored2",
13166
],
13267
)
13368

13469
ruby_binary(
135-
name = "rubocop",
70+
name = "rubocop-bin",
13671
srcs = [
137-
".relaxed-rubocop-2.4.yml",
138-
".rubocop.yml",
139-
],
72+
"script.rb",
73+
"//lib:foo",
74+
] + glob([
75+
"spec/**/*.rb",
76+
]),
14077
args = [
141-
"-c",
142-
".rubocop.yml",
143-
"-P",
144-
"-D",
78+
"-- *.rb spec/*.rb lib/*.rb -a",
14579
],
14680
main = "@bundle//:bin/rubocop",
14781
deps = [
148-
":lib",
14982
"//lib:foo",
15083
"@bundle//:bin",
15184
],
15285
)
86+
87+
# Rubocop rule
88+
# To check
89+
# bazel run rubocop -- -a
90+
ruby_rubocop(
91+
name = "rubocop",
92+
bin = "@bundle//:bin/rubocop",
93+
deps = [
94+
"@bundle//:rubocop",
95+
],
96+
)

examples/simple_script/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ bundle lock --update
1515
Run rubocop with:
1616

1717
```
18-
bazel run :rubocop -- $(pwd)/* -a
18+
bazel run //:rubocop
1919
```

examples/simple_script/script.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'colored2'
43
require 'openssl'
54
require 'awesome_print'
65

examples/simple_script/spec/script_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4-
require_relative '../script'
4+
require 'script'
55

66
describe 'oss_rand' do
77
it 'generates a String' do

ruby/defs.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ load(
2020
_ruby_rspec = "ruby_rspec",
2121
_ruby_rspec_test = "ruby_rspec_test",
2222
)
23+
load(
24+
"@bazelruby_ruby_rules//ruby/private/rubocop:def.bzl",
25+
_rubocop = "rubocop",
26+
)
2327

2428
ruby_toolchain = _toolchain
2529
ruby_library = _library
2630
ruby_binary = _binary
2731
ruby_test = _test
2832
ruby_rspec_test = _ruby_rspec_test
2933
ruby_rspec = _ruby_rspec
30-
bundle_install = _ruby_bundle
3134
ruby_bundle = _ruby_bundle
35+
ruby_rubocop = _rubocop
36+
37+
rb_toolchain = _toolchain
38+
rb_library = _library
39+
rb_binary = _binary
40+
rb_test = _test
41+
rb_rspec = _ruby_rspec
42+
rb_bundle = _ruby_bundle
43+
rb_rubocop = _rubocop

ruby/private/binary.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ def _to_manifest_path(ctx, file):
1010
else:
1111
return ("%s/%s" % (ctx.workspace_name, file.short_path))
1212

13+
def _get_gem_path(incpaths):
14+
"""
15+
incpaths is a list of `<bundle_name>/lib/ruby/<version>/gems/<gemname>-<gemversion>/lib`
16+
The gem_path is `<bundle_name>/lib/ruby/<version>` so we can go from an incpath to the
17+
gem_path pretty easily without much additional work.
18+
"""
19+
if len(incpaths) == 0:
20+
return ""
21+
incpath = incpaths[0]
22+
return incpath.rsplit("/", 3)[0]
23+
1324
# Having this function allows us to override otherwise frozen attributes
1425
# such as main, srcs and deps. We use this in ruby_rspec_test rule by
1526
# adding rspec as a main, and sources, and rspec gem as a dependency.
@@ -41,6 +52,8 @@ def ruby_binary_macro(ctx, main, srcs):
4152
extra_deps = ctx.attr._misc_deps,
4253
)
4354

55+
gem_path = _get_gem_path(deps.incpaths.to_list())
56+
4457
rubyopt = reversed(deps.rubyopt.to_list())
4558

4659
ctx.actions.expand_template(
@@ -51,6 +64,7 @@ def ruby_binary_macro(ctx, main, srcs):
5164
"{rubyopt}": repr(rubyopt),
5265
"{main}": repr(_to_manifest_path(ctx, main)),
5366
"{interpreter}": _to_manifest_path(ctx, interpreter),
67+
"{gem_path}": gem_path,
5468
},
5569
)
5670

ruby/private/binary_wrapper.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def main(args)
103103
runfiles_envkey, runfiles_envvalue = runfiles_envvar(runfiles)
104104
ENV[runfiles_envkey] = runfiles_envvalue if runfiles_envkey
105105

106+
ENV["GEM_PATH"] = File.join(runfiles, "{gem_path}") if "{gem_path}"
107+
106108
ruby_program = find_ruby_binary
107109

108110
main = {main}

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
include = [
3636
".bundle/config",
3737
"{gem_lib_files}",
38+
"lib/ruby/{ruby_version}/specifications/{name}-{version}.gemspec",
3839
{gem_binaries}
3940
],
4041
exclude = {exclude},
4142
),
43+
rubyopt = ["{bundler_setup}"],
4244
deps = {deps},
4345
includes = ["lib/ruby/{ruby_version}/gems/{name}-{version}/lib"],
4446
)
@@ -49,6 +51,7 @@
4951
name = "gems",
5052
srcs = glob([{bundle_lib_files}]) + glob(["bin/*"]),
5153
includes = {bundle_lib_paths},
54+
rubyopt = ["{bundler_setup}"],
5255
)
5356
5457
ruby_library(

0 commit comments

Comments
 (0)