From f217e0d0942f814e94ca45468869251e74cbf82b Mon Sep 17 00:00:00 2001 From: Gautam Mishra Date: Thu, 2 Jul 2020 17:26:08 +0530 Subject: [PATCH] detectwsl --- base/sysinfo.jl | 16 ++++++++++++++-- test/osutils.jl | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index c88dc55278011..2d0f48b039177 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -31,7 +31,8 @@ export BINDIR, iswindows, isjsvm, isexecutable, - which + which, + detectwsl import ..Base: show @@ -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 diff --git a/test/osutils.jl b/test/osutils.jl index c9e3b9d91a377..e426f0dfa8452 100644 --- a/test/osutils.jl +++ b/test/osutils.jl @@ -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