Path: blob/trunk/rb/support/rbs_collection_update.rb
4004 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require "rbconfig"2021# Find the rb directory - try multiple strategies for different Bazel contexts22root = if ENV['BUILD_WORKSPACE_DIRECTORY']23# bazel run sets this to the workspace root24File.join(ENV['BUILD_WORKSPACE_DIRECTORY'], 'rb')25elsif ENV['BUILD_WORKING_DIRECTORY']26# Alternative for some bazel run scenarios27rb_path = File.join(ENV['BUILD_WORKING_DIRECTORY'], 'rb')28File.exist?(rb_path) ? rb_path : File.expand_path("../..", __dir__)29else30# Direct execution or other scenarios - find rb relative to script31script_dir = File.expand_path(__dir__)32if script_dir.include?('runfiles')33# In bazel test, try to find the actual workspace34# Look for the workspace by finding where Gemfile exists35workspace = script_dir.split('runfiles').first.sub(%r{/bazel-out/.*}, '')36File.join(workspace, 'rb')37else38File.expand_path("../..", __dir__)39end40end4142Dir.chdir(root)4344ruby = RbConfig.ruby4546# Run rbs collection update47system(ruby, "-S", "rbs", "collection", "update", *ARGV) || exit(1)4849# Fix the gemfile_lock_path to be relative (rbs writes absolute paths when run via bazel)50lockfile = File.join(root, "rbs_collection.lock.yaml")51content = File.read(lockfile)52content.gsub!(/^gemfile_lock_path:.*$/, 'gemfile_lock_path: Gemfile.lock')53File.write(lockfile, content)5455puts "Updated rbs_collection.lock.yaml with fixed gemfile_lock_path"565758