From 04d81a72aec96a6ed6bc401a0d363c60535b2612 Mon Sep 17 00:00:00 2001 From: shipengcheng1230 Date: Sat, 21 Mar 2020 23:29:20 -0400 Subject: [PATCH 1/6] fix 1 --- deps/build.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deps/build.jl b/deps/build.jl index ea0ed1c..b08b02e 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -56,4 +56,6 @@ else end end write_deps_file(joinpath(@__DIR__, "deps.jl"), products) + run(`cat deps/deps.jl`) + run(`ls deps/usr`) end From 6548bb7528a68ac25b090344930d74374a12125d Mon Sep 17 00:00:00 2001 From: shipengcheng1230 Date: Sat, 21 Mar 2020 23:41:38 -0400 Subject: [PATCH 2/6] fix 2 --- deps/build.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index b08b02e..9f50536 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -56,6 +56,14 @@ else end end write_deps_file(joinpath(@__DIR__, "deps.jl"), products) - run(`cat deps/deps.jl`) - run(`ls deps/usr`) + + +end + +Sys.iswindows() && run(`dir`) +@show isfile(joinpath(@__DIR__, "deps.jl")) +using Printf +open(joinpath(@__DIR__, "deps.jl"), "r") do f + s = read(f, String) + @printf "%s" s end From 212175194193e1daa15b8114d990cbe483e08475 Mon Sep 17 00:00:00 2001 From: shipengcheng1230 Date: Sun, 22 Mar 2020 11:39:45 -0400 Subject: [PATCH 3/6] fix 3 --- deps/build.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/deps/build.jl b/deps/build.jl index 9f50536..b19c23b 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -62,6 +62,7 @@ end Sys.iswindows() && run(`dir`) @show isfile(joinpath(@__DIR__, "deps.jl")) +import Pkg; Pkg.add("Printf") using Printf open(joinpath(@__DIR__, "deps.jl"), "r") do f s = read(f, String) From 80a27b35e82a3d3c5d301a99925e8d44980c1909 Mon Sep 17 00:00:00 2001 From: shipengcheng1230 Date: Sun, 22 Mar 2020 11:57:18 -0400 Subject: [PATCH 4/6] fix 4 --- Project.toml | 3 ++- deps/build.jl | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index a3f3617..529bb1a 100644 --- a/Project.toml +++ b/Project.toml @@ -7,11 +7,12 @@ version = "0.3.5" BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078" +Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" [compat] -julia = "1" BinaryProvider = "0.5.8" MLStyle = "0.3.1" +julia = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/deps/build.jl b/deps/build.jl index b19c23b..9f50536 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -62,7 +62,6 @@ end Sys.iswindows() && run(`dir`) @show isfile(joinpath(@__DIR__, "deps.jl")) -import Pkg; Pkg.add("Printf") using Printf open(joinpath(@__DIR__, "deps.jl"), "r") do f s = read(f, String) From f42ca2cbf6ca8784b1e6416438a486e8a9f671db Mon Sep 17 00:00:00 2001 From: shipengcheng1230 Date: Sun, 22 Mar 2020 12:26:22 -0400 Subject: [PATCH 5/6] fix 5 --- deps/build.jl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 9f50536..134cc55 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -21,18 +21,23 @@ if haskey(ENV, "GMSH_LIB_PATH") products = Product[LibraryProduct(ENV["GMSH_LIB_PATH"], libname, :libgmsh),] write_deps_file(joinpath(@__DIR__, "deps.jl"), products) else + @info "here1" if any(!satisfied(p; verbose=verbose) for p in products) + @info "here2" try + @info "here3" # download and install binaries url, tarball_hash = choose_download(download_info) try + @info "here4" install(url, tarball_hash; prefix=prefix, force=true, verbose=true) catch e + @info "here5" # cannot list content of .zip, manually unzip tarball_path = joinpath(prefix, "downloads", basename(url)) run(`unzip $(tarball_path) -d $(prefix.path)`) end - + @info "here6" # strip the top directory content_path = joinpath(prefix, splitext(basename(url))[1]) foreach( @@ -43,6 +48,7 @@ else # BinaryProvider will search $prefix/bin instead of $prefix/lib if Sys.iswindows() + @info "here7" dir_path = libdir(products[1].prefix, platform_key_abi()) lib_path = joinpath(dirname(dir_path), "lib") run(`cp -L $(lib_path)/* $(dir_path)`) @@ -55,15 +61,20 @@ else end end end + @info "here8" write_deps_file(joinpath(@__DIR__, "deps.jl"), products) - - end Sys.iswindows() && run(`dir`) -@show isfile(joinpath(@__DIR__, "deps.jl")) +@info isfile(joinpath(@__DIR__, "deps.jl")) using Printf +@info "Printf deps.jl" open(joinpath(@__DIR__, "deps.jl"), "r") do f s = read(f, String) @printf "%s" s end +@info "Print build.log" +open(joinpath(@__DIR__, "build.log"), "r") do f + s = read(f, String) + @printf "%s" s +end From c5c134bbb5ea739983b3c4ddf950fff282ec82b2 Mon Sep 17 00:00:00 2001 From: shipengcheng1230 Date: Tue, 21 Apr 2020 15:13:03 -0400 Subject: [PATCH 6/6] switch to JLL package --- Project.toml | 8 ++-- deps/build.jl | 109 +++++++++++++++++------------------------------ src/GmshTools.jl | 21 ++++----- 3 files changed, 49 insertions(+), 89 deletions(-) diff --git a/Project.toml b/Project.toml index 529bb1a..5684997 100644 --- a/Project.toml +++ b/Project.toml @@ -1,18 +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" -Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [compat] -BinaryProvider = "0.5.8" MLStyle = "0.3.1" -julia = "1" +julia = "1.3" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/deps/build.jl b/deps/build.jl index 134cc55..6bf8e1f 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,80 +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 - @info "here1" - if any(!satisfied(p; verbose=verbose) for p in products) - @info "here2" - try - @info "here3" - # download and install binaries - url, tarball_hash = choose_download(download_info) - try - @info "here4" - install(url, tarball_hash; prefix=prefix, force=true, verbose=true) - catch e - @info "here5" - # cannot list content of .zip, manually unzip - tarball_path = joinpath(prefix, "downloads", basename(url)) - run(`unzip $(tarball_path) -d $(prefix.path)`) - end - @info "here6" - # 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) - - # BinaryProvider will search $prefix/bin instead of $prefix/lib - if Sys.iswindows() - @info "here7" - 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 + # 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 - @info "here8" - write_deps_file(joinpath(@__DIR__, "deps.jl"), products) -end -Sys.iswindows() && run(`dir`) -@info isfile(joinpath(@__DIR__, "deps.jl")) -using Printf -@info "Printf deps.jl" -open(joinpath(@__DIR__, "deps.jl"), "r") do f - s = read(f, String) - @printf "%s" s -end -@info "Print build.log" -open(joinpath(@__DIR__, "build.log"), "r") do f - s = read(f, String) - @printf "%s" s + libgmsh_size = filesize(dlpath()) + + 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 end diff --git a/src/GmshTools.jl b/src/GmshTools.jl index a599549..1b37b02 100644 --- a/src/GmshTools.jl +++ b/src/GmshTools.jl @@ -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