feat: support installing gems from Git#312
feat: support installing gems from Git#312withered-magic wants to merge 11 commits intobazel-contrib:mainfrom
Conversation
| @@ -0,0 +1,29 @@ | |||
| # frozen_string_literal: true | |||
| require 'fileutils' | |||
There was a problem hiding this comment.
Would it be reasonable to add a high-level comment on what this file does?
I think it's basically rsync'ing gemspec/extconf.rb files?
There was a problem hiding this comment.
just added a comment but yep exactly! we need this rsync-style functionality when there are Git gems because I noticed that there's some logic in Bunder / some gems that tries to normalize these files, which runs into "file is read-only" errors since it eventually tries to rewrite the (read-only bc of sandboxing) files from vendor/cache, so I need to make a copy of vendor/cache so that Bundler can rewrite stuff as it wants.
So to get around this I needed to make another copy which preserves symlinks except for those files that can potentially get rewritten by bundler (so far I've only noticed this happen for gemspecs and extconf.rb)
| 2.3.0 | ||
| """ | ||
|
|
||
| # Sample Gemfile.lock content with multiple Git gems from same repo |
There was a problem hiding this comment.
Not sure these comments add much, I might just drop them?
There was a problem hiding this comment.
(similar observation for a lot of the comments below, my guess is they're AI remnants)
|
|
||
| raise 'must provide both srcdir and destdir' unless ARGV.length >= 2 | ||
|
|
||
| $srcdir, $destdir = *ARGV |
There was a problem hiding this comment.
Is there a particular reason to use globals here vs something a bit more idiomatic, i.e. logic nested under if $PROGRAM_NAME == __FILE__
There was a problem hiding this comment.
just refactored it to make it a bit more idiomatic and remove the globals!
| _git_reset(rctx, git_repo) | ||
| _git_clean(rctx, git_repo) | ||
|
|
||
| git_metadata_folder = git_repo.directory.get_child(".git") |
There was a problem hiding this comment.
Why do we delete this? Worth a comment
There was a problem hiding this comment.
I'll add a comment! Was mostly since this shouldn't be used by Bundler down the line and therefore didn't want it end up as an unnecessary input to the bundle install action later
| if remote_name.endswith(".git"): | ||
| remote_name = remote_name[:-4] | ||
|
|
||
| extracted_path = "%s/%s-%s" % (cache_path, remote_name, git_package.revision[:12]) |
There was a problem hiding this comment.
I assume the 12 here is arbitrary?
There was a problem hiding this comment.
ah this is to match up with the exact naming format that Bundler creates the directory with in vendor/cache for gems installed from Git
There was a problem hiding this comment.
oh, fun! probably worth a comment then, given this is load-bearing
What issues were you seeing? I wonder if those are related to |
|
Ah, it wasn't related to |
It would be nice to have Windows - we generally tend to keep implementation consistent across all operating systems. I'm happy to help you debug this on Slack! |
|
sounds good! I'll keep investigating this tonight and reach out on slack if needed! |
016db8d to
f6762ba
Compare
9b1a2a0 to
6258b77
Compare
|
works on windows now! i also added another test to make sure creating executable targets for git gems also works |
p0deje
left a comment
There was a problem hiding this comment.
Great work, I'm happy to merge once CI is green. Though I think there is a space to simplify it, feel free to ignore my comments if you disagree.
|
|
||
| <a id="rb_git_gem"></a> | ||
|
|
||
| ## rb_git_gem |
There was a problem hiding this comment.
Can you add docs for this rule similar to rb_gem?
Exposes a Ruby gem cloned from Git.
You normally don't need to call this rule directly as it's an internal one used by
rb_bundle_fetch().
There was a problem hiding this comment.
Are changes in examples/deep_gem necessary?
| srcs = ["hello_world_bin_spec.rb"], | ||
| args = ["spec/hello_world_bin_spec.rb"], | ||
| data = ["@bundle//bin:hello_world"], | ||
| env = {"HELLO_WORLD_BIN": "$(rlocationpath @bundle//bin:hello_world)"}, |
There was a problem hiding this comment.
Are you specifically testing the environment variable expansion?
There was a problem hiding this comment.
FWIW, it might be easier to move the Git gem and related files to examples/gem - it would be easier to maintain since there is a lot of duplication for Bazel setup and CI configs.
Feel free to ignore this one!
| """@generated by @rules_ruby//:ruby/private/bundle_fetch.bzl""" | ||
|
|
||
| load("@rules_ruby//ruby:defs.bzl", "rb_bundle_install", "rb_gem", "rb_gem_install") | ||
| load("@rules_ruby//ruby:defs.bzl", "rb_bundle_install", "rb_gem", "rb_gem_install", "rb_git_gem") |
There was a problem hiding this comment.
The function is not used, I think you can safely remove import.
| dirs_to_visit = [rctx.path(directory)] | ||
| gemspec_dirs = [] | ||
|
|
||
| for i in range(10000): # Bounded loop required by Starlark |
There was a problem hiding this comment.
TIL how to write while in Starlark
| """, | ||
| ) | ||
|
|
||
| def _rb_git_gem_impl(ctx): |
There was a problem hiding this comment.
What do you think about adding the srcs attribute to rb_gem? This way, you won't need to add a new rule.
Fixes: #62
Adds support for installing gems from Git by including the Git sources in vendor/cache. Currently this uses
gitdirectly, but I'm planning to follow this PR up with another PR to use @sushain97's approach of downloading source archives from GitHub with the Bazel downloader.Right now doesn't support Windows as I wasn't able to get this working with my limited Windows knowledge :(
AI Disclaimer
Core logic was written by me, only used AI for comments, setting up the example scaffolding as well as some of the more tedious parsing tests.