Skip to content

Commit

Permalink
detectwsl
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautam98 committed Jul 2, 2020
1 parent 07385ab commit f217e0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 14 additions & 2 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export BINDIR,
iswindows,
isjsvm,
isexecutable,
which
which,
detectwsl

import ..Base: show

Expand Down Expand Up @@ -411,7 +412,18 @@ including e.g. a WebAssembly JavaScript embedding in a web browser.
"""
isjsvm(os::Symbol) = (os === :Emscripten)

for f in (:isunix, :islinux, :isbsd, :isapple, :iswindows, :isfreebsd, :isopenbsd, :isnetbsd, :isdragonfly, :isjsvm)
"""
Sys.detectwsl([os])
Runtime Predicate for testing if Julia is running inside WSL.
"""
function detectwsl(os::Symbol)
islinux(os) &&
isfile("/proc/sys/kernel/osrelease") &&
contains(read("/proc/sys/kernel/osrelease", String), r"Microsoft|WSL"i)
end

for f in (:detectwsl, :isunix, :islinux, :isbsd, :isapple, :iswindows, :isfreebsd, :isopenbsd, :isnetbsd, :isdragonfly, :isjsvm)
@eval $f() = $(getfield(@__MODULE__, f)(KERNEL))
end

Expand Down
5 changes: 5 additions & 0 deletions test/osutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
else
@test Sys.windows_version() >= v"1.0.0-"
end

@test !Sys.detectwsl(:Windows)
if !Sys.islinux()
@test !Sys.detectwsl()
end
end

@testset "@static" begin
Expand Down

0 comments on commit f217e0d

Please sign in to comment.