Skip to content

Commit 7ae6b39

Browse files
committed
feat: Support mapping the vendor cache from workspace
It's pretty common for ruby projects to vendor their dependencies this is to help speedup install time and is probably more useful for hybrid projects rather than pure bazel ones that can use bazel caches. Needless to say it's still an important feature that will make CI faster in cases where there is no cache.
1 parent c855522 commit 7ae6b39

32 files changed

+575
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ ruby_bundle(
538538
gemfile_lock,
539539
bundler_version = "2.1.2",
540540
excludes = [],
541+
vendor_cache = False,
541542
ruby_sdk = "@org_ruby_lang_ruby_toolchain",
542543
ruby_interpreter = "@org_ruby_lang_ruby_toolchain//:ruby",
543544
)
@@ -578,6 +579,13 @@ ruby_bundle(
578579
<p>NOTE: This rule never updates the <code>Gemfile.lock</code>. It is your responsibility to generate/update <code>Gemfile.lock</code></p>
579580
</td>
580581
</tr>
582+
<tr>
583+
<td><code>vendor_cache</code></td>
584+
<td>
585+
<code>Bool, optional</code>
586+
<p>Symlink the vendor directory into the Bazel build space, this allows Bundler to access vendored Gems</p>
587+
</td>
588+
</tr>
581589
<tr>
582590
<td><code>bundler_version</code></td>
583591
<td>
@@ -615,6 +623,28 @@ ruby_bundle(
615623
)
616624
```
617625

626+
##### Vendor directory handling
627+
628+
To use the vendor cache, you have to declare a `managed_directory` in
629+
your workspace. The name should match the name of the bundle.
630+
631+
``` bazel
632+
load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_bundle")
633+
634+
workspace(
635+
name = "my_wksp",
636+
managed_directories = {"@bundle": ["vendor"]},
637+
)
638+
639+
ruby_bundle(
640+
name = "bundle",
641+
bundler_version = "2.1.2",
642+
vendor_cache = True,
643+
gemfile = "//:Gemfile",
644+
gemfile_lock = "//:Gemfile.lock",
645+
)
646+
```
647+
618648
#### `BUILD.bazel`:
619649

620650
```bazel
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bazel-*
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Relaxed.Ruby.Style
2+
## Version 2.4
3+
4+
Style/Alias:
5+
Enabled: false
6+
StyleGuide: https://relaxed.ruby.style/#stylealias
7+
8+
Style/AsciiComments:
9+
Enabled: false
10+
StyleGuide: https://relaxed.ruby.style/#styleasciicomments
11+
12+
Style/BeginBlock:
13+
Enabled: false
14+
StyleGuide: https://relaxed.ruby.style/#stylebeginblock
15+
16+
Style/BlockDelimiters:
17+
Enabled: false
18+
StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
19+
20+
Style/CommentAnnotation:
21+
Enabled: false
22+
StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
23+
24+
Style/Documentation:
25+
Enabled: false
26+
StyleGuide: https://relaxed.ruby.style/#styledocumentation
27+
28+
Layout/DotPosition:
29+
Enabled: false
30+
StyleGuide: https://relaxed.ruby.style/#layoutdotposition
31+
32+
Style/DoubleNegation:
33+
Enabled: false
34+
StyleGuide: https://relaxed.ruby.style/#styledoublenegation
35+
36+
Style/EndBlock:
37+
Enabled: false
38+
StyleGuide: https://relaxed.ruby.style/#styleendblock
39+
40+
Style/FormatString:
41+
Enabled: false
42+
StyleGuide: https://relaxed.ruby.style/#styleformatstring
43+
44+
Style/IfUnlessModifier:
45+
Enabled: false
46+
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
47+
48+
Style/Lambda:
49+
Enabled: false
50+
StyleGuide: https://relaxed.ruby.style/#stylelambda
51+
52+
Style/ModuleFunction:
53+
Enabled: false
54+
StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
55+
56+
Style/MultilineBlockChain:
57+
Enabled: false
58+
StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
59+
60+
Style/NegatedIf:
61+
Enabled: false
62+
StyleGuide: https://relaxed.ruby.style/#stylenegatedif
63+
64+
Style/NegatedWhile:
65+
Enabled: false
66+
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
67+
68+
Style/NumericPredicate:
69+
Enabled: false
70+
StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate
71+
72+
Style/ParallelAssignment:
73+
Enabled: false
74+
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
75+
76+
Style/PercentLiteralDelimiters:
77+
Enabled: false
78+
StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
79+
80+
Style/PerlBackrefs:
81+
Enabled: false
82+
StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
83+
84+
Style/Semicolon:
85+
Enabled: false
86+
StyleGuide: https://relaxed.ruby.style/#stylesemicolon
87+
88+
Style/SignalException:
89+
Enabled: false
90+
StyleGuide: https://relaxed.ruby.style/#stylesignalexception
91+
92+
Style/SingleLineBlockParams:
93+
Enabled: false
94+
StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
95+
96+
Style/SingleLineMethods:
97+
Enabled: false
98+
StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
99+
100+
Layout/SpaceBeforeBlockBraces:
101+
Enabled: false
102+
StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
103+
104+
Layout/SpaceInsideParens:
105+
Enabled: false
106+
StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
107+
108+
Layout/LineLength:
109+
Enabled: false
110+
111+
Style/SpecialGlobalVars:
112+
Enabled: false
113+
StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
114+
115+
Style/StringLiterals:
116+
Enabled: false
117+
StyleGuide: https://relaxed.ruby.style/#stylestringliterals
118+
119+
Style/TrailingCommaInArguments:
120+
Enabled: false
121+
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
122+
123+
Style/TrailingCommaInArrayLiteral:
124+
Enabled: false
125+
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
126+
127+
Style/TrailingCommaInHashLiteral:
128+
Enabled: false
129+
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
130+
131+
Style/SymbolArray:
132+
Enabled: false
133+
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
134+
135+
Style/WhileUntilModifier:
136+
Enabled: false
137+
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
138+
139+
Style/WordArray:
140+
Enabled: false
141+
StyleGuide: https://relaxed.ruby.style/#stylewordarray
142+
143+
Lint/AmbiguousRegexpLiteral:
144+
Enabled: false
145+
StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
146+
147+
Lint/AssignmentInCondition:
148+
Enabled: false
149+
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
150+
151+
Metrics/AbcSize:
152+
Enabled: false
153+
154+
Metrics/BlockNesting:
155+
Enabled: false
156+
157+
Metrics/ClassLength:
158+
Enabled: false
159+
160+
Metrics/ModuleLength:
161+
Enabled: false
162+
163+
Metrics/CyclomaticComplexity:
164+
Enabled: false
165+
166+
Metrics/MethodLength:
167+
Enabled: false
168+
169+
Metrics/ParameterLists:
170+
Enabled: false
171+
172+
Metrics/PerceivedComplexity:
173+
Enabled: false
174+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
inherit_from: .relaxed-rubocop-2.4.yml
2+
3+
AllCops:
4+
TargetRubyVersion: 2.6
5+
UseCache: true
6+
DefaultFormatter: progress
7+
DisplayStyleGuide: true
8+
DisplayCopNames: true
9+
Exclude:
10+
- "external*/**/*"
11+
- "bazel-*/**/*"
12+
- "**/examples/**/*"
13+
- "**/BUILD"
14+
- "**/*.bazel"
15+
- "**/*.bzl"
16+
- "**/rubocop"
17+
- "**/vendor/bundle/**/*"
18+
Include:
19+
- '**/*.rb'
20+
- '**/*.gemfile'
21+
- '**/*.gemspec'
22+
- '**/*.rake'
23+
- '**/*.ru'
24+
- '**/Gemfile'
25+
- '**/Rakefile'
26+
27+
Layout/HashAlignment:
28+
Enabled: true
29+
EnforcedColonStyle: table
30+
31+
Style/Dir:
32+
Enabled: false
33+
34+
# In Bazel we want to use __FILE__ because __dir__points to the actual sources
35+
Style/ExpandPathArguments:
36+
Enabled: false
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
load(
2+
"@bazelruby_rules_ruby//ruby:defs.bzl",
3+
"ruby_binary",
4+
"ruby_rspec",
5+
"ruby_rubocop",
6+
"ruby_test",
7+
)
8+
9+
package(default_visibility = ["//:__subpackages__"])
10+
11+
ruby_binary(
12+
name = "bin",
13+
srcs = ["script.rb"],
14+
main = "script.rb",
15+
deps = [
16+
"//lib:foo",
17+
],
18+
)
19+
20+
# This is an example of the RSpec definition that uses autorun
21+
# and points to spec_helper as the main spec file. It specifies
22+
# which specs to run using the args.
23+
24+
ruby_test(
25+
name = "all-specs",
26+
timeout = "short",
27+
srcs = [
28+
"script.rb",
29+
"//lib:foo",
30+
] + glob([
31+
"spec/**/*.rb",
32+
]),
33+
# This is a WORKSPACE-relative path to a spec directory.
34+
# It could be longer, like "my/path/to/spec".
35+
args = [
36+
"spec",
37+
],
38+
main = "@bundle//:bin/rspec",
39+
deps = [
40+
"@bundle//:bin",
41+
"@bundle//:rspec",
42+
"@bundle//:rspec-its",
43+
],
44+
)
45+
46+
# Finally, this is the short version of the same thing, expressed
47+
# via the ruby_rspec_test rule that does what the above example
48+
# shows but encapsulated in the rule itself. It adds rspec and rspec-its
49+
# gems to the dependency list, executes bin/rspec and passes spec_targets
50+
# as arguments to rspec.
51+
ruby_rspec(
52+
name = "ruby-rspec-test",
53+
srcs = [
54+
"script.rb",
55+
"//lib:foo",
56+
],
57+
rspec_args = {
58+
# NOTE: the output is only visible with --test_output=streamed flag
59+
"--format": "progress", # this is how we can override rspec output format
60+
},
61+
specs = glob([
62+
"spec/**/*.rb",
63+
]),
64+
deps = [],
65+
)
66+
67+
ruby_binary(
68+
name = "rubocop-bin",
69+
srcs = [
70+
"script.rb",
71+
"//lib:foo",
72+
] + glob([
73+
"spec/**/*.rb",
74+
]),
75+
args = [
76+
"-- *.rb spec/*.rb lib/*.rb -a",
77+
],
78+
main = "@bundle//:bin/rubocop",
79+
deps = [
80+
"//lib:foo",
81+
"@bundle//:bin",
82+
],
83+
)
84+
85+
# Rubocop rule
86+
# To check
87+
# bazel run rubocop -- -a
88+
ruby_rubocop(
89+
name = "rubocop",
90+
bin = "@bundle//:bin/rubocop",
91+
deps = [
92+
"@bundle//:rubocop",
93+
],
94+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'rspec', '~> 3.7.0'
6+
gem 'rspec-its'
7+
gem 'rubocop', '~> 0.78.0'

0 commit comments

Comments
 (0)