Skip to content

Commit

Permalink
Merge pull request #93 from musm/fx
Browse files Browse the repository at this point in the history
More resilient precompiled builds
  • Loading branch information
Allardvm committed Jun 6, 2017
2 parents d819882 + 784e8ae commit b0bc710
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 172 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -49,14 +49,14 @@ some of your workarounds might interfere with the new approach. You can reset yo

```julia
using Homebrew
run(`brew remove imagemagick@6`)
run(`brew prune`)
Homebrew.rm("imagemagick@6")
Homebrew.brew(`prune`)
Pkg.build("ImageMagick")
```

You may also find [debugging
Homebrew](https://github.com/JuliaLang/Homebrew.jl/wiki/Debugging-Homebrew.jl)
useful.
useful.

Finally, an alternative to ImageMagick on OS X is
[QuartzImageIO](https://github.com/JuliaIO/QuartzImageIO.jl).
Expand Down
100 changes: 31 additions & 69 deletions deps/build.jl
Expand Up @@ -15,116 +15,78 @@ libwand = library_dependency("libwand", aliases = aliases)

mpath = get(ENV, "MAGICK_HOME", "") # If MAGICK_HOME is defined, add to library search path
if !isempty(mpath)
init_fun =
"""
function init_deps()
ccall((:MagickWandGenesis, libwand), Void, ())
end
"""

provides(Binaries, mpath, libwand, preload = init_fun, onload = "init_deps()")
provides(Binaries, joinpath(mpath, "lib"), libwand, preload = init_fun, onload = "init_deps()")
provides(Binaries, mpath, libwand)
provides(Binaries, joinpath(mpath, "lib"), libwand)
end


if is_linux()
init_fun =
"""
function init_deps()
ccall((:MagickWandGenesis, libwand), Void, ())
end
"""

provides(AptGet, "libmagickwand4", libwand, preload = init_fun, onload = "init_deps()")
provides(AptGet, "libmagickwand5", libwand, preload = init_fun, onload = "init_deps()")
provides(AptGet, "libmagickwand-6.q16-2", libwand, preload = init_fun, onload = "init_deps()")
provides(Pacman, "imagemagick", libwand, preload = init_fun, onload = "init_deps()")
provides(Yum, "ImageMagick", libwand, preload = init_fun, onload = "init_deps()")
provides(AptGet, "libmagickwand4", libwand)
provides(AptGet, "libmagickwand5", libwand)
provides(AptGet, "libmagickwand-6.q16-2", libwand)
provides(Pacman, "imagemagick", libwand)
provides(Yum, "ImageMagick", libwand)
end


if is_windows()
push!(BinDeps.defaults, BuildProcess) # TODO: remove me when upstream is fixed

const OS_ARCH = Sys.WORD_SIZE == 64 ? "x64" : "x86"
OS_ARCH = Sys.WORD_SIZE == 64 ? "x64" : "x86"

# TODO: checksums: we have gpg
# Extract the appropriate filename to download
magick_base = "http://www.imagemagick.org/download/binaries"
binariesfn = download(magick_base)
str = readstring(binariesfn)
pattern = "ImageMagick-6.9.*?-Q16-$(OS_ARCH)-dll.exe"
m = match(Regex(pattern), str)
magick_exe = convert(String, m.match)

magick_tmpdir = BinDeps.downloadsdir(libwand)
magick_url = "$(magick_base)/$(magick_exe)"
magick_libdir = joinpath(BinDeps.libdir(libwand), OS_ARCH)
innounp_url = "https://bintray.com/artifact/download/julialang/generic/innounp.exe"
init_fun =
magick_exe = String(match(Regex(pattern), str).match)

magick_tmpdir = BinDeps.downloadsdir(libwand)
magick_url = "$(magick_base)/$(magick_exe)"
magick_installdir = joinpath(BinDeps.libdir(libwand), OS_ARCH)
magick_libdir = joinpath(magick_installdir, "{app}")
innounp_url = "https://bintray.com/artifact/download/julialang/generic/innounp.exe"
preloads =
"""
function init_deps()
ENV["MAGICK_CONFIGURE_PATH"] = \"$(escape_string(magick_libdir))\"
ENV["MAGICK_CODER_MODULE_PATH"] = \"$(escape_string(magick_libdir))\"
function initenv()
ENV["MAGICK_CONFIGURE_PATH"] = "$(escape_string(magick_libdir))"
ENV["MAGICK_CODER_MODULE_PATH"] = "$(escape_string(joinpath(magick_libdir, "modules", "coders")))"
ENV["MAGICK_FILTER_MODULE_PATH"] = "$(escape_string(joinpath(magick_libdir, "modules", "filters")))"
ENV["PATH"] = "$(escape_string(magick_libdir * ";"))" * ENV["PATH"]
end
"""

provides(BuildProcess,
(@build_steps begin
CreateDirectory(magick_tmpdir)
CreateDirectory(magick_libdir)
FileDownloader(magick_url, joinpath(magick_tmpdir, magick_exe))
FileDownloader(innounp_url, joinpath(magick_tmpdir, "innounp.exe"))
@build_steps begin
ChangeDirectory(magick_tmpdir)
info("Installing ImageMagick library")
`innounp.exe -q -y -b -e -x -d$(magick_libdir) $(magick_exe)`
`innounp.exe -q -y -b -x -d$(magick_installdir) $(magick_exe)`
end
end),
libwand, os = :Windows, unpacked_dir = magick_libdir, preload = init_fun,
onload = "init_deps()")
libwand, os = :Windows, unpacked_dir = magick_libdir, preload = preloads)
end


if is_apple()
using Homebrew
imagemagick_prefix = Homebrew.prefix("staticfloat/juliadeps/imagemagick@6")
init_fun =
homebrew_prefix = Homebrew.prefix()
preloads =
"""
function init_deps()
ENV["MAGICK_CONFIGURE_PATH"] = joinpath("$(imagemagick_prefix)",
"lib", "ImageMagick", "config-Q16")
ENV["MAGICK_CODER_MODULE_PATH"] = joinpath("$(imagemagick_prefix)",
"lib", "ImageMagick", "modules-Q16", "coders")
ENV["PATH"] = joinpath("$(imagemagick_prefix)", "bin") * ":" * ENV["PATH"]
ccall((:MagickWandGenesis,libwand), Void, ())
function initenv()
ENV["MAGICK_CONFIGURE_PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "lib", "ImageMagick", "config-Q16")))"
ENV["MAGICK_CODER_MODULE_PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "lib", "ImageMagick", "modules-Q16", "coders")))"
ENV["MAGICK_FILTER_MODULE_PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "lib", "ImageMagick", "modules-Q16", "filters")))"
ENV["PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "bin") * ":"))" * ENV["PATH"]
end
"""
provides(Homebrew.HB, "staticfloat/juliadeps/imagemagick@6", libwand, os = :Darwin,
preload = init_fun, onload = "init_deps()")
provides(Homebrew.HB, "homebrew/core/imagemagick@6", libwand, os = :Darwin, preload = preloads)
end


@BinDeps.install Dict([(:libwand, :libwand)])

# Hack-fix for issue #12
# Check to see whether init_deps is present, and if not add it
if isempty(search(readstring(joinpath(dirname(@__FILE__),"deps.jl")), "init_deps"))
open("deps.jl", "a") do io
write(io, init_fun)
end
end

module CheckVersion
include("deps.jl")
p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8}, ),
"LIB_VERSION_NUMBER")
vstr = string("v\"", join(split(unsafe_string(p), ',')[1:3], '.'), "\"")
open(joinpath(dirname(@__FILE__), "versioninfo.jl"), "w") do file
write(file, "const libversion = $vstr\n")
end
end


is_windows() && pop!(BinDeps.defaults)
4 changes: 2 additions & 2 deletions src/ImageMagick.jl
Expand Up @@ -19,7 +19,7 @@ include("libmagickwand.jl")

# Image / Video formats

image_formats = [
const image_formats = [
format"BMP",
format"AVI",
format"CRW",
Expand Down Expand Up @@ -152,7 +152,7 @@ function image2wand(img, mapi=identity, quality=nothing, permute_horizontal=true
T = eltype(imgw)
channelorder = T<:Real ? "Gray" : ColorTypes.colorant_string(T)
if T <: Union{RGB,RGBA,ARGB,BGRA,ABGR}
cs = libversion > v"6.7.5" ? "sRGB" : "RGB"
cs = getlibversion() > v"6.7.5" ? "sRGB" : "RGB"
else
cs = channelorder
end
Expand Down

0 comments on commit b0bc710

Please sign in to comment.