From f0891ec27cb36667de6047c523abdae726e9e3f5 Mon Sep 17 00:00:00 2001 From: Kevin Menard Date: Tue, 15 Aug 2023 11:58:43 -0400 Subject: [PATCH] Add a new `--install` option to `jt build` for installing custom builds. --- tool/jt.rb | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tool/jt.rb b/tool/jt.rb index 6c19061c20be..b280c90ec423 100755 --- a/tool/jt.rb +++ b/tool/jt.rb @@ -788,6 +788,8 @@ def help by default it is the name of the mx env file, the named build stays until it is rebuilt or deleted manually --new-hash update the git commit hash in RUBY_DESCRIPTION + --install PATH move the build to the specified directory + by default, builds will remain localized to the source tree mx options: options passed directly to mx -d start the Java debugger and enables assertions when running truffleruby to configure C extensions mx build options options passed to the 'build' command of mx @@ -2504,6 +2506,12 @@ def bootstrap_toolchain env end + install_path = if (i = options.index('--install') || options.index('-i')) + options.delete_at i + options.delete_at i + end + raise 'Installation path already exists' if File.exist?(install_path.to_s) + name = "truffleruby-#{@ruby_name}" mx_base_args = ['--env', env] @@ -2543,26 +2551,30 @@ def bootstrap_toolchain File.symlink(build_dir, dest) end - # Symlink builds into version manager - rbenv_root = ENV['RBENV_ROOT'] - rubies_dir = File.join(rbenv_root, 'versions') if rbenv_root && File.directory?(rbenv_root) - - chruby_versions = File.expand_path('~/.rubies') - rubies_dir = chruby_versions if File.directory?(chruby_versions) + if install_path + File.rename build_dir, install_path + else + # Symlink builds into version manager + rbenv_root = ENV['RBENV_ROOT'] + rubies_dir = File.join(rbenv_root, 'versions') if rbenv_root && File.directory?(rbenv_root) + + chruby_versions = File.expand_path('~/.rubies') + rubies_dir = chruby_versions if File.directory?(chruby_versions) + + if rubies_dir + Dir.glob(rubies_dir + '/truffleruby-*').each do |link| + next unless File.symlink?(link) + next if File.exist?(link) + target = File.readlink(link) + next unless target.start_with?("#{TRUFFLERUBY_DIR}/mxbuild") + File.delete link + puts "Deleted broken link: #{link} -> #{target}" + end - if rubies_dir - Dir.glob(rubies_dir + '/truffleruby-*').each do |link| - next unless File.symlink?(link) - next if File.exist?(link) - target = File.readlink(link) - next unless target.start_with?("#{TRUFFLERUBY_DIR}/mxbuild") - File.delete link - puts "Deleted broken link: #{link} -> #{target}" + link_path = "#{rubies_dir}/#{name}" + File.delete link_path if File.symlink? link_path or File.exist? link_path + File.symlink dest_ruby, link_path end - - link_path = "#{rubies_dir}/#{name}" - File.delete link_path if File.symlink? link_path or File.exist? link_path - File.symlink dest_ruby, link_path end end