Skip to content

Commit 77a3922

Browse files
author
graham jenson
committed
[Fix] no spaces in files bug, remove deprecated code, demonstrate rubocop, remove host
1 parent 3a554f4 commit 77a3922

File tree

13 files changed

+76
-98
lines changed

13 files changed

+76
-98
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
**/bazel-*
22
**/.idea
3+
4+
.DS_Store

examples/simple_script/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ ruby_test(
3030
"@bundle//:rspec",
3131
],
3232
)
33+
34+
# TODO: not the best way of defining this, should make `rubocop` rule like `buildifier`
35+
ruby_binary(
36+
name = "rubocop",
37+
srcs = [
38+
"@bundle//:bin/rubocop",
39+
],
40+
main = "@bundle//:bin/rubocop",
41+
deps = [
42+
"@bundle//:rubocop",
43+
],
44+
)

examples/simple_script/Gemfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

3-
source "https://rubygems.org"
4-
5-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
3+
source 'https://rubygems.org'
64

5+
gem 'awesome_print'
76
gem 'rspec', '~> 3.7.0'
8-
gem 'awesome_print'
7+
gem 'rubocop'

examples/simple_script/Gemfile.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
ast (2.4.0)
45
awesome_print (1.8.0)
56
diff-lcs (1.3)
7+
jaro_winkler (1.5.4)
8+
parallel (1.19.1)
9+
parser (2.6.5.0)
10+
ast (~> 2.4.0)
11+
rainbow (3.0.0)
612
rspec (3.7.0)
713
rspec-core (~> 3.7.0)
814
rspec-expectations (~> 3.7.0)
@@ -16,13 +22,23 @@ GEM
1622
diff-lcs (>= 1.2.0, < 2.0)
1723
rspec-support (~> 3.7.0)
1824
rspec-support (3.7.1)
25+
rubocop (0.77.0)
26+
jaro_winkler (~> 1.5.1)
27+
parallel (~> 1.10)
28+
parser (>= 2.6)
29+
rainbow (>= 2.2.2, < 4.0)
30+
ruby-progressbar (~> 1.7)
31+
unicode-display_width (>= 1.4.0, < 1.7)
32+
ruby-progressbar (1.10.1)
33+
unicode-display_width (1.6.0)
1934

2035
PLATFORMS
2136
ruby
2237

2338
DEPENDENCIES
2439
awesome_print
2540
rspec (~> 3.7.0)
41+
rubocop
2642

2743
BUNDLED WITH
2844
1.17.3

examples/simple_script/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# Simple Script Example
22

3-
This Workspace includes a simple ruby script that includes and external gem and an internal library
3+
This Workspace includes a simple ruby script that includes and external gem and an internal library
4+
5+
6+
### Bundle
7+
8+
Update gemfile using
9+
10+
```
11+
bundle lock --update
12+
```
13+
14+
### Rubocop
15+
Run rubocop with:
16+
17+
```
18+
bazel run :rubocop -- $(pwd)/* -a
19+
```

examples/simple_script/WORKSPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ load("@bazelruby_ruby_rules//ruby:defs.bzl", "bundle_install")
2525

2626
bundle_install(
2727
name = "bundle",
28+
excludes = {
29+
"mini_portile": ["test/**/*"],
30+
},
2831
gemfile = "//:Gemfile",
2932
gemfile_lock = "//:Gemfile.lock",
3033
version = "2.0.2",

examples/simple_script/script.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
require 'openssl'
44
require 'lib/foo'
5-
require "awesome_print"
5+
require 'awesome_print'
66

77
def oss_rand
88
OpenSSL::BN.rand(512).to_s
99
end
1010

11-
puts Foo.aha + " " + oss_rand
11+
puts Foo.aha + ' ' + oss_rand
1212

1313
puts $LOAD_PATH
1414

15-
ap Class
15+
ap Class

ruby/private/binary.bzl

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,26 @@ def _ruby_binary_impl(ctx):
2929
"main",
3030
)
3131

32-
if sdk.is_host:
33-
interpreter_file_deps = []
34-
interpreter_trans_deps = []
35-
else:
36-
interpreter_file_deps = [interpreter]
37-
interpreter_trans_deps = [sdk.interpreter]
38-
3932
executable = ctx.actions.declare_file(ctx.attr.name)
4033
deps = _transitive_deps(
4134
ctx,
42-
extra_files = interpreter_file_deps + [executable],
43-
extra_deps = interpreter_trans_deps + ctx.attr._misc_deps,
35+
extra_files = [executable],
36+
extra_deps = ctx.attr._misc_deps,
4437
)
4538

