Skip to content

Commit

Permalink
Use temp dir (no scratch space) for mutable GAP root
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Dec 10, 2024
1 parent 0412fa6 commit de7bed9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 60 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Ncurses_jll = "68e3532b-a499-55ff-9963-d1c0c0748b3a"
Pidfile = "fa939f87-e72e-5be4-a000-7fc836dbe307"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
Expand All @@ -38,6 +39,7 @@ Markdown = "1.6"
Ncurses_jll = "6.4.1"
Pidfile = "1.3"
Pkg = "1.6"
PrecompileTools = "1.2.1"
REPL = "1.6"
Random = "1.6"
Scratch = "1.1"
Expand Down
20 changes: 16 additions & 4 deletions src/GAP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ import Libdl
import Random

# setup the initial sysinfo dictionary; we'll update this later in __init__
# this also ensures that Setup.regenerate_gaproot gets precompiled, reducing
# the startup time a little bit
const sysinfo = Setup.regenerate_gaproot()

const sysinfo = Dict{String, String}()

include("types.jl")

Expand Down Expand Up @@ -336,4 +333,19 @@ include("prompt.jl")
include("exec.jl")
include("doctestfilters.jl")

################################################################################
#
# Precompilation
#
################################################################################

using PrecompileTools: @setup_workload, @compile_workload

@setup_workload begin
@compile_workload begin
sysinfo = Setup.regenerate_gaproot()
Setup.locate_JuliaInterface_so(sysinfo)
end
end

end
20 changes: 9 additions & 11 deletions src/packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module Packages

import Downloads
import Pidfile
import ...GAP: Globals, GapObj, replace_global!, RNamObj, sysinfo, Wrappers
import ...GAP: GAP, Globals, GapObj, replace_global!, RNamObj, Wrappers

const DEFAULT_PKGDIR = Ref{String}()
const DOWNLOAD_HELPER = Ref{Downloads.Downloader}()

function init_packagemanager()
Expand All @@ -16,7 +15,6 @@ function init_packagemanager()
res = load("PackageManager")
@assert res

global DEFAULT_PKGDIR[] = sysinfo["DEFAULT_PKGDIR"]
global DOWNLOAD_HELPER[] = Downloads.Downloader(; grace=0.1)

# overwrite PKGMAN_DownloadURL
Expand Down Expand Up @@ -211,7 +209,7 @@ end
install(spec::String, version::String = "";
interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
Download and install the GAP package given by `spec` into the `pkgdir`
directory.
Expand Down Expand Up @@ -239,7 +237,7 @@ For details, please refer to its documentation.
function install(spec::String, version::String = "";
interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)
Expand Down Expand Up @@ -287,7 +285,7 @@ end
"""
update(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
Update the GAP package given by `spec` that is installed in the
`pkgdir` directory, to the latest version.
Expand All @@ -306,7 +304,7 @@ For details, please refer to its documentation.
"""
function update(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)
Expand All @@ -328,7 +326,7 @@ end
"""
remove(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
Remove the GAP package with name `spec` that is installed in the
`pkgdir` directory.
Expand All @@ -343,7 +341,7 @@ For details, please refer to its documentation.
"""
function remove(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)
Expand All @@ -362,7 +360,7 @@ end
"""
build(name::String; quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
Build the GAP package with name `name` that is installed in the
`pkgdir` directory.
Expand All @@ -379,7 +377,7 @@ The info messages shown by this function can be suppressed by passing
"""
function build(name::String; quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
pkgdir::AbstractString = GAP.sysinfo["DEFAULT_PKGDIR"])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)
Expand Down
89 changes: 44 additions & 45 deletions src/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import Artifacts: find_artifacts_toml, @artifact_str
import GAP_jll
import GAP_lib_jll
import GAP_pkg_juliainterface_jll
import Scratch: @get_scratch!
import Pidfile
import TOML

# to separate the scratchspaces of different GAP.jl copies and Julia versions
# put the Julia version and the hash of the path to this file into the key
const scratch_key = "gap_$(hash(@__FILE__))-$(VERSION.major).$(VERSION.minor)"
const _gaproot = Ref{String}()

gaproot() = @get_scratch!(scratch_key)
function gaproot()
if !isassigned(_gaproot)
_gaproot[] = mktempdir()
end
return _gaproot[]
end

