@@ -1502,6 +1502,7 @@ function _tryrequire_from_serialized(modkey::PkgId, build_id::UInt128)
1502
1502
assert_havelock (require_lock)
1503
1503
loaded = nothing
1504
1504
if root_module_exists (modkey)
1505
+ warn_if_already_loaded_different (modkey)
1505
1506
loaded = root_module (modkey)
1506
1507
else
1507
1508
loaded = start_loading (modkey)
@@ -1532,6 +1533,7 @@ function _tryrequire_from_serialized(modkey::PkgId, path::String, ocachepath::Un
1532
1533
assert_havelock (require_lock)
1533
1534
loaded = nothing
1534
1535
if root_module_exists (modkey)
1536
+ warn_if_already_loaded_different (modkey)
1535
1537
loaded = root_module (modkey)
1536
1538
else
1537
1539
loaded = start_loading (modkey)
@@ -1975,11 +1977,50 @@ function __require_prelocked(uuidkey::PkgId, env=nothing)
1975
1977
# After successfully loading, notify downstream consumers
1976
1978
run_package_callbacks (uuidkey)
1977
1979
else
1980
+ warn_if_already_loaded_different (uuidkey)
1978
1981
newm = root_module (uuidkey)
1979
1982
end
1980
1983
return newm
1981
1984
end
1982
1985
1986
+ const already_warned_path_change_pkgs = Set {UUID} ()
1987
+ # warns if the loaded version of a module is different to the one that locate_package wants to load
1988
+ function warn_if_already_loaded_different (uuidkey:: PkgId )
1989
+ uuidkey. uuid ∈ already_warned_path_change_pkgs && return
1990
+ pkgorig = get (pkgorigins, uuidkey, nothing )
1991
+ if pkgorig != = nothing && pkgorig. path != = nothing
1992
+ new_path = locate_package (uuidkey)
1993
+ if ! samefile (fixup_stdlib_path (pkgorig. path), new_path)
1994
+ if isnothing (pkgorig. version)
1995
+ v = get_pkgversion_from_path (dirname (dirname (pkgorig. path)))
1996
+ cur_vstr = isnothing (v) ? " " : " v$v "
1997
+ else
1998
+ cur_vstr = " v$v "
1999
+ end
2000
+ new_v = get_pkgversion_from_path (dirname (dirname (new_path)))
2001
+ new_vstr = isnothing (new_v) ? " " : " v$new_v "
2002
+ warnstr = """
2003
+ $uuidkey is already loaded from a different path:
2004
+ loaded: $cur_vstr$(repr (pkgorig. path))
2005
+ requested: $new_vstr$(repr (new_path))
2006
+ """
2007
+ if isempty (already_warned_path_change_pkgs)
2008
+ warnstr *= """
2009
+ This might indicate a change of environment has happened between package loads and can mean that
2010
+ incompatible packages have been loaded"""
2011
+ if JLOptions (). startupfile < 2 # (0 = auto, 1 = yes)
2012
+ warnstr *= """ . If this happened due to a startup.jl consider starting julia
2013
+ directly in the project via the `--project` arg."""
2014
+ else
2015
+ warnstr *= " ."
2016
+ end
2017
+ end
2018
+ @warn warnstr
2019
+ push! (already_warned_path_change_pkgs, uuidkey. uuid)
2020
+ end
2021
+ end
2022
+ end
2023
+
1983
2024
mutable struct PkgOrigin
1984
2025
path:: Union{String,Nothing}
1985
2026
cachepath:: Union{String,Nothing}
0 commit comments