diff --git a/MODULE.bazel b/MODULE.bazel index 9648b85423c2b..504fd91a6a522 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -38,7 +38,7 @@ bazel_dep(name = "rules_oci", version = "2.3.0") bazel_dep(name = "rules_pkg", version = "1.2.0") bazel_dep(name = "rules_python", version = "1.9.0") bazel_dep(name = "rules_proto", version = "7.1.0") -bazel_dep(name = "rules_ruby", version = "0.26.0") +bazel_dep(name = "rules_ruby", version = "0.28.0") bazel_dep(name = "rules_rs", version = "0.0.96") single_version_override( diff --git a/rb/Steepfile b/rb/Steepfile index 117ae8deeed94..f0f3b77bd2ec2 100644 --- a/rb/Steepfile +++ b/rb/Steepfile @@ -16,8 +16,6 @@ target :lib do 'lib/selenium/webdriver/bidi/struct.rb', # The generator + its up-to-date checker are build tooling, not typed runtime code 'lib/selenium/webdriver/bidi/support/**/*.rb', - # Vendored Bazel::Runfiles (rules_ruby#374); build/test tooling, removed when that ships upstream - 'lib/bazel/**/*.rb', # Ignore all spec files 'spec/**/*.rb', # Ignore line 166 due to UDP RBS issue diff --git a/rb/lib/bazel/BUILD.bazel b/rb/lib/bazel/BUILD.bazel deleted file mode 100644 index 261dabc197869..0000000000000 --- a/rb/lib/bazel/BUILD.bazel +++ /dev/null @@ -1,8 +0,0 @@ -load("@rules_ruby//ruby:defs.bzl", "rb_library") - -package(default_visibility = ["//rb:__subpackages__"]) - -rb_library( - name = "runfiles", - srcs = ["runfiles.rb"], -) diff --git a/rb/lib/bazel/runfiles.rb b/rb/lib/bazel/runfiles.rb deleted file mode 100644 index 8c32f88c3ae42..0000000000000 --- a/rb/lib/bazel/runfiles.rb +++ /dev/null @@ -1,129 +0,0 @@ -# frozen_string_literal: true - -# Licensed to the Software Freedom Conservancy (SFC) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The SFC licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# Mirrors the Bazel::Runfiles helper in rules_ruby#374; drop this file and depend on -# @rules_ruby//ruby/runfiles once a rules_ruby release ships it. - -require 'pathname' - -module Bazel - # Resolves runtime paths to data dependencies using either a - # manifest file or a runfiles directory. - class Runfiles - def self.create(env = ENV) - manifest_file = env['RUNFILES_MANIFEST_FILE'] - runfiles_dir = env['RUNFILES_DIR'] - - return new(ManifestBased.new(manifest_file)) if manifest_file && !manifest_file.empty? - return new(DirectoryBased.new(runfiles_dir)) if runfiles_dir && !runfiles_dir.empty? - - create_from_program_name($PROGRAM_NAME) - end - - def self.create_from_program_name(program_name) - if File.exist?("#{program_name}.runfiles_manifest") - new(ManifestBased.new("#{program_name}.runfiles_manifest")) - elsif File.exist?("#{program_name}.runfiles") - new(DirectoryBased.new("#{program_name}.runfiles")) - else - new(DirectoryBased.new('')) - end - end - - def initialize(strategy) - @strategy = strategy - end - - def rlocation(path) - raise ArgumentError, 'path must not be empty' if path.to_s.empty? - - return path if Pathname.new(path).absolute? - - invalid_path = %r{\A\.\.[/\\]|[/\\]\.\.[/\\]|\A\.[/\\]|[/\\]\.[/\\]|[/\\]\.\z|[/\\][/\\]} - raise ArgumentError, "path is not valid: #{path.inspect}" if path.match?(invalid_path) - - raise ArgumentError, "path is absolute without a drive letter: #{path.inspect}" if path.start_with?('\\') - - @strategy.rlocation(path) - end - - # Resolves paths by looking them up in a runfiles MANIFEST file. - class ManifestBased - def initialize(manifest_path) - @entries = parse_manifest(manifest_path) - end - - def rlocation(path) - return @entries[path] if @entries.key?(path) - - prefix = File.dirname(path) - while prefix != '.' && prefix != '/' - base = @entries[prefix] - return "#{base}#{path[prefix.length..]}" if base && !base.empty? - - prefix = File.dirname(prefix) - end - - nil - end - - private - - def parse_manifest(path) - entries = {} - return entries unless File.exist?(path) - - File.foreach(path) do |line| - line.chomp! - next if line.empty? - - key, value = parse_entry(line) - entries[key] = value - end - - entries - end - - def parse_entry(line) - escaped = line.delete_prefix!(' ') - key, _, value = line.partition(' ') - return [key, value] unless escaped - - [unescape(key), unescape(value)] - end - - def unescape(str) - str.gsub(/\\[snb]/, '\s' => ' ', '\n' => "\n", '\b' => '\\') - end - end - - # Resolves paths by joining them onto a runfiles directory root. - class DirectoryBased - def initialize(runfiles_dir) - @runfiles_dir = runfiles_dir - end - - def rlocation(path) - return nil if @runfiles_dir.empty? - - File.join(@runfiles_dir, path) - end - end - end -end diff --git a/rb/spec/integration/selenium/webdriver/BUILD.bazel b/rb/spec/integration/selenium/webdriver/BUILD.bazel index 237936d62cfe0..62e565039d868 100644 --- a/rb/spec/integration/selenium/webdriver/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/BUILD.bazel @@ -16,7 +16,6 @@ rb_library( visibility = ["//rb/spec:__subpackages__"], deps = [ "//rb/lib:selenium-webdriver", - "//rb/lib/bazel:runfiles", "//rb/lib/selenium:devtools", "//rb/lib/selenium:server", "//rb/lib/selenium:webdriver", @@ -25,6 +24,7 @@ rb_library( "//rb/lib/selenium/webdriver:remote", "//rb/spec:rspec_matchers", "@bundle", + "@rules_ruby//ruby/runfiles", ], ) diff --git a/rb/support/BUILD.bazel b/rb/support/BUILD.bazel index bd7d1235ef8a9..c4c0d62d7336b 100644 --- a/rb/support/BUILD.bazel +++ b/rb/support/BUILD.bazel @@ -25,5 +25,5 @@ rb_library( rb_library( name = "generated_note", srcs = ["generated_note.rb"], - deps = ["//rb/lib/bazel:runfiles"], # Delete this when updating to rules_ruby 0.28.0 + deps = ["@rules_ruby//ruby/runfiles"], ) diff --git a/rb/support/generated_note.rb b/rb/support/generated_note.rb index 562855ac42db7..06366213b258a 100644 --- a/rb/support/generated_note.rb +++ b/rb/support/generated_note.rb @@ -21,7 +21,6 @@ module GeneratedNote def self.runfiles @runfiles ||= begin - ensure_runfiles_on_load_path # Delete this when updating to rules_ruby 0.28.0 require 'bazel/runfiles' Bazel::Runfiles.create end @@ -39,14 +38,4 @@ def self.render(comment_prefix, generator, command) text = template.sub('{generator}', generator).sub('{command}', command) text.rstrip.split("\n").map { |line| "#{comment_prefix} #{line}" }.join("\n") end - - # Delete this when updating to rules_ruby 0.28.0 - def self.ensure_runfiles_on_load_path - if (manifest = ENV.fetch('RUNFILES_MANIFEST_FILE', nil)) && File.exist?(manifest) - entry = File.foreach(manifest).find { |line| line.start_with?('_main/rb/lib/bazel/runfiles.rb ') } - $LOAD_PATH.unshift(File.dirname(entry.split(' ', 2).last.chomp, 2)) if entry - elsif (dir = ENV.fetch('RUNFILES_DIR', nil)) && !dir.empty? - $LOAD_PATH.unshift(File.join(dir, '_main', 'rb', 'lib')) - end - end end