diff --git a/Rakefile b/Rakefile index 5f15277785176..448a8f556e77e 100644 --- a/Rakefile +++ b/Rakefile @@ -747,9 +747,35 @@ namespace :rb do desc 'Update generated Ruby files for local development' task :local_dev do + puts 'installing ruby, this may take a minute' Bazel.execute('build', [], '@bundle//:bundle') Rake::Task['rb:build'].invoke Rake::Task['grid'].invoke + Bazel.execute('build', [], '@bundle//bin:rubocop') + manage_selenium_ruby! + end + + def manage_selenium_ruby! + label = 'selenium-ruby' + + rbenv_path = `command -v rbenv`.strip + rbenv_root = `#{rbenv_path} root`.strip + dest = File.join(rbenv_root, 'versions', label) + return if File.symlink?(dest) + + rb_dir = File.join(Dir.pwd, 'rb') + bazel_bin = File.expand_path('../bazel-selenium/external/rules_ruby++ruby+ruby/dist/bin', rb_dir) + bazel_dist = File.dirname(bazel_bin) + FileUtils.ln_s(bazel_dist, dest) + system(rbenv_path, 'rehash') + + Dir.chdir(rb_dir) do + system('direnv allow') + system('direnv reload') + system({ "RBENV_VERSION" => label }, 'bundle', 'install') + end + rescue StandardError => e + puts "Unable to set Bazel Selenium as Default: #{e.message}" end desc 'Push Ruby gems to rubygems' diff --git a/rb/.envrc b/rb/.envrc new file mode 100644 index 0000000000000..5a7d20a943d10 --- /dev/null +++ b/rb/.envrc @@ -0,0 +1,18 @@ +# Local Ruby environment for Selenium's Bazel-built Ruby +# Safe to check in — only activates if the symlink already exists. + +if command -v rbenv >/dev/null 2>&1; then + LABEL=selenium-ruby + + RBENV_ROOT_DEFAULT="$(rbenv root 2>/dev/null || echo "$HOME/.rbenv")" + RUBY_SYMLINK="${RBENV_ROOT_DEFAULT}/versions/${LABEL}" + BIN_DIR="${RUBY_SYMLINK}/bin" + + # Always track the directory, even if missing now + watch_file "${BIN_DIR}" + + # Only set environment variable if directory currently present + if [ -d "${BIN_DIR}" ]; then + export RBENV_VERSION="${LABEL}" + fi +fi