Skip to content

Commit

Permalink
Merge pull request #143 from JunoLab/rd/v0.7
Browse files Browse the repository at this point in the history
Julia v0.7 support
  • Loading branch information
pfitzseb authored Aug 21, 2018
2 parents 3eff499 + 37a5ca0 commit f48c6ac
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 83 deletions.
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ notifications:
matrix:
include:
- os: linux
julia: 0.6
julia: 0.7
env: TESTCMD="xvfb-run julia"
- os: linux
julia: 1.0
env: TESTCMD="xvfb-run julia"
- os: linux
julia: nightly
env: TESTCMD="xvfb-run julia"
- os: osx
julia: 0.6
julia: 0.7
env: TESTCMD="julia"
- os: osx
julia: 1.0
env: TESTCMD="julia"
- os: osx
julia: nightly
env: TESTCMD="julia"
allow_failures:
- julia: nightly
branches:
only:
- master
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- $TESTCMD -e 'Pkg.clone(pwd()); Pkg.build("Blink"); import Blink; Pkg.test("Blink"; coverage=true)'
- $TESTCMD --color=yes -e "VERSION >= v\"0.7.0-DEV.5183\" && using Pkg; Pkg.clone(pwd()); Pkg.build(\"Blink\"); Pkg.test(\"Blink\"; coverage=true)"
after_success:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder()); Coveralls.submit(process_folder())'
8 changes: 3 additions & 5 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
julia 0.6
julia 0.7
WebSockets 0.2.3
HttpServer
Lazy 0.11.3
JSON
Reexport
Mustache
MacroTools
Mux
BinDeps
Compat 0.8.6
WebIO
JSExpr
WebIO 0.3
JSExpr 0.3
37 changes: 24 additions & 13 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

# Uncomment the following lines to allow failures on nightly julia
# (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia_version: nightly

branches:
only:
Expand All @@ -15,18 +26,18 @@ notifications:
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Blink\"); Pkg.build(\"Blink\"); using Blink; Blink.AtomShell.install()"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Blink\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
4 changes: 2 additions & 2 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module BuildBlink
include(joinpath(@__DIR__, "../src/AtomShell/install.jl"))

function get_installed_version()
_path = is_apple() ?
_path = Sys.isapple() ?
joinpath(folder(), "version") :
joinpath(folder(), "atom", "version")
strip(readstring(_path), 'v')
strip(read(_path, String), 'v')
end

if isinstalled() && !(version == get_installed_version())
Expand Down
2 changes: 1 addition & 1 deletion src/AtomShell/AtomShell.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module AtomShell

using Compat; import Compat.String
using Sockets

abstract type Shell end

Expand Down
14 changes: 7 additions & 7 deletions src/AtomShell/install.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ const version = "2.0.5"

folder() = normpath(joinpath(@__FILE__, "../../../deps"))

@static if is_apple()
@static if Sys.isapple()
uninstall() = map(rm′, filter(x -> !endswith(x, "build.jl"), readdir(folder())))
else
uninstall() = rm′(joinpath(folder(), "atom"))
end

isinstalled() = is_apple() ?
isinstalled() = Sys.isapple() ?
isfile(joinpath(folder(), "version")) :
isdir(joinpath(folder(), "atom"))


function install()
dir = folder()
if is_apple()
const _icons = normpath(joinpath(@__FILE__, "../../../res/julia-icns.icns"))
if Sys.isapple()
_icons = normpath(joinpath(@__FILE__, "../../../res/julia-icns.icns"))
end
!isdir(dir) && mkpath(dir)
uninstall()
Expand All @@ -29,7 +29,7 @@ function install()

download("http://junolab.s3.amazonaws.com/blink/julia.png")

if is_apple()
if Sys.isapple()
file = "electron-v$version-darwin-x64.zip"
download("https://github.com/electron/electron/releases/download/v$version/$file")
run(`unzip -q $file`)
Expand All @@ -41,15 +41,15 @@ function install()
run(`touch Julia.app`) # Apparently this is necessary to tell the OS to double-check for the new icons.
end

