Skip to content

Commit

Permalink
Add Sys.is<os>
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jul 17, 2017
1 parent c3e15e9 commit 53366d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ Currently, the `@compat` macro supports the following syntaxes:

* `takebuf_array` is now a method of `take!`. `takebuf_string(io)` becomes `String(take!(io))` ([#19088])

* `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows` are now `Sys.isapple`, `Sys.isbsd`,
`Sys.islinux`, `Sys.isunix`, and `Sys.iswindows`, respectively. These are available in the `Compat.Sys`
submodule. ([#22182])

## New macros

* `@static` has been added ([#16219])
Expand Down Expand Up @@ -380,3 +384,4 @@ includes this fix. Find the minimum version from there.
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#22064]: https://github.com/JuliaLang/julia/issues/22064
[#22182]: https://github.com/JuliaLang/julia/issues/22182
14 changes: 14 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1535,4 +1535,18 @@ include("to-be-deprecated.jl")
# https://github.com/JuliaLang/julia/pull/21746
const macros_have_sourceloc = VERSION >= v"0.7-" && length(:(@test).args) == 2

# https://github.com/JuliaLang/julia/pull/22182
module Sys
using ..Compat: KERNEL
if VERSION < v"0.7.0-DEV.914"
isapple(k::Symbol=KERNEL) = k in (:Darwin, :Apple)
isbsd(k::Symbol=KERNEL) = isapple(k) || k in (:FreeBSD, :OpenBSD, :NetBSD, :DragonFly)
islinux(k::Symbol=KERNEL) = k == :Linux
isunix(k::Symbol=KERNEL) = isbsd(k) || islinux(k)
iswindows(k::Symbol=KERNEL) = k in (:Windows, :NT)
else
import Base.Sys: isapple, isbsd, islinux, isunix, iswindows
end
end

end # module Compat
15 changes: 12 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ let x = rand(rng, Int64, 3,4)
@test x == rand(rng, Int64, (3,4))
end

extrapath = is_windows() ? joinpath(JULIA_HOME,"..","Git","usr","bin")*";" : ""
extrapath = Compat.Sys.iswindows() ? joinpath(JULIA_HOME,"..","Git","usr","bin")*";" : ""
@compat withenv("PATH" => extrapath * ENV["PATH"]) do
cmd1 = pipeline(`echo hello`, `sort`)
cmd2 = pipeline(`true`, `true`)
if is_windows()
if Compat.Sys.iswindows()
try # use busybox-w32
success(`busybox`)
cmd1 = pipeline(`busybox echo hello`, `busybox sort`)
Expand Down Expand Up @@ -916,7 +916,7 @@ cd(dirwalk) do
touch(joinpath("sub_dir1", "file$i"))
end
touch(joinpath("sub_dir2", "file_dir2"))
has_symlinks = is_unix() ? true : (isdefined(Base, :WINDOWS_VISTA_VER) && Base.windows_version() >= Base.WINDOWS_VISTA_VER)
has_symlinks = Compat.Sys.isunix() ? true : (isdefined(Base, :WINDOWS_VISTA_VER) && Base.windows_version() >= Base.WINDOWS_VISTA_VER)
follow_symlink_vec = has_symlinks ? [true, false] : [false]
has_symlinks && symlink(abspath("sub_dir2"), joinpath("sub_dir1", "link"))
for follow_symlinks in follow_symlink_vec
Expand Down Expand Up @@ -1242,6 +1242,15 @@ if VERSION < v"0.5.0-dev+4267"
end
else
@test Compat.KERNEL == Sys.KERNEL
for os in [:apple, :bsd, :linux, :unix, :windows]
from_compat = Symbol("Compat.Sys.is", os)
from_base = if VERSION >= v"0.7.0-DEV.914"
Symbol("Base.Sys.is", os)
else # VERSION >= v"0.5.0-dev+4267"
Symbol("Base.is_", os)
end
@test @eval $from_compat() == $from_base()
end
end

io = IOBuffer()
Expand Down

0 comments on commit 53366d6

Please sign in to comment.