Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 1 #4

Merged
merged 6 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name = "GmshTools"
uuid = "82e2f556-b1bd-5f1a-9576-f93c0da5f0ee"
authors = ["Pengcheng Shi"]
version = "0.3.5"
version = "0.4.0"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[compat]
julia = "1"
BinaryProvider = "0.5.8"
MLStyle = "0.3.1"
julia = "1.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
88 changes: 38 additions & 50 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,59 +1,47 @@
using BinaryProvider
using Libdl
using Pkg

const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
const libname = Sys.iswindows() ? "gmsh-4.5" : "libgmsh"
Pkg.add(PackageSpec(url="https://github.com/shipengcheng1230/Gmsh_jll.jl"))

products = Product[
LibraryProduct(prefix, libname, :libgmsh),
]
const depsfile = joinpath(@__DIR__, "deps.jl")

bin_prefix = "http://gmsh.info/bin"
version = "4.5.5"
const libpath = get(ENV, "GMSH_LIB_PATH", nothing)

download_info = Dict(
Linux(:x86_64, :glibc) => ("$bin_prefix/Linux/gmsh-$version-Linux64-sdk.tgz", "d068f28be4271e57582624cbdb39927b6ed9929b50f88ad828ac9add015004ae"),
Windows(:x86_64) => ("$bin_prefix/Windows/gmsh-$version-Windows64-sdk.zip", "e87fc92a312814be09a196ab7bef34dd104070d0d10de6eda0f0087f6564266d"),
MacOS(:x86_64) => ("$bin_prefix/MacOSX/gmsh-$version-MacOSX-sdk.tgz", "9f560f51a43603d20fd54bc3fc4294c6ef292a570ac8c69095f81fe1164afc30"),
)

if haskey(ENV, "GMSH_LIB_PATH")
products = Product[LibraryProduct(ENV["GMSH_LIB_PATH"], libname, :libgmsh),]
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
if libpath === nothing
open(depsfile, "w") do io
print(io,
raw"""
# This file is automatically generated
# Do not edit
using Gmsh_SDK_jll
check_deps() = nothing
"""
)
else
if any(!satisfied(p; verbose=verbose) for p in products)
try
# download and install binaries
url, tarball_hash = choose_download(download_info)
try
install(url, tarball_hash; prefix=prefix, force=true, verbose=true)
catch e
# cannot list content of .zip, manually unzip
tarball_path = joinpath(prefix, "downloads", basename(url))
run(`unzip $(tarball_path) -d $(prefix.path)`)
end
# For windows, you must create a link from `gmsh-*.*.dll` to `libgmsh.dll`
libgmsh = find_library("libgmsh", [libpath])
if isempty(libgmsh)
@static if Sys.iswindows()
@info "You may create a link from `gmsh-*.*.dll` to `libgmsh.dll`."
end
error("libgmsh is not found in $libpath.")
end

# strip the top directory
content_path = joinpath(prefix, splitext(basename(url))[1])
foreach(
(x) -> mv(joinpath(content_path, x), joinpath(prefix, x); force=true),
readdir(content_path)
)
rm(content_path; force=true, recursive=true)
libgmsh_size = filesize(dlpath())

# BinaryProvider will search $prefix/bin instead of $prefix/lib
if Sys.iswindows()
dir_path = libdir(products[1].prefix, platform_key_abi())
lib_path = joinpath(dirname(dir_path), "lib")
run(`cp -L $(lib_path)/* $(dir_path)`)
end
catch e
if typeof(e) <: ArgumentError
error("Your platform $(Sys.MACHINE) is not supported by this package!")
else
rethrow(e)
end
end
open(depsfile, "w") do io
println(io,
"""
# This file is automatically generated
# Do not edit
function check_deps()
if libgmsh_size != filesize(Libdl.dlpath(libgmsh_size))
error("Gmsh library has changed, re-run Pkg.build(\\\"GmshTools\\\")")
end
end
"""
)
println(io, :(const libgmsh = $libgmsh))
println(io, :(const libgmsh_size = $libgmsh_size))
end
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
end
21 changes: 8 additions & 13 deletions src/GmshTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@ module GmshTools

using MLStyle

const depsjl_path = joinpath(@__DIR__, "..", "deps", "deps.jl")
const depsfile = joinpath(@__DIR__, "..", "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
else
error("GmshTools is not properly installed. Please run Pkg.build(\"GmshTools\") ",
"and restart Julia.")
end

function __init__()
try
include(depsjl_path)
gmshmodule = joinpath(dirname(libgmsh), "gmsh.jl")
include(gmshmodule)
Base.invokelatest(check_deps) # world age problem
catch ex
if isa(ex, ErrorException)
@error "libgmsh not installed properly. Please check *.travis* for additional dependencies and rebuild this package."
else
rethrow(ex)
end
end
check_deps()
end

export gmsh, @gmsh_do, @gmsh_open
Expand Down