if is_windows()
if Sys.iswindows()
arch = Int == Int64 ? "x64" : "ia32"
file = "electron-v$version-win32-$arch.zip"
download("https://github.com/electron/electron/releases/download/v$version/$file")
run(`7z x $file -oatom`)
rm(file)
end

if is_linux()
if Sys.islinux()
arch = Int == Int64 ? "x64" : "ia32"
file = "electron-v$version-linux-$arch.zip"
download("https://github.com/electron/electron/releases/download/v$version/$file")
Expand Down
39 changes: 24 additions & 15 deletions src/AtomShell/process.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
using Lazy, JSON, MacroTools

hascommand(c) =
try readstring(`which $c`); true catch e false end
try read(`which $c`, String); true catch e false end

spawn_rdr(cmd) = spawn(cmd, Base.spawn_opts_inherit()...)
run_rdr(cmd; kw...) = run(cmd, Base.spawn_opts_inherit()...; kw...)

resolve(pkg, path...) =
joinpath(Base.find_in_path(pkg, nothing), "..","..", path...) |> normpath
"""
resolve_blink_asset(path...)
Find a file, expressed as a relative path from the Blink package
folder. Example:
resolve_blink_asset("src", "Blink.jl") -> /home/<user>/.julia/v0.6/Blink/src/Blink.jl
"""
resolve_blink_asset(path...) = abspath(joinpath(@__DIR__, "..", "..", path...))

@deprecate resolve(pkg, path...) resolve_blink_asset(path...)

# node-inspector

Expand All @@ -27,26 +36,26 @@ end

# atom-shell

import Base: Process, TCPSocket
import Base: Process

export Electron

type Electron <: Shell
mutable struct Electron <: Shell
proc::Process
sock::TCPSocket
handlers::Dict{String, Any}
end

Electron(proc, sock) = Electron(proc, sock, Dict())

@static if is_apple()
const _electron = resolve("Blink", "deps/Julia.app/Contents/MacOS/Julia")
elseif is_linux()
const _electron = resolve("Blink", "deps/atom/electron")
elseif is_windows()
const _electron = resolve("Blink", "deps", "atom", "electron.exe")
@static if Sys.isapple()
const _electron = resolve_blink_asset("deps/Julia.app/Contents/MacOS/Julia")
elseif Sys.islinux()
const _electron = resolve_blink_asset("deps/atom/electron")
elseif Sys.iswindows()
const _electron = resolve_blink_asset("deps", "atom", "electron.exe")
end
const mainjs = resolve("Blink", "src", "AtomShell", "main.js")
const mainjs = resolve_blink_asset("src", "AtomShell", "main.js")

function electron()
path = get(ENV, "ELECTRON_PATH", _electron)
Expand All @@ -72,7 +81,7 @@ function init(; debug = false)
p, dp = port(), port()
debug && inspector(dp)
dbg = debug ? "--debug=$dp" : []
proc = (debug ? spawn_rdr : spawn)(`$(electron()) $dbg $mainjs port $p`)
proc = (debug ? run_rdr : run)(`$(electron()) $dbg $mainjs port $p`; wait=false)
conn = try_connect(ip"127.0.0.1", p)
shell = Electron(proc, conn)
initcbs(shell)
Expand All @@ -89,7 +98,7 @@ handlers(shell::Electron) = shell.handlers

function initcbs(shell)
enable_callbacks!(shell)
@schedule begin
@async begin
while active(shell)
@errs handle_message(shell, JSON.parse(shell.sock))
end
Expand Down
14 changes: 7 additions & 7 deletions src/AtomShell/window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export Window, flashframe, shell, progress, title,
centre, floating, loadurl, opentools, closetools, tools,
loadhtml, loadfile, css, front

