-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[rb] resolve spec runfiles via Bazel::Runfiles #17810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
titusfortner
merged 7 commits into
SeleniumHQ:trunk
from
titusfortner:rb-bazel-runfiles
Jul 22, 2026
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51fee7a
[rb] resolve spec runfiles via Bazel::Runfiles
titusfortner aad21e1
[rb] make bazel_java runfiles resolution hermetic and nil-safe
titusfortner b4c64bd
[rb] return absolute paths from Bazel::Runfiles#rlocation before valiβ¦
titusfortner 37898fa
[rb] reject drive-letter-less absolute paths in Bazel::Runfiles#rlocaβ¦
titusfortner feb389c
[rb] relocate vendored Bazel::Runfiles to rb/lib/bazel for reuse outsβ¦
titusfortner e4a63fb
[rb] route spec runfiles ENV lookups through a blank-safe, fail-loud β¦
titusfortner 3f2938b
[rb] honor on-disk driver/browser overrides in runfiles_path for non-β¦
titusfortner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
rb/spec/integration/selenium/webdriver/spec_support/bazel/runfiles.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # 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? | ||
|
|
||
| invalid_path = %r{\A\.\.[/\\]|[/\\]\.\.[/\\]|\A\.[/\\]|[/\\]\.[/\\]|[/\\]\.\z|[/\\][/\\]} | ||
| raise ArgumentError, "path is not valid: #{path.inspect}" if path.match?(invalid_path) | ||
|
|
||
| return path if Pathname.new(path).absolute? | ||
|
|
||
| @strategy.rlocation(path) | ||
| end | ||
|
titusfortner marked this conversation as resolved.
|
||
|
|
||
| # 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.