Skip to content

Commit b1caead

Browse files
author
Graham Jenson
authored
Merge pull request #38 from bazelruby/graham/remove-host-fix-excludes
[Fix] no spaces in files bug, remove deprecated code, remove host
2 parents dc837ff + e93b7b9 commit b1caead

File tree

11 files changed

+40
-98
lines changed

11 files changed

+40
-98
lines changed

.gitignore

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

examples/simple_script/Gemfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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'

examples/simple_script/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
```

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: 1 addition & 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
@@ -122,28 +117,10 @@ def main(args)
122117
end
123118
end
124119
end
125-
exec(ruby_program, '--disable-gems', *rubyopt, main, *args)
120+
exec(ruby_program, *rubyopt, main, *args)
126121
# TODO(yugui) Support windows
127122
end
128123

129124
if __FILE__ == $0
130125
main(ARGV)
131126
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
)

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919
visibility = ["//visibility:private"],
2020
)
2121
22-
# DEPRECATED: use :all instead
2322
ruby_library(
24-
name = "libs",
23+
name = "bundler",
2524
srcs = glob(
2625
include = [
27-
"lib/ruby/{ruby_version}/gems/*/**/*",
28-
"lib/ruby/{ruby_version}/bin/**/*",
26+
"bundler/**/*",
2927
],
30-
exclude = {exclude},
3128
),
32-
deps = [":bundler_setup"],
3329
rubyopt = ["-r${RUNFILES_DIR}/{repo_name}/lib/bundler/setup.rb"],
3430
)
3531
@@ -42,33 +38,23 @@
4238
srcs = glob(
4339
include = [
4440
"lib/ruby/{ruby_version}/gems/{name}-{version}/**/*",
45-
# TODO scope down included bin files
46-
"lib/ruby/{ruby_version}/bin/**/*",
4741
],
4842
exclude = {exclude},
4943
),
5044
deps = {deps},
5145
rubyopt = ["-r${RUNFILES_DIR}/{repo_name}/lib/bundler/setup.rb"],
5246
)
53-
5447
'
5548

56-
ALL_TEMPLATE = '
57-
ruby_library(
58-
name = "all",
59-
deps = {deps},
60-
rubyopt = ["-r${RUNFILES_DIR}/{repo_name}/lib/bundler/setup.rb"],
61-
)
62-
'
6349
require "bundler"
50+
require 'json'
6451

6552
def create_bundle_build_file(build_out_file, lock_file, repo_name, excludes, workspace_name)
6653
# TODO: properly calculate path/ruby version here
6754
# ruby_version = RUBY_VERSION # doesnt work because verion is 2.5.5 path is 2.5.0
6855
ruby_version = "*"
6956

7057
template_out = TEMPLATE.gsub("{workspace_name}", workspace_name)
71-
.gsub("{exclude}", excludes)
7258
.gsub("{repo_name}", repo_name)
7359
.gsub("{ruby_version}", ruby_version)
7460

@@ -78,18 +64,19 @@ def create_bundle_build_file(build_out_file, lock_file, repo_name, excludes, wor
7864
bundle.specs.each { |spec|
7965
deps = spec.dependencies.map(&:name)
8066
deps += [":bundler_setup"]
81-
template_out += GEM_TEMPLATE.gsub("{exclude}", excludes)
67+
68+
exclude_array = excludes[spec.name] || []
69+
# We want to exclude files and folder with spaces in them
70+
exclude_array += ["**/* *.*", "**/* */*"]
71+
72+
template_out += GEM_TEMPLATE.gsub("{exclude}", exclude_array.to_s)
8273
.gsub("{name}", spec.name)
8374
.gsub("{version}", spec.version.to_s)
8475
.gsub("{deps}", deps.to_s)
8576
.gsub("{repo_name}", repo_name)
8677
.gsub("{ruby_version}", ruby_version)
8778
}
8879

89-
# Append collection of all gems
90-
template_out += ALL_TEMPLATE.gsub("{repo_name}", repo_name)
91-
.gsub("{deps}", ([":bundler_setup"] + bundle.specs.map(&:name)).to_s)
92-
9380
# Write the actual BUILD file
9481
::File.open(build_out_file, 'w') { |f|
9582
f.puts template_out
@@ -106,7 +93,9 @@ def create_bundle_build_file(build_out_file, lock_file, repo_name, excludes, wor
10693
build_out_file = ARGV[0]
10794
lock_file = ARGV[1]
10895
repo_name = ARGV[2]
109-
excludes = ARGV[3]
96+
97+
excludes = JSON.parse(ARGV[3])
98+
11099
workspace_name = ARGV[4]
111100

112101
create_bundle_build_file(build_out_file, lock_file, repo_name, excludes, workspace_name)

ruby/private/toolchain.bzl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RubyRuntimeInfo = provider(
77
"bundler": "A label which points bundler command",
88
"runtime": "A list of labels which points runtime libraries",
99
"rubyopt": "A list of strings which should be passed to the interpreter as command line options",
10-
"is_host": "True only if the runtime is the host ruby ",
1110
},
1211
)
1312

@@ -17,7 +16,6 @@ def _ruby_toolchain_impl(ctx):
1716
interpreter = ctx.attr.interpreter,
1817
runtime = ctx.files.runtime,
1918
rubyopt = ctx.attr.rubyopt,
20-
is_host = ctx.attr.is_host,
2119
),
2220
)]
2321

@@ -38,7 +36,6 @@ _ruby_toolchain = rule(
3836
"rubyopt": attr.string_list(
3937
default = [],
4038
),
41-
"is_host": attr.bool(default = False),
4239
},
4340
)
4441

@@ -47,7 +44,6 @@ def ruby_toolchain(
4744
interpreter,
4845
runtime,
4946
rubyopt = [],
50-
is_host = False,
5147
rules_ruby_workspace = RULES_RUBY_WORKSPACE_NAME,
5248
**kwargs):
5349
impl_name = name + "_sdk"
@@ -56,7 +52,6 @@ def ruby_toolchain(
5652
interpreter = interpreter,
5753
runtime = runtime,
5854
rubyopt = rubyopt,
59-
is_host = is_host,
6055
)
6156

6257
native.toolchain(

0 commit comments

Comments
 (0)