Skip to content

Commit

Permalink
Deprecate is_<os> functions in favor of Sys.is<os>
Browse files Browse the repository at this point in the history
This makes them consistent with the vast majority of Base predicates,
which simply prefix with `is` rather than `is_`. It also moves to
requiring the `Sys.` prefix, which helps explain the intent behind the
function names.
  • Loading branch information
ararslan committed Jun 30, 2017
1 parent bbc516c commit 81f7b32
Show file tree
Hide file tree
Showing 74 changed files with 339 additions and 333 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Deprecated or removed
Ternaries must now include some amount of whitespace, e.g. `x ? a : b` rather than
`x? a : b` ([#22523]).

* The operating system identification functions: `is_linux`, `is_bsd`, `is_apple`, `is_unix`,
and `is_windows`, have been deprecated in favor of `Sys.islinux`, `Sys.isbsd`, `Sys.isapple`,
`Sys.isunix`, and `Sys.iswindows`, respectively ([#22182]).


Julia v0.6.0 Release Notes
==========================
Expand Down Expand Up @@ -920,6 +924,7 @@ Command-line option changes
[#22038]: https://github.com/JuliaLang/julia/issues/22038
[#22062]: https://github.com/JuliaLang/julia/issues/22062
[#22064]: https://github.com/JuliaLang/julia/issues/22064
[#22182]: https://github.com/JuliaLang/julia/issues/22182
[#22187]: https://github.com/JuliaLang/julia/issues/22187
[#22188]: https://github.com/JuliaLang/julia/issues/22188
[#22224]: https://github.com/JuliaLang/julia/issues/22224
Expand Down
7 changes: 4 additions & 3 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Equivalent to the native `char` c-type.
"""
Cchar

if is_windows()
# The ccall is equivalent to Sys.iswindows(), but that's not defined yet
if ccall(:jl_get_UNAME, Any, ()) === :NT
const Clong = Int32
const Culong = UInt32
const Cwchar_t = UInt16
Expand Down Expand Up @@ -49,7 +50,7 @@ Equivalent to the native `wchar_t` c-type ([`Int32`](@ref)).
"""
Cwchar_t

if !is_windows()
if ccall(:jl_get_UNAME, Any, ()) !== :NT
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
if sizeof_mode_t == 2
const Cmode_t = Int16
Expand Down Expand Up @@ -118,7 +119,7 @@ end
# symbols are guaranteed not to contain embedded NUL
convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))

if is_windows()
if ccall(:jl_get_UNAME, Any, ()) === :NT
"""
Base.cwstring(s)
Expand Down
6 changes: 3 additions & 3 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ function repl_cmd(cmd, out)
end
cd(ENV["OLDPWD"])
else
cd(@static is_windows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
cd(@static Sys.iswindows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
end
else
cd()
end
ENV["OLDPWD"] = new_oldpwd
println(out, pwd())
else
run(ignorestatus(@static is_windows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`)))
run(ignorestatus(@static Sys.iswindows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`)))
end
nothing
end
Expand Down Expand Up @@ -385,7 +385,7 @@ function _start()
global is_interactive |= !isa(STDIN, Union{File, IOStream})
color_set || (global have_color = false)
else
term = Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
term = Terminals.TTYTerminal(get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
global is_interactive = true
color_set || (global have_color = Terminals.hascolor(term))
quiet || REPL.banner(term,term)
Expand Down
2 changes: 1 addition & 1 deletion base/dSFMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ end

## Windows entropy

if is_windows()
if Sys.iswindows()
function win32_SystemFunction036!(a::Array)
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
end
Expand Down
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ readdlm_auto(input::IO, dlm::Char, T::Type, eol::Char, auto::Bool; opts...) =
readdlm_string(readstring(input), dlm, T, eol, auto, val_opts(opts))
function readdlm_auto(input::AbstractString, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
optsd = val_opts(opts)
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
use_mmap = get(optsd, :use_mmap, Sys.iswindows() ? false : true)
fsz = filesize(input)
if use_mmap && fsz > 0 && fsz < typemax(Int)
a = open(input, "r") do f
Expand Down
7 changes: 7 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,13 @@ function bkfact!(A::StridedMatrix, uplo::Symbol, symmetric::Bool = issymmetric(A
return bkfact!(symmetric ? Symmetric(A, uplo) : Hermitian(A, uplo), rook)
end

# PR #22182
@deprecate is_apple Sys.isapple
@deprecate is_bsd Sys.isbsd
@deprecate is_linux Sys.islinux
@deprecate is_unix Sys.isunix
@deprecate is_windows Sys.iswindows

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
2 changes: 1 addition & 1 deletion base/distributed/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ end
function disable_nagle(sock)
# disable nagle on all OSes
ccall(:uv_tcp_nodelay, Cint, (Ptr{Void}, Cint), sock.handle, 1)
@static if is_linux()
@static if Sys.islinux()
# tcp_quickack is a linux only option
if ccall(:jl_tcp_quickack, Cint, (Ptr{Void}, Cint), sock.handle, 1) < 0
warn_once("Networking unoptimized ( Error enabling TCP_QUICKACK : ", Libc.strerror(Libc.errno()), " )")
Expand Down
2 changes: 1 addition & 1 deletion base/distributed/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ function socket_reuse_port()
s = TCPSocket(delay = false)

# Some systems (e.g. Linux) require the port to be bound before setting REUSEPORT
bind_early = is_linux()
bind_early = Sys.islinux()

bind_early && bind_client_port(s)
rc = ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle)
Expand Down
4 changes: 2 additions & 2 deletions base/env.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

if is_windows()
if Sys.iswindows()
const ERROR_ENVVAR_NOT_FOUND = UInt32(203)

_getenvlen(var::Vector{UInt16}) = ccall(:GetEnvironmentVariableW,stdcall,UInt32,(Ptr{UInt16},Ptr{UInt16},UInt32),var,C_NULL,0)
Expand Down Expand Up @@ -84,7 +84,7 @@ delete!(::EnvHash, k::AbstractString) = (_unsetenv(k); ENV)
setindex!(::EnvHash, v, k::AbstractString) = _setenv(k,string(v))
push!(::EnvHash, k::AbstractString, v) = setindex!(ENV, v, k)

if is_windows()
if Sys.iswindows()
start(hash::EnvHash) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
function done(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
if unsafe_load(block[1]) == 0
Expand Down
2 changes: 1 addition & 1 deletion base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function wait()
# unreachable
end

if is_windows()
if Sys.iswindows()
pause() = ccall(:Sleep, stdcall, Void, (UInt32,), 0xffffffff)
else
pause() = ccall(:pause, Void, ())
Expand Down
9 changes: 1 addition & 8 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1257,14 +1257,6 @@ export
@code_llvm,
@code_native,

# platform-conditional code
@static,
is_windows,
is_linux,
is_apple,
is_bsd,
is_unix,

# tasks
@schedule,
@sync,
Expand Down Expand Up @@ -1294,6 +1286,7 @@ export
@goto,
@view,
@views,
@static,

# SparseArrays module re-exports
SparseArrays,
Expand Down
18 changes: 9 additions & 9 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function cd(dir::AbstractString)
end
cd() = cd(homedir())

if is_windows()
if Sys.iswindows()
function cd(f::Function, dir::AbstractString)
old = pwd()
try
Expand Down Expand Up @@ -91,7 +91,7 @@ this function throws an error. See [`mkpath`](@ref) for a function which creates
required intermediate directories.
"""
function mkdir(path::AbstractString, mode::Unsigned=0o777)
@static if is_windows()
@static if Sys.iswindows()
ret = ccall(:_wmkdir, Int32, (Cwstring,), path)
else
ret = ccall(:mkdir, Int32, (Cstring, UInt32), path, mode)
Expand Down Expand Up @@ -136,7 +136,7 @@ directory, then all contents are removed recursively.
function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
if islink(path) || !isdir(path)
try
@static if is_windows()
@static if Sys.iswindows()
# is writable on windows actually means "is deletable"
if (filemode(path) & 0o222) == 0
chmod(path, 0o777)
Expand All @@ -155,7 +155,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
rm(joinpath(path, p), force=force, recursive=true)
end
end
@static if is_windows()
@static if Sys.iswindows()
ret = ccall(:_wrmdir, Int32, (Cwstring,), path)
else
ret = ccall(:rmdir, Int32, (Cstring,), path)
Expand Down Expand Up @@ -254,7 +254,7 @@ function touch(path::AbstractString)
end
end

if is_windows()
if Sys.iswindows()

function tempdir()
temppath = Vector{UInt16}(32767)
Expand Down Expand Up @@ -536,7 +536,7 @@ function sendfile(src::AbstractString, dst::AbstractString)
end
end

if is_windows()
if Sys.iswindows()
const UV_FS_SYMLINK_JUNCTION = 0x0002
end

Expand All @@ -550,20 +550,20 @@ Creates a symbolic link to `target` with the name `link`.
soft symbolic links, such as Windows XP.
"""
function symlink(p::AbstractString, np::AbstractString)
@static if is_windows()
@static if Sys.iswindows()
if Sys.windows_version() < Sys.WINDOWS_VISTA_VER
error("Windows XP does not support soft symlinks")
end
end
flags = 0
@static if is_windows()
@static if Sys.iswindows()
if isdir(p)
flags |= UV_FS_SYMLINK_JUNCTION
p = abspath(p)
end
end
err = ccall(:jl_fs_symlink, Int32, (Cstring, Cstring, Cint), p, np, flags)
@static if is_windows()
@static if Sys.iswindows()
if err < 0 && !isdir(p)
Base.warn_once("Note: on Windows, creating file symlinks requires Administrator privileges.")
end
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Base:
skip, stat, unsafe_read, unsafe_write, transcode, uv_error, uvhandle,
uvtype, write

if is_windows()
if Sys.iswindows()
import Base: cwstring
end

Expand Down
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const LOAD_CACHE_PATH = String[]
function init_load_path()
vers = "v$(VERSION.major).$(VERSION.minor)"
if haskey(ENV, "JULIA_LOAD_PATH")
prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static is_windows() ? ';' : ':'))
prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static Sys.iswindows() ? ';' : ':'))
end
push!(LOAD_PATH, abspath(JULIA_HOME, "..", "local", "share", "julia", "site", vers))
push!(LOAD_PATH, abspath(JULIA_HOME, "..", "share", "julia", "site", vers))
Expand Down
28 changes: 14 additions & 14 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for use within backticks. You can change the editor by setting `JULIA_EDITOR`, `
`EDITOR` as an environment variable.
"""
function editor()
if is_windows() || is_apple()
if Sys.iswindows() || Sys.isapple()
default_editor = "open"
elseif isfile("/etc/alternatives/editor")
default_editor = "/etc/alternatives/editor"
Expand Down Expand Up @@ -49,11 +49,11 @@ function edit(path::AbstractString, line::Integer=0)
cmd = line != 0 ? `$command $path -l $line` : `$command $path`
elseif startswith(name, "subl") || startswith(name, "atom")
cmd = line != 0 ? `$command $path:$line` : `$command $path`
elseif name == "code" || (is_windows() && uppercase(name) == "CODE.EXE")
elseif name == "code" || (Sys.iswindows() && uppercase(name) == "CODE.EXE")
cmd = line != 0 ? `$command -g $path:$line` : `$command -g $path`
elseif startswith(name, "notepad++")
cmd = line != 0 ? `$command $path -n$line` : `$command $path`
elseif is_apple() && name == "open"
elseif Sys.isapple() && name == "open"
cmd = `open -t $path`
line_unsupported = true
else
Expand All @@ -62,8 +62,8 @@ function edit(path::AbstractString, line::Integer=0)
line_unsupported = true
end

if is_windows() && name == "open"
@static is_windows() && # don't emit this ccall on other platforms
if Sys.iswindows() && name == "open"
@static Sys.iswindows() && # don't emit this ccall on other platforms
systemerror(:edit, ccall((:ShellExecuteW, "shell32"), stdcall, Int,
(Ptr{Void}, Cwstring, Cwstring, Ptr{Void}, Ptr{Void}, Cint),
C_NULL, "open", path, C_NULL, C_NULL, 10) 32)
Expand All @@ -90,7 +90,7 @@ edit(file, line::Integer) = error("could not find source file for function")

# terminal pager

if is_windows()
if Sys.iswindows()
function less(file::AbstractString, line::Integer)
pager = get(ENV, "PAGER", "more")
g = pager == "more" ? "" : "g"
Expand Down Expand Up @@ -123,15 +123,15 @@ less(file, line::Integer) = error("could not find source file for function")

# clipboard copy and paste

if is_apple()
if Sys.isapple()
function clipboard(x)
open(pipeline(`pbcopy`, stderr=STDERR), "w") do io
print(io, x)
end
end
clipboard() = readstring(`pbpaste`)

elseif is_linux()
elseif Sys.islinux()
_clipboardcmd = nothing
function clipboardcmd()
global _clipboardcmd
Expand All @@ -158,7 +158,7 @@ elseif is_linux()
readstring(pipeline(cmd, stderr=STDERR))
end

elseif is_windows()
elseif Sys.iswindows()
# TODO: these functions leak memory and memory locks if they throw an error
function clipboard(x::AbstractString)
if containsnul(x)
Expand Down Expand Up @@ -262,21 +262,21 @@ function versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
println(io, "DEBUG build")
end
println(io, "Platform Info:")
println(io, " OS: ", is_windows() ? "Windows" : is_apple() ?
println(io, " OS: ", Sys.iswindows() ? "Windows" : Sys.isapple() ?
"macOS" : Sys.KERNEL, " (", Sys.MACHINE, ")")

if verbose
lsb = ""
if is_linux()
if Sys.islinux()
try lsb = readchomp(pipeline(`lsb_release -ds`, stderr=DevNull)) end
end
if is_windows()
if Sys.iswindows()
try lsb = strip(readstring(`$(ENV["COMSPEC"]) /c ver`)) end
end
if !isempty(lsb)
println(io, " ", lsb)
end
if is_unix()
if Sys.isunix()
println(io, " uname: ", readchomp(`uname -mprsv`))
end
end
Expand Down Expand Up @@ -592,7 +592,7 @@ end
# file downloading

downloadcmd = nothing
if is_windows()
if Sys.iswindows()
function download(url::AbstractString, filename::AbstractString)
res = ccall((:URLDownloadToFileW,:urlmon),stdcall,Cuint,
(Ptr{Void},Cwstring,Cwstring,Cuint,Ptr{Void}),C_NULL,url,filename,0,C_NULL)
Expand Down
Loading

0 comments on commit 81f7b32

Please sign in to comment.