@@ -1364,6 +1364,59 @@ end
13641364
13651365# End extensions
13661366
1367+ # should sync with the types of arguments of `stale_cachefile`
1368+ const StaleCacheKey = Tuple{Base. PkgId, UInt128, String, String}
1369+
1370+ """
1371+ Base.isprecompiled(pkg::PkgId)
1372+
1373+ Returns whether a given PkgId within the active project is precompiled.
1374+
1375+ !!! compat "Julia 1.10"
1376+ This function requires at least Julia 1.10.
1377+ """
1378+ function isprecompiled (pkg:: PkgId ;
1379+ stale_cache:: Dict{StaleCacheKey,Bool} = Dict {StaleCacheKey, Bool} (),
1380+ cachepaths:: Vector{String} = Base. find_all_in_cache_path (pkg),
1381+ sourcepath:: String = Base. locate_package (pkg)
1382+ )
1383+ isnothing (sourcepath) && error (" Cannot locate source for $(repr (PkgId)) " )
1384+ for path_to_try in cachepaths
1385+ staledeps = stale_cachefile (sourcepath, path_to_try, ignore_loaded = true )
1386+ if staledeps === true
1387+ continue
1388+ end
1389+ staledeps, _ = staledeps:: Tuple{Vector{Any}, Union{Nothing, String}}
1390+ # finish checking staledeps module graph
1391+ for i in 1 : length (staledeps)
1392+ dep = staledeps[i]
1393+ dep isa Module && continue
1394+ modpath, modkey, modbuild_id = dep:: Tuple{String, PkgId, UInt128}
1395+ modpaths = find_all_in_cache_path (modkey)
1396+ for modpath_to_try in modpaths:: Vector{String}
1397+ stale_cache_key = (modkey, modbuild_id, modpath, modpath_to_try):: StaleCacheKey
1398+ if get! (() -> stale_cachefile (stale_cache_key... , ignore_loaded= true ) === true ,
1399+ stale_cache, stale_cache_key)
1400+ continue
1401+ end
1402+ @goto check_next_dep
1403+ end
1404+ @goto check_next_path
1405+ @label check_next_dep
1406+ end
1407+ try
1408+ # update timestamp of precompilation file so that it is the first to be tried by code loading
1409+ touch (path_to_try)
1410+ catch ex
1411+ # file might be read-only and then we fail to update timestamp, which is fine
1412+ ex isa IOError || rethrow ()
1413+ end
1414+ return true
1415+ @label check_next_path
1416+ end
1417+ return false
1418+ end
1419+
13671420# loads a precompile cache file, after checking stale_cachefile tests
13681421function _tryrequire_from_serialized (modkey:: PkgId , build_id:: UInt128 )
13691422 assert_havelock (require_lock)
0 commit comments