Skip to content

Commit a1aad34

Browse files
committed
Deprecate is_<os> functions in favor of Sys.is<os>
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.
1 parent 090e549 commit a1aad34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+341
-334
lines changed

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ Deprecated or removed
160160
* `InexactError` now takes arguments: `InexactError(func::Symbol,
161161
type, -3)` now prints as `ERROR: InexactError: func(type, -3)`. ([#20005])
162162

163+
* The operating system identification functions: `is_linux`, `is_bsd`, `is_apple`, `is_unix`,
164+
and `is_windows`, have been deprecated in favor of `Sys.islinux`, `Sys.isbsd`, `Sys.isapple`,
165+
`Sys.isunix`, and `Sys.iswindows`, respectively ([#22182]).
166+
167+
163168
Julia v0.6.0 Release Notes
164169
==========================
165170

@@ -954,6 +959,7 @@ Command-line option changes
954959
[#22038]: https://github.com/JuliaLang/julia/issues/22038
955960
[#22062]: https://github.com/JuliaLang/julia/issues/22062
956961
[#22064]: https://github.com/JuliaLang/julia/issues/22064
962+
[#22182]: https://github.com/JuliaLang/julia/issues/22182
957963
[#22187]: https://github.com/JuliaLang/julia/issues/22187
958964
[#22188]: https://github.com/JuliaLang/julia/issues/22188
959965
[#22224]: https://github.com/JuliaLang/julia/issues/22224

base/c.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Equivalent to the native `char` c-type.
1818
"""
1919
Cchar
2020

21-
if is_windows()
21+
# The ccall here is equivalent to Sys.iswindows(), but that's not defined yet
22+
@static if ccall(:jl_get_UNAME, Any, ()) === :NT
2223
const Clong = Int32
2324
const Culong = UInt32
2425
const Cwchar_t = UInt16
@@ -49,7 +50,7 @@ Equivalent to the native `wchar_t` c-type ([`Int32`](@ref)).
4950
"""
5051
Cwchar_t
5152

52-
if !is_windows()
53+
@static if ccall(:jl_get_UNAME, Any, ()) !== :NT
5354
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
5455
if sizeof_mode_t == 2
5556
const Cmode_t = Int16
@@ -118,7 +119,7 @@ end
118119
# symbols are guaranteed not to contain embedded NUL
119120
convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))
120121

121-
if is_windows()
122+
@static if ccall(:jl_get_UNAME, Any, ()) === :NT
122123
"""
123124
Base.cwstring(s)
124125

base/client.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ function repl_cmd(cmd, out)
102102
end
103103
cd(ENV["OLDPWD"])
104104
else
105-
cd(@static is_windows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
105+
cd(@static Sys.iswindows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
106106
end
107107
else
108108
cd()
109109
end
110110
ENV["OLDPWD"] = new_oldpwd
111111
println(out, pwd())
112112
else
113-
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))"`)))
113+
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))"`)))
114114
end
115115
nothing
116116
end
@@ -390,7 +390,7 @@ function _start()
390390
global is_interactive |= !isa(STDIN, Union{File, IOStream})
391391
color_set || (global have_color = false)
392392
else
393-
term = Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
393+
term = Terminals.TTYTerminal(get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
394394
global is_interactive = true
395395
color_set || (global have_color = Terminals.hascolor(term))
396396
quiet || REPL.banner(term,term)

base/dSFMT.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ end
163163

164164
## Windows entropy
165165

166-
if is_windows()
166+
if Sys.iswindows()
167167
function win32_SystemFunction036!(a::Array)
168168
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
169169
end

base/datafmt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ readdlm_auto(input::IO, dlm::Char, T::Type, eol::Char, auto::Bool; opts...) =
120120
readdlm_string(readstring(input), dlm, T, eol, auto, val_opts(opts))
121121
function readdlm_auto(input::AbstractString, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
122122
optsd = val_opts(opts)
123-
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
123+
use_mmap = get(optsd, :use_mmap, Sys.iswindows() ? false : true)
124124
fsz = filesize(input)
125125
if use_mmap && fsz > 0 && fsz < typemax(Int)
126126
a = open(input, "r") do f

base/deprecated.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,13 @@ end
15701570
# nfields(::Type) deprecation in builtins.c: update nfields tfunc in inference.jl when it is removed.
15711571
# also replace `_nfields` with `nfields` in summarysize.c when this is removed.
15721572

1573+
# PR #22182
1574+
@deprecate is_apple Sys.isapple
1575+
@deprecate is_bsd Sys.isbsd
1576+
@deprecate is_linux Sys.islinux
1577+
@deprecate is_unix Sys.isunix
1578+
@deprecate is_windows Sys.iswindows
1579+
15731580
# END 0.7 deprecations
15741581

15751582
# BEGIN 1.0 deprecations

base/distributed/cluster.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ end
975975
function disable_nagle(sock)
976976
# disable nagle on all OSes
977977
ccall(:uv_tcp_nodelay, Cint, (Ptr{Void}, Cint), sock.handle, 1)
978-
@static if is_linux()
978+
@static if Sys.islinux()
979979
# tcp_quickack is a linux only option
980980
if ccall(:jl_tcp_quickack, Cint, (Ptr{Void}, Cint), sock.handle, 1) < 0
981981
warn_once("Networking unoptimized ( Error enabling TCP_QUICKACK : ", Libc.strerror(Libc.errno()), " )")

base/distributed/managers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ function socket_reuse_port()
460460
s = TCPSocket(delay = false)
461461

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

465465
bind_early && bind_client_port(s)
466466
rc = ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle)

base/env.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
if is_windows()
3+
if Sys.iswindows()
44
const ERROR_ENVVAR_NOT_FOUND = UInt32(203)
55

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

87-
if is_windows()
87+
if Sys.iswindows()
8888
start(hash::EnvHash) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
8989
function done(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
9090
if unsafe_load(block[1]) == 0

base/event.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function wait()
247247
# unreachable
248248
end
249249

250-
if is_windows()
250+
if Sys.iswindows()
251251
pause() = ccall(:Sleep, stdcall, Void, (UInt32,), 0xffffffff)
252252
else
253253
pause() = ccall(:pause, Void, ())

base/exports.jl

+1-8
Original file line numberDiff line numberDiff line change
@@ -1258,14 +1258,6 @@ export
12581258
@code_llvm,
12591259
@code_native,
12601260

1261-
# platform-conditional code
1262-
@static,
1263-
is_windows,
1264-
is_linux,
1265-
is_apple,
1266-
is_bsd,
1267-
is_unix,
1268-
12691261
# tasks
12701262
@schedule,
12711263
@sync,
@@ -1295,6 +1287,7 @@ export
12951287
@goto,
12961288
@view,
12971289
@views,
1290+
@static,
12981291

12991292
# SparseArrays module re-exports
13001293
SparseArrays,

base/file.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function cd(dir::AbstractString)
5151
end
5252
cd() = cd(homedir())
5353

54-
if is_windows()
54+
if Sys.iswindows()
5555
function cd(f::Function, dir::AbstractString)
5656
old = pwd()
5757
try
@@ -91,7 +91,7 @@ this function throws an error. See [`mkpath`](@ref) for a function which creates
9191
required intermediate directories.
9292
"""
9393
function mkdir(path::AbstractString, mode::Unsigned=0o777)
94-
@static if is_windows()
94+
@static if Sys.iswindows()
9595
ret = ccall(:_wmkdir, Int32, (Cwstring,), path)
9696
else
9797
ret = ccall(:mkdir, Int32, (Cstring, UInt32), path, mode)
@@ -136,7 +136,7 @@ directory, then all contents are removed recursively.
136136
function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
137137
if islink(path) || !isdir(path)
138138
try
139-
@static if is_windows()
139+
@static if Sys.iswindows()
140140
# is writable on windows actually means "is deletable"
141141
if (filemode(path) & 0o222) == 0
142142
chmod(path, 0o777)
@@ -155,7 +155,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
155155
rm(joinpath(path, p), force=force, recursive=true)
156156
end
157157
end
158-
@static if is_windows()
158+
@static if Sys.iswindows()
159159
ret = ccall(:_wrmdir, Int32, (Cwstring,), path)
160160
else
161161
ret = ccall(:rmdir, Int32, (Cstring,), path)
@@ -254,7 +254,7 @@ function touch(path::AbstractString)
254254
end
255255
end
256256

257-
if is_windows()
257+
if Sys.iswindows()
258258

259259
function tempdir()
260260
temppath = Vector{UInt16}(32767)
@@ -536,7 +536,7 @@ function sendfile(src::AbstractString, dst::AbstractString)
536536
end
537537
end
538538

539-
if is_windows()
539+
if Sys.iswindows()
540540
const UV_FS_SYMLINK_JUNCTION = 0x0002
541541
end
542542

@@ -550,20 +550,20 @@ Creates a symbolic link to `target` with the name `link`.
550550
soft symbolic links, such as Windows XP.
551551
"""
552552
function symlink(p::AbstractString, np::AbstractString)
553-
@static if is_windows()
553+
@static if Sys.iswindows()
554554
if Sys.windows_version() < Sys.WINDOWS_VISTA_VER
555555
error("Windows XP does not support soft symlinks")
556556
end
557557
end
558558
flags = 0
559-
@static if is_windows()
559+
@static if Sys.iswindows()
560560
if isdir(p)
561561
flags |= UV_FS_SYMLINK_JUNCTION
562562
p = abspath(p)
563563
end
564564
end
565565
err = ccall(:jl_fs_symlink, Int32, (Cstring, Cstring, Cint), p, np, flags)
566-
@static if is_windows()
566+
@static if Sys.iswindows()
567567
if err < 0 && !isdir(p)
568568
Base.warn_once("Note: on Windows, creating file symlinks requires Administrator privileges.")
569569
end

base/filesystem.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Base:
4444
skip, stat, unsafe_read, unsafe_write, transcode, uv_error, uvhandle,
4545
uvtype, write
4646

47-
if is_windows()
47+
if Sys.iswindows()
4848
import Base: cwstring
4949
end
5050

base/initdefs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const LOAD_CACHE_PATH = String[]
5050
function init_load_path()
5151
vers = "v$(VERSION.major).$(VERSION.minor)"
5252
if haskey(ENV, "JULIA_LOAD_PATH")
53-
prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static is_windows() ? ';' : ':'))
53+
prepend!(LOAD_PATH, split(ENV["JULIA_LOAD_PATH"], @static Sys.iswindows() ? ';' : ':'))
5454
end
5555
push!(LOAD_PATH, abspath(JULIA_HOME, "..", "local", "share", "julia", "site", vers))
5656
push!(LOAD_PATH, abspath(JULIA_HOME, "..", "share", "julia", "site", vers))

base/interactiveutil.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for use within backticks. You can change the editor by setting `JULIA_EDITOR`, `
1010
`EDITOR` as an environment variable.
1111
"""
1212
function editor()
13-
if is_windows() || is_apple()
13+
if Sys.iswindows() || Sys.isapple()
1414
default_editor = "open"
1515
elseif isfile("/etc/alternatives/editor")
1616
default_editor = "/etc/alternatives/editor"
@@ -49,11 +49,11 @@ function edit(path::AbstractString, line::Integer=0)
4949
cmd = line != 0 ? `$command $path -l $line` : `$command $path`
5050
elseif startswith(name, "subl") || startswith(name, "atom")
5151
cmd = line != 0 ? `$command $path:$line` : `$command $path`
52-
elseif name == "code" || (is_windows() && uppercase(name) == "CODE.EXE")
52+
elseif name == "code" || (Sys.iswindows() && uppercase(name) == "CODE.EXE")
5353
cmd = line != 0 ? `$command -g $path:$line` : `$command -g $path`
5454
elseif startswith(name, "notepad++")
5555
cmd = line != 0 ? `$command $path -n$line` : `$command $path`
56-
elseif is_apple() && name == "open"
56+
elseif Sys.isapple() && name == "open"
5757
cmd = `open -t $path`
5858
line_unsupported = true
5959
else
@@ -62,8 +62,8 @@ function edit(path::AbstractString, line::Integer=0)
6262
line_unsupported = true
6363
end
6464

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

9191
# terminal pager
9292

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

124124
# clipboard copy and paste
125125

126-
if is_apple()
126+
if Sys.isapple()
127127
function clipboard(x)
128128
open(pipeline(`pbcopy`, stderr=STDERR), "w") do io
129129
print(io, x)
130130
end
131131
end
132132
clipboard() = readstring(`pbpaste`)
133133

134-
elseif is_linux()
134+
elseif Sys.islinux()
135135
_clipboardcmd = nothing
136136
function clipboardcmd()
137137
global _clipboardcmd
@@ -158,7 +158,7 @@ elseif is_linux()
158158
readstring(pipeline(cmd, stderr=STDERR))
159159
end
160160

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

268268
if verbose
269269
lsb = ""
270-
if is_linux()
270+
if Sys.islinux()
271271
try lsb = readchomp(pipeline(`lsb_release -ds`, stderr=DevNull)) end
272272
end
273-
if is_windows()
273+
if Sys.iswindows()
274274
try lsb = strip(readstring(`$(ENV["COMSPEC"]) /c ver`)) end
275275
end
276276
if !isempty(lsb)
277277
println(io, " ", lsb)
278278
end
279-
if is_unix()
279+
if Sys.isunix()
280280
println(io, " uname: ", readchomp(`uname -mprsv`))
281281
end
282282
end
@@ -592,7 +592,7 @@ end
592592
# file downloading
593593

594594
downloadcmd = nothing
595-
if is_windows()
595+
if Sys.iswindows()
596596
function download(url::AbstractString, filename::AbstractString)
597597
res = ccall((:URLDownloadToFileW,:urlmon),stdcall,Cuint,
598598
(Ptr{Void},Cwstring,Cwstring,Cuint,Ptr{Void}),C_NULL,url,filename,0,C_NULL)

0 commit comments

Comments
 (0)