2021-03-30 06:08:46 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-03-27 06:41:23 +08:00
|
|
|
# What have they done to the Gemfile???
|
|
|
|
#
|
2021-09-21 00:20:02 +08:00
|
|
|
# Relax. Breathe deep. All the gems are still there; they're just loaded in
|
|
|
|
# various files in Gemfile.d/. This allows us to require gems locally that we
|
|
|
|
# might not want to commit to our public repo. We can maintain a customized
|
|
|
|
# list of gems for development and debuggery, without affecting our ability to
|
|
|
|
# merge with canvas-lms
|
2014-03-27 06:41:23 +08:00
|
|
|
#
|
2011-02-01 09:57:29 +08:00
|
|
|
|
2021-09-21 00:20:02 +08:00
|
|
|
source "https://rubygems.org/"
|
2017-10-12 02:10:24 +08:00
|
|
|
|
2023-09-12 23:20:10 +08:00
|
|
|
# cleanup local envs automatically from the old plugin
|
|
|
|
Plugin.uninstall(["bundler_lockfile_extensions"], {}) if Plugin.installed?("bundler_lockfile_extensions")
|
2023-01-18 22:32:47 +08:00
|
|
|
|
2023-09-12 23:20:10 +08:00
|
|
|
# vendored until https://github.com/rubygems/rubygems/pull/6957 is merged and released
|
2023-12-19 04:33:05 +08:00
|
|
|
plugin "bundler-multilock", "1.2.1", path: "vendor/gems/bundler-multilock"
|
2023-09-12 23:20:10 +08:00
|
|
|
# the extra check here is in case `bundle check` or `bundle exec` gets run before `bundle install`,
|
|
|
|
# and is also fixed by the same PR
|
|
|
|
raise GemNotFound, "bundler-multilock plugin is not installed" if !is_a?(Bundler::Plugin::DSL) && !Plugin.installed?("bundler-multilock")
|
|
|
|
return unless Plugin.installed?("bundler-multilock")
|
|
|
|
|
|
|
|
Plugin.send(:load_plugin, "bundler-multilock")
|
|
|
|
|
|
|
|
require_relative "config/canvas_rails_switcher"
|
2023-01-18 22:32:47 +08:00
|
|
|
|
2023-10-06 03:19:24 +08:00
|
|
|
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
|
2023-01-18 22:32:47 +08:00
|
|
|
|
2023-10-06 03:19:24 +08:00
|
|
|
active = rails_version == $canvas_rails && !!include_plugins
|
2023-09-12 23:20:10 +08:00
|
|
|
|
2023-10-06 03:19:24 +08:00
|
|
|
lockfile(lockfile,
|
|
|
|
active:,
|
|
|
|
parent:,
|
|
|
|
enforce_pinned_additional_dependencies: include_plugins) do
|
|
|
|
$canvas_rails = rails_version
|
|
|
|
@include_plugins = include_plugins
|
|
|
|
end
|
2023-04-12 23:49:30 +08:00
|
|
|
end
|
2023-01-18 22:32:47 +08:00
|
|
|
|
2023-10-06 03:19:24 +08:00
|
|
|
(gemfile_root.glob("Gemfile.d/*.lock") + gemfile_root.glob("gems/*/Gemfile.lock")).each do |gem_lockfile_name|
|
|
|
|
return unless lockfile(gem_lockfile_name,
|
2023-10-10 22:23:36 +08:00
|
|
|
gemfile: gem_lockfile_name.to_s.sub(/\.lock$/, ""))
|
2023-10-06 03:19:24 +08:00
|
|
|
end
|
2023-09-12 23:20:10 +08:00
|
|
|
end
|
2023-03-29 06:56:26 +08:00
|
|
|
|
2023-05-23 05:51:35 +08:00
|
|
|
module PreferGlobalRubyGemsSource
|
|
|
|
def rubygems_sources
|
|
|
|
[global_rubygems_source] + non_global_rubygems_sources
|
|
|
|
end
|
|
|
|
end
|
2023-06-02 06:06:09 +08:00
|
|
|
Bundler::SourceList.prepend(PreferGlobalRubyGemsSource)
|
2023-05-23 05:51:35 +08:00
|
|
|
|
2023-05-03 01:01:05 +08:00
|
|
|
module GemOverride
|
|
|
|
def gem(name, *version, path: nil, **kwargs)
|
keep lockfiles in sync as part of `bundle` commands
closes AE-283
this eliminates script/sync_lockfiles.rb and integrates its
functionality directly into `bundle install`, `bundle check`, etc.
it also generalizes a few pieces so that the same approach is used
for all use cases:
* syncing versions between the main Gemfile and gems in gems/
* maintaining separate lockfiles for no plugins/including
private plugins
* maintaining separate lockfiles for multiple Rails versions
(crossed with the previous bullet)
The differences between them are just small variations on how strict
versions must match between lockfiles, and requiring pinning of
versions not in the default lockfile.
For full details, checks the docs on BundlerLockfileExtensions
This does change the strategy for filtering private plugin dependencies
out of the committed lockfile(s) - instead of filtering based on hash
of source, simply don't even include private plugin gems in the gemfile
when building the filtered lockfile (i.e. dynamic Gemfile, rather than
monkeypatching bundler to filter out -- semi-succesfully -- private
plugins from the Definition).
It also changes the "default" lockfile for Canvas that gets checked
in to be Gemfile.lock, so that other tools that are not
multi-lockfile aware can find it (such as rubocop, dependabot, and
others). This will be the lockfile corresponding to the current
default rails version for Canvas, and without private plugins.
Change-Id: I7ba398381974acbc4445f34fa3b788e8a07c5ce6
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/317888
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
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>
2023-05-11 02:12:39 +08:00
|
|
|
# Bundler calls `gem` internally by passing a splat with a hash as the
|
|
|
|
# last argument, instead of properly using kwargs. Detect that.
|
|
|
|
if version.last.is_a?(Hash) && kwargs.empty?
|
|
|
|
kwargs = version.pop
|
|
|
|
end
|
2023-05-17 06:01:22 +08:00
|
|
|
vendor_path = File.expand_path("vendor/#{name}", __dir__)
|
|
|
|
if File.directory?(vendor_path)
|
|
|
|
super(name, path: vendor_path, **kwargs)
|
2023-05-03 01:01:05 +08:00
|
|
|
else
|
2023-06-02 06:06:09 +08:00
|
|
|
super(name, *version, path:, **kwargs)
|
2023-05-03 01:01:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Bundler::Dsl.prepend(GemOverride)
|
|
|
|
|
2023-10-06 03:19:24 +08:00
|
|
|
if @include_plugins
|
2023-09-20 07:29:39 +08:00
|
|
|
gemfile_root.glob("gems/plugins/*/Gemfile.d/_before.rb") do |file|
|
keep lockfiles in sync as part of `bundle` commands
closes AE-283
this eliminates script/sync_lockfiles.rb and integrates its
functionality directly into `bundle install`, `bundle check`, etc.
it also generalizes a few pieces so that the same approach is used
for all use cases:
* syncing versions between the main Gemfile and gems in gems/
* maintaining separate lockfiles for no plugins/including
private plugins
* maintaining separate lockfiles for multiple Rails versions
(crossed with the previous bullet)
The differences between them are just small variations on how strict
versions must match between lockfiles, and requiring pinning of
versions not in the default lockfile.
For full details, checks the docs on BundlerLockfileExtensions
This does change the strategy for filtering private plugin dependencies
out of the committed lockfile(s) - instead of filtering based on hash
of source, simply don't even include private plugin gems in the gemfile
when building the filtered lockfile (i.e. dynamic Gemfile, rather than
monkeypatching bundler to filter out -- semi-succesfully -- private
plugins from the Definition).
It also changes the "default" lockfile for Canvas that gets checked
in to be Gemfile.lock, so that other tools that are not
multi-lockfile aware can find it (such as rubocop, dependabot, and
others). This will be the lockfile corresponding to the current
default rails version for Canvas, and without private plugins.
Change-Id: I7ba398381974acbc4445f34fa3b788e8a07c5ce6
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/317888
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
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>
2023-05-11 02:12:39 +08:00
|
|
|
eval_gemfile(file)
|
|
|
|
end
|
2017-10-12 02:10:24 +08:00
|
|
|
end
|
|
|
|
|
2023-09-20 07:29:39 +08:00
|
|
|
gemfile_root.glob("Gemfile.d/*.rb").each do |file|
|
keep lockfiles in sync as part of `bundle` commands
closes AE-283
this eliminates script/sync_lockfiles.rb and integrates its
functionality directly into `bundle install`, `bundle check`, etc.
it also generalizes a few pieces so that the same approach is used
for all use cases:
* syncing versions between the main Gemfile and gems in gems/
* maintaining separate lockfiles for no plugins/including
private plugins
* maintaining separate lockfiles for multiple Rails versions
(crossed with the previous bullet)
The differences between them are just small variations on how strict
versions must match between lockfiles, and requiring pinning of
versions not in the default lockfile.
For full details, checks the docs on BundlerLockfileExtensions
This does change the strategy for filtering private plugin dependencies
out of the committed lockfile(s) - instead of filtering based on hash
of source, simply don't even include private plugin gems in the gemfile
when building the filtered lockfile (i.e. dynamic Gemfile, rather than
monkeypatching bundler to filter out -- semi-succesfully -- private
plugins from the Definition).
It also changes the "default" lockfile for Canvas that gets checked
in to be Gemfile.lock, so that other tools that are not
multi-lockfile aware can find it (such as rubocop, dependabot, and
others). This will be the lockfile corresponding to the current
default rails version for Canvas, and without private plugins.
Change-Id: I7ba398381974acbc4445f34fa3b788e8a07c5ce6
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/317888
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
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>
2023-05-11 02:12:39 +08:00
|
|
|
eval_gemfile(file)
|
2017-10-12 02:10:24 +08:00
|
|
|
end
|