8000 Allow to use ruby_bundle() without Gemfile.lock · p0deje/rules_ruby-1@9ed01cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ed01cb

Browse files
committed
Allow to use ruby_bundle() without Gemfile.lock
1 parent b7574c4 commit 9ed01cb

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ A unique name for this rule.
506506
The `Gemfile` which Bundler runs with.
507507

508508
|`gemfile_lock` a|
509-
`Label, required`
509+
`Label, optional`
510510

511511
The `Gemfile.lock` which Bundler runs with.
512512

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ class BundleBuildFileGenerator
176176
def initialize(workspace_name:,
177177
repo_name:,
178178
build_file: 'BUILD.bazel',
179-
gemfile_lock: 'Gemfile.lock',
179+
gemfile: 'Gemfile',
180180
includes: nil,
181181
excludes: nil,
182182
additional_require_paths: nil)
183183
@workspace_name = workspace_name
184184
@repo_name = repo_name
185185
@build_file = build_file
186-
@gemfile_lock = gemfile_lock
186+
@gemfile_lock = "#{gemfile}.lock"
187187
@includes = includes
188188
@excludes = excludes
189189
# This attribute returns 0 as the third minor version number, which happens to be
@@ -313,14 +313,14 @@ def to_flat_string(array)
313313
# ruby ./create_bundle_build_file.rb "BUILD.bazel" "Gemfile.lock" "repo_name" "{}" "{}" "wsp_name"
314314
if $0 == __FILE__
315315
if ARGV.length != 6
316-
warn("USAGE: #{$0} BUILD.bazel Gemfile.lock repo-name {includes-json} {excludes-json} workspace-name".orange)
316+
warn("USAGE: #{$0} BUILD.bazel Gemfile repo-name {includes-json} {excludes-json} workspace-name".orange)
317317
exit(1)
318318
end
319319

320-
build_file, gemfile_lock, repo_name, includes, excludes, workspace_name, * = *ARGV
320+
build_file, gemfile, repo_name, includes, excludes, workspace_name, * = *ARGV
321321

322322
BundleBuildFileGenerator.new(build_file: build_file,
323-
gemfile_lock: gemfile_lock,
323+
gemfile: gemfile,
324324
repo_name: repo_name,
325325
includes: JSON.parse(includes),
326326
excludes: JSON.parse(excludes),

ruby/private/bundle/def.bzl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,19 @@ def install_bundler(runtime_ctx, bundler_version):
115115

116116
def bundle_install(runtime_ctx, previous_result):
117117
cwd = runtime_ctx.ctx.path(".")
118+
bundler_args = [
119+
"install",
120+
"--binstubs={}".format(cwd.get_child(BUNDLE_BIN_PATH)),
121+
"--path={}".format(cwd.get_child(BUNDLE_PATH)),
122+
"--standalone",
123+
"--gemfile={}".format(runtime_ctx.ctx.attr.gemfile.name),
124+
]
125+
if runtime_ctx.ctx.attr.gemfile_lock:
126+
bundler_args += ["--deployment", "--frozen"]
127+
118128
result = run_bundler(
119129
runtime_ctx,
120-
[
121-
"install",
122-
"--binstubs={}".format(cwd.get_child(BUNDLE_BIN_PATH)),
123-
"--path={}".format(cwd.get_child(BUNDLE_PATH)),
124-
"--deployment",
125-
"--standalone",
126-
"--frozen",
127-
"--gemfile={}".format(runtime_ctx.ctx.attr.gemfile.name)
128-
],
130+
bundler_args,
129131
previous_result,
130132
)
131133

@@ -144,7 +146,7 @@ def generate_bundle_build_file(runtime_ctx, previous_result):
144146
"bundler/lib",
145147
SCRIPT_BUILD_FILE_GENERATOR, # The template used to created bundle file
146148
"BUILD.bazel", # Bazel build file (can be empty)
147-
runtime_ctx.ctx.attr.gemfile_lock.name, # Gemfile.lock where we list all direct and transitive dependencies
149+
runtime_ctx.ctx.attr.gemfile.name, # Gemfile -> Gemfile.lock where we list all direct and transitive dependencies
148150
runtime_ctx.ctx.name, # Name of the target
149151
repr(runtime_ctx.ctx.attr.includes),
150152
repr(runtime_ctx.ctx.attr.excludes),
@@ -157,7 +159,8 @@ def generate_bundle_build_file(runtime_ctx, previous_result):
157159

158160
def _ruby_bundle_impl(ctx):
159161
ctx.symlink(ctx.attr.gemfile, ctx.attr.gemfile.name)
160-
ctx.symlink(ctx.attr.gemfile_lock, ctx.attr.gemfile_lock.name)
162+
if ctx.attr.gemfile_lock:
163+
ctx.symlink(ctx.attr.gemfile_lock, ctx.attr.gemfile_lock.name)
161164
if ctx.attr.vendor_cache:
162165
ctx.symlink(
163166
ctx.path(str(ctx.path(ctx.attr.gemfile).dirname) + "/vendor"),

0 commit comments

Comments
 (0)
0