Skip to content

Commit

Permalink
manage libGKS
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Sep 23, 2022
1 parent 3693598 commit 816adc3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/GR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function init(always::Bool = false)
return
end
if check_env[] || always
get!(ENV, "GKS_FONTPATH", GRPreferences.grdir[])
haskey(ENV, "GKS_FONTPATH") || get!(ENV, "GKS_FONTPATH", GRPreferences.grdir[])
ENV["GKS_USE_CAIRO_PNG"] = "true"
if "GRDISPLAY" in keys(ENV)
display_name[] = ENV["GRDISPLAY"]
Expand All @@ -326,28 +326,26 @@ function init(always::Bool = false)
ENV["GKS_FILEPATH"] = file_path[]
@debug "Found an embedded environment" mime_type[] file_path[] ENV["GKSwstype"] ENV["GKS_FILEPATH"]
else
if !haskey(ENV, "GKSwstype")
ENV["GKSwstype"] = "gksqt"
end
haskey(ENV, "GKSwstype") || get!(ENV, "GKSwstype", "gksqt")
@static if Sys.iswindows()
if !haskey(ENV, "GKS_QT")
ENV["GKS_QT"] = string("set PATH=", GRPreferences.libpath[], " & \"", GRPreferences.gksqt[], "\"")
ENV["GKS_QT"] = string("set PATH=", GRPreferences.libpath[], " & \"", GRPreferences.gks[], "\"")
elseif ENV["GKS_QT"] == ""
ENV["PATH"] = GRPreferences.libpath[]
gkqst = run(`$(GRPreferences.gksqt[])`; wait = false)
gkqst = run(`$(GRPreferences.gks[])`; wait = false)
# gksqt(gkscmd -> run(`gksqt`; wait=false))
end
else
env = (os == :Darwin) ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH"
ENV["GKS_QT"] = string("env $env=", GRPreferences.libpath[], " ", GRPreferences.gksqt[])
ENV["GKS_QT"] = string("env $env=", GRPreferences.libpath[], " ", GRPreferences.gks[])
end
@debug "BinaryBuilder Setup" ENV["GKSwstype"] os ENV["GKS_QT"] ENV["PATH"] GRPreferences.libpath[] GRPreferences.gksqt[]
@debug "BinaryBuilder Setup" ENV["GKSwstype"] os ENV["GKS_QT"] ENV["PATH"] GRPreferences.libpath[] GRPreferences.gks[]
end
if "GKS_IGNORE_ENCODING" in keys(ENV)
text_encoding[] = ENCODING_UTF8
@debug "Found GKS_IGNORE_ENCODING in ENV" text_encoding[]
elseif "GKS_ENCODING" in keys(ENV)
text_encoding[] = if ENV["GKS_ENCODING"] == "latin1" || ENV["GKS_ENCODING"] == "latin-1"
text_encoding[] = if (enc = ENV["GKS_ENCODING"]) == "latin1" || enc == "latin-1"
ENCODING_LATIN1
else
ENCODING_UTF8
Expand Down
22 changes: 19 additions & 3 deletions src/preferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ module GRPreferences
const os = Sys.KERNEL === :NT ? :Windows : Sys.KERNEL

const grdir = Ref{Union{Nothing,String}}()
const gksqt = Ref{Union{Nothing,String}}()
const gks = Ref{Union{Nothing,String}}()
const libGR = Ref{Union{Nothing,String}}()
const libGR3 = Ref{Union{Nothing,String}}()
const libGRM = Ref{Union{Nothing,String}}()
const libGKS = Ref{Union{Nothing,String}}()
const libpath = Ref{Union{Nothing,String}}()

lib_path(grdir, lib) =
Expand All @@ -24,21 +25,36 @@ module GRPreferences
joinpath(grdir, "lib", lib)
end

function gks_path(grdir)
bin = joinpath(grdir[], "bin")
exe = if os === :Windows
"gksqt.exe"
elseif os === :Darwin
isfile(joinpath(bin, "GKSTerm")) ? "GKSTerm" : "gksqt"
else
"gksqt"
end
joinpath(bin, exe)
end


function __init__()
binary = @load_preference("binary", haskey(ENV, "GRDIR") ? "system" : "GR_jll")
if binary == "GR_jll"
grdir[] = GR_jll.find_artifact_dir()
gksqt[] = GR_jll.gksqt_path
gks[] = GR_jll.gksqt_path
libGR[] = GR_jll.libGR
libGR3[] = GR_jll.libGR3
libGRM[] = GR_jll.libGRM
libGKS[] = GR_jll.libGKS
libpath[] = GR_jll.LIBPATH[]
elseif binary == "system"
grdir[] = haskey(ENV, "GRDIR") ? ENV["GRDIR"] : @load_preference("grdir")
gksqt[] = joinpath(grdir[], "bin", "gksqt" * (os === :Windows ? ".exe" : ""))
gks[] = gks_path(gkdir[])
libGR[] = lib_path(grdir[], "libGR")
libGR3[] = lib_path(grdir[], "libGR3")
libGRM[] = lib_path(grdir[], "libGRM")
libGKS[] = lib_path(grdir[], "libGKS")
libpath[] = joinpath(grdir[], "lib")
else
error("Unknown GR binary: $binary")
Expand Down

0 comments on commit 816adc3

Please sign in to comment.