#############################################################################
#
Expand Down Expand Up @@ -160,50 +161,48 @@ function regenerate_gaproot()

# create the mutable gaproot
mkpath(gaproot_mutable)
Pidfile.mkpidlock("$gaproot_mutable.lock"; stale_age=10) do
# create fake sysinfo.gap
unquoted = Set(["GAParch", "GAP_ABI", "GAP_HPCGAP", "GAP_KERNEL_MAJOR_VERSION", "GAP_KERNEL_MINOR_VERSION", "GAP_OBJEXT"])
open("$gaproot_mutable/sysinfo.gap", "w") do file
write(file, """
# This file has been generated by the GAP build system,
# do not edit manually!
""")
for key in sort(collect(keys(sysinfo)))
if key in unquoted
str = "$(key)=$(sysinfo[key])"
else
str = "$(key)=\"$(sysinfo[key])\""
end
write(file, str, "\n")

# create fake sysinfo.gap
unquoted = Set(["GAParch", "GAP_ABI", "GAP_HPCGAP", "GAP_KERNEL_MAJOR_VERSION", "GAP_KERNEL_MINOR_VERSION", "GAP_OBJEXT"])
open("$gaproot_mutable/sysinfo.gap", "w") do file
write(file, """
# This file has been generated by the GAP build system,
# do not edit manually!
""")
for key in sort(collect(keys(sysinfo)))
if key in unquoted
str = "$(key)=$(sysinfo[key])"
else
str = "$(key)=\"$(sysinfo[key])\""
end
write(file, str, "\n")
end
end

# patch gac to load correct sysinfo.gap
gac = read(joinpath(gap_prefix, "bin", "gac"), String)
gac = replace(gac, r"^\. \"[^\"]+\"$"m => ". \"$(gaproot_mutable)/sysinfo.gap\"")
write("$gaproot_mutable/gac", gac)
chmod("$gaproot_mutable/gac", 0o755)

#
mkpath(joinpath(gaproot_mutable, "bin"))
for d in (("include/gap", "src"), ("lib", "lib"), ("bin/gap", "gap"))
force_symlink(joinpath(gap_prefix, d[1]), joinpath(gaproot_mutable, d[2]))
end
# patch gac to load correct sysinfo.gap
gac = read(joinpath(gap_prefix, "bin", "gac"), String)
gac = replace(gac, r"^\. \"[^\"]+\"$"m => ". \"$(gaproot_mutable)/sysinfo.gap\"")
write("$gaproot_mutable/gac", gac)
chmod("$gaproot_mutable/gac", 0o755)

# emulate the "compat mode" of the GAP build system, to help certain
# packages like Browse with an outdated build system
mkpath(joinpath(gaproot_mutable, "bin", sysinfo["GAParch"]))
force_symlink("../../gac",
joinpath(gaproot_mutable, "bin", sysinfo["GAParch"], "gac"))

# create a `pkg` directory with symlinks to all the GAP packages artifacts
mkpath(joinpath(gaproot_mutable, "pkg"))
pkg_artifacts = filter(startswith("GAP_pkg_"), keys(TOML.parsefile(find_artifacts_toml(@__FILE__))))
for name in pkg_artifacts
force_symlink(@artifact_str(name), joinpath(gaproot_mutable, "pkg", name))
end
#
mkpath(joinpath(gaproot_mutable, "bin"))
for d in (("include/gap", "src"), ("lib", "lib"), ("bin/gap", "gap"))
force_symlink(joinpath(gap_prefix, d[1]), joinpath(gaproot_mutable, d[2]))
end

end # mkpidlock
# emulate the "compat mode" of the GAP build system, to help certain
# packages like Browse with an outdated build system
mkpath(joinpath(gaproot_mutable, "bin", sysinfo["GAParch"]))
force_symlink("../../gac",
joinpath(gaproot_mutable, "bin", sysinfo["GAParch"], "gac"))

# create a `pkg` directory with symlinks to all the GAP packages artifacts
mkpath(joinpath(gaproot_mutable, "pkg"))
pkg_artifacts = filter(startswith("GAP_pkg_"), keys(TOML.parsefile(find_artifacts_toml(@__FILE__))))
for name in pkg_artifacts
force_symlink(@artifact_str(name), joinpath(gaproot_mutable, "pkg", name))
end

return sysinfo
end
Expand Down

0 comments on commit de7bed9

Please sign in to comment.