4639
rubyopt = reversed(deps.rubyopt.to_list())
47-
intermediate_executable = ctx.actions.declare_file("%s.tpl.intermediate" % ctx.attr.name)
40+
4841
ctx.actions.expand_template(
4942
template = ctx.file._wrapper_template,
50-
output = intermediate_executable,
43+
output = executable,
5144
substitutions = {
5245
"{loadpaths}": repr(deps.incpaths.to_list()),
5346
"{rubyopt}": repr(rubyopt),
5447
"{main}": repr(_to_manifest_path(ctx, main)),
5548
"{interpreter}": _to_manifest_path(ctx, interpreter),
5649
},
5750
)
58-
if sdk.is_host:
59-
ctx.actions.run_shell(
60-
inputs = [intermediate_executable],
61-
outputs = [executable],
62-
command = "grep -v '^#shell ' %s > %s" % (
63-
intermediate_executable.path,
64-
executable.path,
65-
),
66-
)
67-
else:
68-
ctx.actions.run_shell(
69-
inputs = [intermediate_executable],
70-
outputs = [executable],
71-
command = "sed 's/^#shell //' %s > %s" % (
72-
intermediate_executable.path,
73-
executable.path,
74-
),
75-
)
51+
7652
return [DefaultInfo(
7753
executable = executable,
7854
default_runfiles = deps.default_files,

ruby/private/binary_wrapper.tpl

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#shell #!/usr/bin/env bash
2-
#shell # This conditional is evaluated as true in Ruby, false in shell
3-
#shell if [ ]; then
4-
#shell eval <<'END_OF_RUBY'
5-
#shell # -- begin Ruby --
61
#!/usr/bin/env ruby
72

83
# Ruby-port of the Bazel's wrapper script for Python
@@ -24,6 +19,7 @@
2419
#
2520

2621
require 'rbconfig'
22+
require 'rubygems'
2723

2824
def find_runfiles
2925
stub_filename = File.absolute_path($0)
@@ -122,28 +118,10 @@ def main(args)
122118
end
123119
end
124120
end
125-
exec(ruby_program, '--disable-gems', *rubyopt, main, *args)
121+
exec(ruby_program, *rubyopt, main, *args)
126122
# TODO(yugui) Support windows
127123
end
128124

129125
if __FILE__ == $0
130126
main(ARGV)
131127
end
132-
#shell END_OF_RUBY
133-
#shell __END__
134-
#shell # -- end Ruby --
135-
#shell fi
136-
#shell # -- begin Shell Script --
137-
#shell
138-
#shell # --- begin runfiles.bash initialization v2 ---
139-
#shell # Copy-pasted from the Bazel Bash runfiles library v2.
140-
#shell set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
141-
#shell source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
142-
#shell source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
143-
#shell source "$0.runfiles/$f" 2>/dev/null || \
144-
#shell source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
145-
#shell source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
146-
#shell { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
147-
#shell # --- end runfiles.bash initialization v2 ---
148-
#shell
149-
#shell exec "$(rlocation {interpreter})" ${BASH_SOURCE:-$0} "$@"

ruby/private/bundle/bundle.bzl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ def bundle_install_impl(ctx):
5656
if result.return_code:
5757
fail("Failed to install gems: %s%s" % (result.stdout, result.stderr))
5858

59-
# exclude any specified files
60-
exclude = []
61-
for gem, globs in ctx.attr.excludes.items():
62-
expanded = ["lib/ruby/*/gems/%s-*/%s" % (gem, glob) for glob in globs]
63-
exclude.extend(expanded)
64-
6559
# Create the BUILD file to expose the gems to the WORKSPACE
6660
args = [
6761
"env",
@@ -74,7 +68,7 @@ def bundle_install_impl(ctx):
7468
"BUILD.bazel", # Bazel build file (can be empty)
7569
"Gemfile.lock", # Gemfile.lock where we list all direct and transitive dependencies
7670
ctx.name, # Name of the target
77-
repr(exclude),
71+
repr(ctx.attr.excludes),
7872
RULES_RUBY_WORKSPACE_NAME,
7973
]
8074
result = ctx.execute(args, quiet = False)
@@ -87,7 +81,6 @@ def bundle_install_impl(ctx):
8781
ctx.attr._buildfile_template,
8882
substitutions = {
8983
"{repo_name}": ctx.name,
90-
"{exclude}": repr(exclude),
9184
"{workspace_name}": RULES_RUBY_WORKSPACE_NAME,
9285
},
9386
)

0 commit comments

Comments
 (0)