type Window
mutable struct Window
id::Int
shell::Shell
content
Expand All @@ -20,17 +20,17 @@ const window_defaults = @d(:url => "about:blank",
:title => "Julia",
"node-integration" => false,
"use-content-size" => true,
:icon => resolve("Blink", "deps", "julia.png"))
:icon => resolve_blink_asset("deps", "julia.png"))

raw_window(a::Electron, opts) = @js a createWindow($(merge(window_defaults, opts)))

function Window(a::Shell, opts::Associative = Dict())
function Window(a::Shell, opts::AbstractDict = Dict())
return haskey(opts, :url) ?
Window(raw_window(a, opts), a, nothing) :
Window(a, Page(), opts)
end

function Window(a::Shell, content::Page, opts::Associative = Dict())
function Window(a::Shell, content::Page, opts::AbstractDict = Dict())
opts = merge(opts, Dict(:url => Blink.localurl(content)))
return Window(raw_window(a, opts), a, content)
end
Expand Down Expand Up @@ -120,15 +120,15 @@ close(win::Window) =

# Window content APIs

active(::Void) = false
active(::Nothing) = false

handlers(w::Window) = handlers(w.content)

msg(win::Window, m) = msg(win.content, m)

js(win::Window, s::JSString; callback = true) =
active(win.content) ? js(win.content, s, callback = callback) :
dot(win, :(this.webContents.executeJavaScript($(jsstring(s)))), callback = callback)
dot(win, :(this.webContents.executeJavaScript($(s.s))), callback = callback)

const initcss = """
<style>html,body{margin:0;padding:0;border:0;text-align:center;}</style>
Expand All @@ -141,6 +141,6 @@ function loadhtml(win::Window, html::AbstractString)
println(io, html)
end
loadfile(win, tmp)
@schedule (sleep(1); rm(tmp))
@async (sleep(1); rm(tmp))
return
end
7 changes: 5 additions & 2 deletions src/Blink.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ __precompile__()
module Blink

using Reexport
using Compat; import Compat.String
using Distributed: Future
using Sockets
using Logging
using Base64: stringmime

include("rpc/rpc.jl")
include("content/content.jl")

include("AtomShell/AtomShell.jl")
export AtomShell
@reexport using .AtomShell
import .AtomShell: resolve
import .AtomShell: resolve_blink_asset

end # module
2 changes: 1 addition & 1 deletion src/content/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function load!(w, file; async=false)
elseif ext == "css"
loadcss!(w, file)
elseif ext == "html"
importhtml!(w, file; async)
importhtml!(w, file; async=async)
else
error("Blink: Unsupported file type")
end
Expand Down
14 changes: 8 additions & 6 deletions src/content/config.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export localips

@init global const port = get(ENV, "BLINK_PORT", rand(2_000:10_000))
const port = Ref{Int}()

@init port[] = haskey(ENV, "BLINK_PORT") ? parse(Int, get(ENV, "BLINK_PORT")) : rand(2_000:10_000)

const ippat = r"([0-9]+\.){3}[0-9]+"

@static if is_unix()
@static if Sys.isunix()
localips() = map(IPv4, readlines(`ifconfig` |>
`grep -Eo $("inet (addr:)?$(ippat.pattern)")` |>
`grep -Eo $(ippat.pattern)` |>
Expand All @@ -13,14 +15,14 @@ end

# Browser Window

@static if is_apple()
@static if Sys.isapple()
launch(x) = run(`open $x`)
elseif is_linux()
elseif Sys.islinux()
launch(x) = run(`xdg-open $x`)
elseif is_windows()
elseif Sys.iswindows()
launch(x) = run(`cmd /C start $x`)
end

localurl(p::Page) = "http://127.0.0.1:$port/$(id(p))"
localurl(p::Page) = "http://127.0.0.1:$(port[])/$(id(p))"

launch(p::Page) = (launch(localurl(p)); p)
Loading

0 comments on commit f48c6ac

Please sign in to comment.