Use zeitwerk everywhere always
Change-Id: Ide7490f4e8d2447b147328b6f7e2afc545941c14 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/287599 Reviewed-by: Aaron Ogata <aogata@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Jacob Burroughs <jburroughs@instructure.com> Product-Review: Jacob Burroughs <jburroughs@instructure.com>
This commit is contained in:
parent
d931f0b59f
commit
4253bed58b
|
@ -481,28 +481,6 @@ pipeline {
|
|||
sh 'build/new-jenkins/consumer-smoke-test.sh'
|
||||
}
|
||||
|
||||
extendedStage('Zeitwerk Check').hooks(buildSummaryReportHooks.call()).queue(stages) {
|
||||
withEnv([
|
||||
'COMPOSE_FILE=docker-compose.new-jenkins.yml',
|
||||
'CANVAS_ZEITWERK=1'
|
||||
]) {
|
||||
// the purpose of this stage is to ensure any new code introduce to canvas or any
|
||||
// autoloaded/eager-loaded dependencies conforms to our zeitwerk config
|
||||
// so we can start using zeitwerk as our code loader.
|
||||
//
|
||||
// the generally expected file structure can be found here: https://github.com/fxn/zeitwerk#file-structure
|
||||
sh '''
|
||||
echo "HEY HUMAN!"
|
||||
echo "**********"
|
||||
echo "Are you debugging a build failure here?"
|
||||
echo "see general zeitwerk rules, it may help: https://github.com/fxn/zeitwerk#file-structure"
|
||||
echo "**********"
|
||||
echo "HEY HUMAN!"
|
||||
docker-compose -p "zeitwerk-check" run --rm canvas bash -c "./bin/rails zeitwerk:check"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
extendedStage(JS_BUILD_IMAGE_STAGE)
|
||||
.hooks(buildSummaryReportHooks.call())
|
||||
.queue(stages, buildDockerImageStage.&jsImage)
|
||||
|
|
|
@ -112,7 +112,6 @@ pipeline {
|
|||
POSTGRES_PASSWORD = 'sekret'
|
||||
RSPECQ_REDIS_URL = redisUrl()
|
||||
PATCHSET_TAG = getPatchsetTag()
|
||||
CANVAS_ZEITWERK = '1'
|
||||
|
||||
CASSANDRA_PREFIX = configuration.buildRegistryPath('cassandra-migrations')
|
||||
DYNAMODB_PREFIX = configuration.buildRegistryPath('dynamodb-migrations')
|
||||
|
|
|
@ -169,7 +169,6 @@ pipeline {
|
|||
ENABLE_AXE_SELENIUM = "${env.ENABLE_AXE_SELENIUM}"
|
||||
POSTGRES_PASSWORD = 'sekret'
|
||||
RSPECQ_REDIS_URL = redisUrl()
|
||||
CANVAS_ZEITWERK = '1'
|
||||
}
|
||||
|
||||
stages {
|
||||
|
|
|
@ -27,51 +27,20 @@ require "rails/test_unit/railtie"
|
|||
|
||||
Bundler.require(*Rails.groups)
|
||||
|
||||
# Zeitwerk does not HAVE to be enabled with rails 6
|
||||
# Use this environment variable (which may have other file-based ways
|
||||
# to trigger it later) in order to determine which autoloader we should
|
||||
# use. The goal is to move to zeitwerk over time.
|
||||
# https://guides.rubyonrails.org/autoloading_and_reloading_constants.html
|
||||
# One way to set this in development would be to use your docker-compose.override.yml
|
||||
# file to pass an env var to the web container:
|
||||
#
|
||||
# web:
|
||||
# <<: *BASE
|
||||
# environment:
|
||||
# <<: *BASE-ENV
|
||||
# VIRTUAL_HOST: .canvas.docker
|
||||
# ...
|
||||
# CANVAS_ZEITWERK: 1
|
||||
unless defined?(CANVAS_ZEITWERK)
|
||||
# choose to force zeitwerk on
|
||||
# unless overridden with
|
||||
# an env var or file
|
||||
CANVAS_ZEITWERK = if ENV["CANVAS_ZEITWERK"]
|
||||
(ENV["CANVAS_ZEITWERK"] == "1")
|
||||
elsif Rails.root && (zw_settings = ConfigFile.load("zeitwerk"))
|
||||
zw_settings["enabled"]
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
# TODO: remove once no plugins require this
|
||||
CANVAS_ZEITWERK = true
|
||||
|
||||
module CanvasRails
|
||||
class Application < Rails::Application
|
||||
# this CANVAS_ZEITWERK constant flag is defined above in this file.
|
||||
# It should be temporary,
|
||||
# and removed once we've fully upgraded to zeitwerk autoloading,
|
||||
# at which point the stuff inside this conditional block should remain.
|
||||
if CANVAS_ZEITWERK
|
||||
config.autoloader = :zeitwerk
|
||||
config.autoloader = :zeitwerk
|
||||
|
||||
# TODO: someday we can use this line, which will NOT
|
||||
# add anything on the autoload paths the actual ruby
|
||||
# $LOAD_PATH because zeitwerk will take care of anything
|
||||
# we autolaod. This will make ACTUAL require statements
|
||||
# that are necessary work faster because they'll have a smaller
|
||||
# load path to scan.
|
||||
# config.add_autoload_paths_to_load_path = false
|
||||
end
|
||||
# TODO: someday we can use this line, which will NOT
|
||||
# add anything on the autoload paths the actual ruby
|
||||
# $LOAD_PATH because zeitwerk will take care of anything
|
||||
# we autolaod. This will make ACTUAL require statements
|
||||
# that are necessary work faster because they'll have a smaller
|
||||
# load path to scan.
|
||||
# config.add_autoload_paths_to_load_path = false
|
||||
|
||||
$LOAD_PATH << config.root.to_s
|
||||
config.encoding = "utf-8"
|
||||
|
|
|
@ -17,53 +17,48 @@
|
|||
# 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/>.
|
||||
|
||||
# this CANVAS_ZEITWERK constant flag is defined in canvas' "application.rb"
|
||||
# from an env var. It should be temporary,
|
||||
# and removed once we've fully upgraded to zeitwerk autoloading.
|
||||
if CANVAS_ZEITWERK
|
||||
# This is because the jsx folder does not contain ruby to
|
||||
# autoload. You should NOT use this pattern as a workaround
|
||||
# for badly-named ruby code.
|
||||
Rails.autoloaders.main.ignore(Rails.root.join("app/jsx"))
|
||||
# This is because the jsx folder does not contain ruby to
|
||||
# autoload. You should NOT use this pattern as a workaround
|
||||
# for badly-named ruby code.
|
||||
Rails.autoloaders.main.ignore(Rails.root.join("app/jsx"))
|
||||
|
||||
Rails.autoloaders.main.ignore(
|
||||
# we don't want zeitwerk to try to eager_load some "Version" constant from any plugins
|
||||
"#{__dir__}/../../gems/plugins/simply_versioned/lib/simply_versioned/gem_version.rb",
|
||||
"#{__dir__}/../../lib/cdc_migration_testing", # these aren't really modules we use in canvas runtime
|
||||
"#{__dir__}/../../gems/plugins/*/lib/cdc_migration_testing"
|
||||
Rails.autoloaders.main.ignore(
|
||||
# we don't want zeitwerk to try to eager_load some "Version" constant from any plugins
|
||||
"#{__dir__}/../../gems/plugins/simply_versioned/lib/simply_versioned/gem_version.rb",
|
||||
"#{__dir__}/../../lib/cdc_migration_testing", # these aren't really modules we use in canvas runtime
|
||||
"#{__dir__}/../../gems/plugins/*/lib/cdc_migration_testing"
|
||||
)
|
||||
|
||||
Rails.autoloaders.each do |autoloader|
|
||||
autoloader.inflector.inflect(
|
||||
"api_array_serializer" => "APIArraySerializer",
|
||||
"api_serialization" => "APISerialization",
|
||||
"api_serializer" => "APISerializer",
|
||||
"aws" => "AWS",
|
||||
"basic_lti" => "BasicLTI",
|
||||
"basic_lti_links" => "BasicLTILinks",
|
||||
"brandable_css" => "BrandableCSS",
|
||||
"cas" => "CAS",
|
||||
"cc" => "CC",
|
||||
"cc_helper" => "CCHelper",
|
||||
"cc_exporter" => "CCExporter",
|
||||
"cc_worker" => "CCWorker",
|
||||
"dynamo_db" => "DynamoDB",
|
||||
"icu" => "ICU",
|
||||
"id_loader" => "IDLoader",
|
||||
"ims" => "IMS",
|
||||
"inst_fs" => "InstFS",
|
||||
"ldap" => "LDAP",
|
||||
"legacy_id_interface" => "LegacyIDInterface",
|
||||
"open_id_connect" => "OpenIDConnect",
|
||||
"saml" => "SAML",
|
||||
"sis" => "SIS",
|
||||
"sisid_loader" => "SISIDLoader",
|
||||
"sms_presenter" => "SMSPresenter",
|
||||
"ssl_common" => "SSLCommon",
|
||||
"turnitin_id" => "TurnitinID",
|
||||
"uk_federation" => "UKFederation",
|
||||
"vericite" => "VeriCite",
|
||||
"xml_helper" => "XMLHelper"
|
||||
)
|
||||
|
||||
Rails.autoloaders.each do |autoloader|
|
||||
autoloader.inflector.inflect(
|
||||
"api_array_serializer" => "APIArraySerializer",
|
||||
"api_serialization" => "APISerialization",
|
||||
"api_serializer" => "APISerializer",
|
||||
"aws" => "AWS",
|
||||
"basic_lti" => "BasicLTI",
|
||||
"basic_lti_links" => "BasicLTILinks",
|
||||
"brandable_css" => "BrandableCSS",
|
||||
"cas" => "CAS",
|
||||
"cc" => "CC",
|
||||
"cc_helper" => "CCHelper",
|
||||
"cc_exporter" => "CCExporter",
|
||||
"cc_worker" => "CCWorker",
|
||||
"dynamo_db" => "DynamoDB",
|
||||
"icu" => "ICU",
|
||||
"id_loader" => "IDLoader",
|
||||
"ims" => "IMS",
|
||||
"inst_fs" => "InstFS",
|
||||
"ldap" => "LDAP",
|
||||
"legacy_id_interface" => "LegacyIDInterface",
|
||||
"open_id_connect" => "OpenIDConnect",
|
||||
"saml" => "SAML",
|
||||
"sis" => "SIS",
|
||||
"sisid_loader" => "SISIDLoader",
|
||||
"sms_presenter" => "SMSPresenter",
|
||||
"ssl_common" => "SSLCommon",
|
||||
"turnitin_id" => "TurnitinID",
|
||||
"uk_federation" => "UKFederation",
|
||||
"vericite" => "VeriCite",
|
||||
"xml_helper" => "XMLHelper"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,6 @@ services:
|
|||
RERUNS_RETRY:
|
||||
COVERAGE:
|
||||
FORCE_FAILURE:
|
||||
CANVAS_ZEITWERK:
|
||||
TEST_CACHE_CLASSES:
|
||||
|
||||
# parallel_tests
|
||||
|
|
|
@ -17,18 +17,12 @@
|
|||
# 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/>.
|
||||
|
||||
# this CANVAS_ZEITWERK constant flag is defined in canvas' "application.rb"
|
||||
# from an env var. It should be temporary,
|
||||
# and removed once we've fully upgraded to zeitwerk autoloading.
|
||||
if defined?(CANVAS_ZEITWERK) && CANVAS_ZEITWERK
|
||||
|
||||
# it's standard practice to ignore parts of the project
|
||||
# that intentionally don't follow the zeitwerk pattern
|
||||
# because they do something like monkeypatch a constant
|
||||
# defined elsewhere https://github.com/fxn/zeitwerk#use-case-files-that-do-not-follow-the-conventions.
|
||||
#
|
||||
# these extensions are required explicitly by the gem engine when it's ready to patch,
|
||||
# so that they can modify constants defined in a third party gem,
|
||||
# and so don't need to be autoloaded
|
||||
Rails.autoloaders.main.ignore("#{__dir__}/../../lib/academic_benchmark/ab_gem_extensions")
|
||||
end
|
||||
# it's standard practice to ignore parts of the project
|
||||
# that intentionally don't follow the zeitwerk pattern
|
||||
# because they do something like monkeypatch a constant
|
||||
# defined elsewhere https://github.com/fxn/zeitwerk#use-case-files-that-do-not-follow-the-conventions.
|
||||
#
|
||||
# these extensions are required explicitly by the gem engine when it's ready to patch,
|
||||
# so that they can modify constants defined in a third party gem,
|
||||
# and so don't need to be autoloaded
|
||||
Rails.autoloaders.main.ignore("#{__dir__}/../../lib/academic_benchmark/ab_gem_extensions")
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# this CANVAS_ZEITWERK constant flag is defined in canvas' "application.rb"
|
||||
# from an env var. It should be temporary,
|
||||
# and removed once we've fully upgraded to zeitwerk autoloading.
|
||||
if defined?(CANVAS_ZEITWERK) && CANVAS_ZEITWERK
|
||||
# we don't want zeitwerk to try to eager_load some
|
||||
# "Version" constant, as it won't exist
|
||||
Rails.autoloaders.main.ignore("#{__dir__}/../../lib/qti_exporter/version.rb")
|
||||
end
|
||||
# we don't want zeitwerk to try to eager_load some
|
||||
# "Version" constant, as it won't exist
|
||||
Rails.autoloaders.main.ignore("#{__dir__}/../../lib/qti_exporter/version.rb")
|
||||
|
|
Loading…
Reference in New Issue