simplify lockfile definitions
by avoiding constants also don't add the alternate lockfiles unless we actually are the primary gemfile (fixes ruby-lsp) Change-Id: Icaa47ea81a35938da335b7d5632e04f2d76b1e8c Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/329543 Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> Build-Review: Cody Cutrer <cody@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
parent
139e021e0a
commit
9d377cc778
|
@ -459,6 +459,8 @@ Style/FormatString:
|
|||
Severity: convention
|
||||
AutoCorrect: false
|
||||
Style/GlobalVars:
|
||||
AllowedVariables:
|
||||
- $canvas_rails
|
||||
Severity: convention
|
||||
Style/GuardClause:
|
||||
Enabled: false
|
||||
|
|
48
Gemfile
48
Gemfile
|
@ -25,37 +25,33 @@ Plugin.send(:load_plugin, "bundler-multilock")
|
|||
|
||||
require_relative "config/canvas_rails_switcher"
|
||||
|
||||
# Bundler evaluates this from a non-global context for plugins, so we have
|
||||
# to explicitly pop up to set global constants
|
||||
# rubocop:disable Style/RedundantConstantBase
|
||||
if Bundler.default_gemfile == gemfile
|
||||
SUPPORTED_RAILS_VERSIONS.product([nil, true]).each do |rails_version, include_plugins|
|
||||
lockfile = ["rails#{rails_version.delete(".")}", include_plugins && "plugins"].compact.join(".")
|
||||
if rails_version == SUPPORTED_RAILS_VERSIONS.first
|
||||
lockfile = nil unless include_plugins
|
||||
elsif include_plugins
|
||||
parent = "rails#{rails_versions.delete(".")}"
|
||||
end
|
||||
|
||||
# will already be defined during the second Gemfile evaluation
|
||||
::CANVAS_INCLUDE_PLUGINS = true unless defined?(::CANVAS_INCLUDE_PLUGINS)
|
||||
active = rails_version == $canvas_rails && !!include_plugins
|
||||
|
||||
SUPPORTED_RAILS_VERSIONS.product([nil, true]).each do |rails_version, include_plugins|
|
||||
lockfile = ["rails#{rails_version.delete(".")}", include_plugins && "plugins"].compact.join(".")
|
||||
lockfile = nil if rails_version == SUPPORTED_RAILS_VERSIONS.first && !include_plugins
|
||||
lockfile(lockfile,
|
||||
active:,
|
||||
parent:,
|
||||
enforce_pinned_additional_dependencies: include_plugins) do
|
||||
$canvas_rails = rails_version
|
||||
@include_plugins = include_plugins
|
||||
end
|
||||
end
|
||||
|
||||
active = rails_version == CANVAS_RAILS && !!include_plugins
|
||||
|
||||
lockfile(lockfile,
|
||||
active:,
|
||||
allow_mismatched_dependencies: rails_version != SUPPORTED_RAILS_VERSIONS.first,
|
||||
enforce_pinned_additional_dependencies: include_plugins) do
|
||||
Object.send(:remove_const, :CANVAS_RAILS)
|
||||
::CANVAS_RAILS = rails_version
|
||||
Object.send(:remove_const, :CANVAS_INCLUDE_PLUGINS)
|
||||
::CANVAS_INCLUDE_PLUGINS = include_plugins
|
||||
(gemfile_root.glob("Gemfile.d/*.lock") + gemfile_root.glob("gems/*/Gemfile.lock")).each do |gem_lockfile_name|
|
||||
return unless lockfile(gem_lockfile_name,
|
||||
gemfile: gem_lockfile_name.to_s.sub(/\.lock$/, ""),
|
||||
allow_mismatched_dependencies: false)
|
||||
end
|
||||
end
|
||||
|
||||
(gemfile_root.glob("Gemfile.d/*.lock") + gemfile_root.glob("gems/*/Gemfile.lock")).each do |gem_lockfile_name|
|
||||
return unless lockfile(gem_lockfile_name,
|
||||
gemfile: gem_lockfile_name.to_s.sub(/\.lock$/, ""),
|
||||
allow_mismatched_dependencies: false)
|
||||
end
|
||||
# rubocop:enable Style/RedundantConstantBase
|
||||
|
||||
module PreferGlobalRubyGemsSource
|
||||
def rubygems_sources
|
||||
[global_rubygems_source] + non_global_rubygems_sources
|
||||
|
@ -80,7 +76,7 @@ module GemOverride
|
|||
end
|
||||
Bundler::Dsl.prepend(GemOverride)
|
||||
|
||||
if CANVAS_INCLUDE_PLUGINS
|
||||
if @include_plugins
|
||||
gemfile_root.glob("gems/plugins/*/Gemfile.d/_before.rb") do |file|
|
||||
eval_gemfile(file)
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
CANVAS_INLINE_PLUGINS = %w[
|
||||
inline_plugins = %w[
|
||||
academic_benchmark
|
||||
account_reports
|
||||
moodle_importer
|
||||
|
@ -30,7 +30,7 @@ gemfile_root.glob("../gems/plugins/*") do |plugin_dir|
|
|||
next unless File.directory?(plugin_dir)
|
||||
|
||||
gem_name = File.basename(plugin_dir)
|
||||
next unless CANVAS_INCLUDE_PLUGINS || CANVAS_INLINE_PLUGINS.include?(gem_name)
|
||||
next unless @include_plugins || inline_plugins.include?(gem_name)
|
||||
|
||||
gem(gem_name, path: plugin_dir.relative_path_from(gemfile_root))
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
# Non-standard Canvas extension to Bundler behavior -- load the Gemfiles from
|
||||
# plugins.
|
||||
|
||||
if CANVAS_INCLUDE_PLUGINS
|
||||
if @include_plugins
|
||||
gemfile_root.glob("../gems/plugins/*/Gemfile.d/*") do |g|
|
||||
next if g.basename == "_before.rb"
|
||||
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
# the default version (corresponding to the bare Gemfile.lock) must be listed first
|
||||
SUPPORTED_RAILS_VERSIONS = %w[7.0].freeze
|
||||
|
||||
unless defined?(CANVAS_RAILS)
|
||||
unless defined?($canvas_rails)
|
||||
file_path = File.expand_path("RAILS_VERSION", __dir__)
|
||||
|
||||
if ENV["CANVAS_RAILS"]
|
||||
CANVAS_RAILS = ENV["CANVAS_RAILS"]
|
||||
$canvas_rails = ENV["CANVAS_RAILS"]
|
||||
elsif File.exist?(file_path)
|
||||
CANVAS_RAILS = File.read(file_path).strip
|
||||
$canvas_rails = File.read(file_path).strip
|
||||
else
|
||||
begin
|
||||
# have to do the consul communication without any gems, because
|
||||
|
@ -63,13 +63,13 @@ unless defined?(CANVAS_RAILS)
|
|||
break if result
|
||||
end
|
||||
end
|
||||
CANVAS_RAILS = result ? Base64.decode64(JSON.parse(result.body).first["Value"]).strip : SUPPORTED_RAILS_VERSIONS.first
|
||||
$canvas_rails = result ? Base64.decode64(JSON.parse(result.body).first["Value"]).strip : SUPPORTED_RAILS_VERSIONS.first
|
||||
rescue
|
||||
CANVAS_RAILS = SUPPORTED_RAILS_VERSIONS.first
|
||||
$canvas_rails = SUPPORTED_RAILS_VERSIONS.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless SUPPORTED_RAILS_VERSIONS.any?(CANVAS_RAILS)
|
||||
raise "unsupported Rails version specified #{CANVAS_RAILS}"
|
||||
unless SUPPORTED_RAILS_VERSIONS.any?($canvas_rails)
|
||||
raise "unsupported Rails version specified #{$canvas_rails}"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue