Skip to content

feat: Support mapping the vendor cache from workspace #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ ruby_bundle(
gemfile_lock,
bundler_version = "2.1.4",
excludes = [],
vendor_cache = False,
ruby_sdk = "@org_ruby_lang_ruby_toolchain",
ruby_interpreter = "@org_ruby_lang_ruby_toolchain//:ruby",
)
Expand Down Expand Up @@ -589,6 +590,13 @@ ruby_bundle(
<p>NOTE: This rule never updates the <code>Gemfile.lock</code>. It is your responsibility to generate/update <code>Gemfile.lock</code></p>
</td>
</tr>
<tr>
<td><code>vendor_cache</code></td>
<td>
<code>Bool, optional</code>
<p>Symlink the vendor directory into the Bazel build space, this allows Bundler to access vendored Gems</p>
</td>
</tr>
<tr>
<td><code>bundler_version</code></td>
<td>
Expand Down Expand Up @@ -627,6 +635,28 @@ ruby_bundle(
)
```

##### Vendor directory handling

To use the vendor cache, you have to declare a `managed_directory` in
your workspace. The name should match the name of the bundle.

``` bazel
load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_bundle")

workspace(
name = "my_wksp",
managed_directories = {"@bundle": ["vendor"]},
)

ruby_bundle(
name = "bundle",
bundler_version = "2.1.2",
vendor_cache = True,
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
```

#### `BUILD.bazel`:

```python
Expand Down
1 change: 1 addition & 0 deletions examples/simple_script_vendored/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bazel-*
174 changes: 174 additions & 0 deletions examples/simple_script_vendored/.relaxed-rubocop-2.4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Relaxed.Ruby.Style
## Version 2.4

Style/Alias:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylealias

Style/AsciiComments:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleasciicomments

Style/BeginBlock:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylebeginblock

Style/BlockDelimiters:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters

Style/CommentAnnotation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylecommentannotation

Style/Documentation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styledocumentation

Layout/DotPosition:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutdotposition

Style/DoubleNegation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styledoublenegation

Style/EndBlock:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleendblock

Style/FormatString:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleformatstring

Style/IfUnlessModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier

Style/Lambda:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylelambda

Style/ModuleFunction:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylemodulefunction

Style/MultilineBlockChain:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain

Style/NegatedIf:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenegatedif

Style/NegatedWhile:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile

Style/NumericPredicate:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate

Style/ParallelAssignment:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment

Style/PercentLiteralDelimiters:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters

Style/PerlBackrefs:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs

Style/Semicolon:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesemicolon

Style/SignalException:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesignalexception

Style/SingleLineBlockParams:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams

Style/SingleLineMethods:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods

Layout/SpaceBeforeBlockBraces:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces

Layout/SpaceInsideParens:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens

Layout/LineLength:
Enabled: false

Style/SpecialGlobalVars:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars

Style/StringLiterals:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylestringliterals

Style/TrailingCommaInArguments:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments

Style/TrailingCommaInArrayLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral

Style/TrailingCommaInHashLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral

Style/SymbolArray:
Enabled: false
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray

Style/WhileUntilModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier

Style/WordArray:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylewordarray

Lint/AmbiguousRegexpLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral

Lint/AssignmentInCondition:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition

Metrics/AbcSize:
Enabled: false

Metrics/BlockNesting:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/ParameterLists:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

36 changes: 36 additions & 0 deletions examples/simple_script_vendored/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
inherit_from: .relaxed-rubocop-2.4.yml

AllCops:
TargetRubyVersion: 2.6
UseCache: true
DefaultFormatter: progress
DisplayStyleGuide: true
DisplayCopNames: true
Exclude:
- "external*/**/*"
- "bazel-*/**/*"
- "**/examples/**/*"
- "**/BUILD"
- "**/*.bazel"
- "**/*.bzl"
- "**/rubocop"
- "**/vendor/bundle/**/*"
Include:
- '**/*.rb'
- '**/*.gemfile'
- '**/*.gemspec'
- '**/*.rake'
- '**/*.ru'
- '**/Gemfile'
- '**/Rakefile'

Layout/HashAlignment:
Enabled: true
EnforcedColonStyle: table

Style/Dir:
Enabled: false

# In Bazel we want to use __FILE__ because __dir__points to the actual sources
Style/ExpandPathArguments:
Enabled: false
94 changes: 94 additions & 0 deletions examples/simple_script_vendored/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
load(
"@bazelruby_rules_ruby//ruby:defs.bzl",
"ruby_binary",
"ruby_rspec",
"ruby_rubocop",
"ruby_test",
)

package(default_visibility = ["//:__subpackages__"])

ruby_binary(
name = "bin",
srcs = ["script.rb"],
main = "script.rb",
deps = [
"//lib:foo",
],
)

# This is an example of the RSpec definition that uses autorun
# and points to spec_helper as the main spec file. It specifies
# which specs to run using the args.

ruby_test(
name = "all-specs",
timeout = "short",
srcs = [
"script.rb",
"//lib:foo",
] + glob([
"spec/**/*.rb",
]),
# This is a WORKSPACE-relative path to a spec directory.
# It could be longer, like "my/path/to/spec".
args = [
"spec",
],
main = "@bundle//:bin/rspec",
deps = [
"@bundle//:bin",
"@bundle//:rspec",
"@bundle//:rspec-its",
],
)

# Finally, this is the short version of the same thing, expressed
# via the ruby_rspec_test rule that does what the above example
# shows but encapsulated in the rule itself. It adds rspec and rspec-its
# gems to the dependency list, executes bin/rspec and passes spec_targets
# as arguments to rspec.
ruby_rspec(
name = "ruby-rspec-test",
srcs = [
"script.rb",
"//lib:foo",
],
rspec_args = {
# NOTE: the output is only visible with --test_output=streamed flag
"--format": "progress", # this is how we can override rspec output format
},
specs = glob([
"spec/**/*.rb",
]),
deps = [],
)

ruby_binary(
name = "rubocop-bin",
srcs = [
"script.rb",
"//lib:foo",
] + glob([
"spec/**/*.rb",
]),
args = [
"-- *.rb spec/*.rb lib/*.rb -a",
],
main = "@bundle//:bin/rubocop",
deps = [
"//lib:foo",
"@bundle//:bin",
],
)

# Rubocop rule
# To check
# bazel run rubocop -- -a
ruby_rubocop(
name = "rubocop",
bin = "@bundle//:bin/rubocop",
deps = [
"@bundle//:rubocop",
],
)
7 changes: 7 additions & 0 deletions examples/simple_script_vendored/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rspec', '~> 3.7.0'
gem 'rspec-its'
gem 'rubocop', '~> 0.78.0'
Loading