Skip to content

Commit e325593

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 c67c523 commit e325593

Some content is hidden

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

74 files changed

+346
-333
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ Deprecated or removed
139139
* The method `replace(s::AbstractString, pat, r, count)` with `count <= 0` is deprecated
140140
in favor of `replace(s::AbstractString, pat, r, typemax(Int))` ([#22325]).
141141

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

143147
Julia v0.6.0 Release Notes
144148
==========================
@@ -932,6 +936,7 @@ Command-line option changes
932936
[#22038]: https://github.com/JuliaLang/julia/issues/22038
933937
[#22062]: https://github.com/JuliaLang/julia/issues/22062
934938
[#22064]: https://github.com/JuliaLang/julia/issues/22064
939+
[#22182]: https://github.com/JuliaLang/julia/issues/22182
935940
[#22187]: https://github.com/JuliaLang/julia/issues/22187
936941
[#22188]: https://github.com/JuliaLang/julia/issues/22188
937942
[#22224]: https://github.com/JuliaLang/julia/issues/22224

base/c.jl

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import Core.Intrinsics: cglobal, bitcast
66

7+
# This is equivalent to Sys.iswindows(), but that's not defined yet.
8+
# FIXME: Do not use this constant outside of this file! We're only using it here
9+
# rather than repeating the ccall as needed to avoid a weird SIGABRT on Windows.
10+
# See PR #22182 for reference.
11+
const _jl_get_UNAME_eq_NT = ccall(:jl_get_UNAME, Any, ()) === :NT
12+
713
cfunction(f, r, a) = ccall(:jl_function_ptr, Ptr{Void}, (Any, Any, Any), f, r, a)
814

915
if ccall(:jl_is_char_signed, Ref{Bool}, ())
@@ -18,7 +24,8 @@ Equivalent to the native `char` c-type.
1824
"""
1925
Cchar
2026

21-
if is_windows()
27+
# The ccall is equivalent to Sys.iswindows(), but that's not defined yet
28+
if _jl_get_UNAME_eq_NT
2229
const Clong = Int32
2330
const Culong = UInt32
2431
const Cwchar_t = UInt16
@@ -49,7 +56,7 @@ Equivalent to the native `wchar_t` c-type ([`Int32`](@ref)).
4956
"""
5057
Cwchar_t
5158

52-
if !is_windows()
59+
if !_jl_get_UNAME_eq_NT
5360
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
5461
if sizeof_mode_t == 2
5562
const Cmode_t = Int16
@@ -118,7 +125,7 @@ end
118125
# symbols are guaranteed not to contain embedded NUL
119126
convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))
120127

121-
if is_windows()
128+
if _jl_get_UNAME_eq_NT
122129
"""
123130
Base.cwstring(s)
124131

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

+8
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,7 @@ function bkfact!(A::StridedMatrix, uplo::Symbol, symmetric::Bool = issymmetric(A
15031503
return bkfact!(symmetric ? Symmetric(A, uplo) : Hermitian(A, uplo), rook)
15041504
end
15051505

1506+
<<<<<<< HEAD
15061507
# PR #22325
15071508
# TODO: when this replace is removed from deprecated.jl:
15081509
# 1) rename the function replace_new from strings/util.jl to replace
@@ -1543,6 +1544,13 @@ end
15431544
@deprecate cat_t{N,T}(::Type{Val{N}}, ::Type{T}, A, B) cat_t(Val(N), T, A, B) false
15441545
@deprecate reshape{N}(A::AbstractArray, ::Type{Val{N}}) reshape(A, Val(N))
15451546

1547+
# PR #22182
1548+
@deprecate is_apple Sys.isapple
1549+
@deprecate is_bsd Sys.isbsd
1550+
@deprecate is_linux Sys.islinux
1551+
@deprecate is_unix Sys.isunix
1552+
@deprecate is_windows Sys.iswindows
1553+
15461554
# END 0.7 deprecations
15471555

15481556
# 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
@@ -1257,14 +1257,6 @@ export
12571257
@code_llvm,
12581258
@code_native,
12591259

1260-
# platform-conditional code
1261-
@static,
1262-
is_windows,
1263-
is_linux,
1264-
is_apple,
1265-
is_bsd,
1266-
is_unix,
1267-
12681260
# tasks
12691261
@schedule,
12701262
@sync,
@@ -1294,6 +1286,7 @@ export
12941286
@goto,
12951287
@view,
12961288
@views,
1289+
@static,
12971290

12981291
# SparseArrays module re-exports
12991292
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)