Skip to content

Commit

Permalink
continue cleanup surrounding OS_NAME and move more into Sys
Browse files Browse the repository at this point in the history
Sys.KERNEL now replaces OS_NAME and unambiguously returns
the name of the kernel reported by uname for the build system configuration
  • Loading branch information
vtjnash committed May 13, 2016
1 parent 29cb7bb commit 5c0882e
Show file tree
Hide file tree
Showing 40 changed files with 232 additions and 191 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ Library improvements

* The new `Base.StackTraces` module makes stack traces easier to use programmatically. ([#14469])

* System reflection is now more consistently exposed from Sys and not Base.
`OS_NAME` has been replaced by `Sys.KERNEL` and always reports the name of the kernel (as reported by `uname`).
The `@windows_only` and `@osx` family of macros have been replaced with functions such as `is_windows()` and
or `is_apple()`. There's now also an `@static` macro that will evaluate the condition of an if-statement at
compile time, for when a static branch is required.

Deprecated or removed
---------------------

Expand Down
1 change: 0 additions & 1 deletion base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ $(BUILDDIR)/uv_constants.jl: $(SRCDIR)/../src/uv_constants.h $(build_includedir)

$(BUILDDIR)/build_h.jl.phony:
@echo "# This file is automatically generated in base/Makefile" > $@
@echo "const ARCH = :$(ARCH)" >> $@
ifeq ($(XC_HOST),)
@echo "const MACHINE = \"$(BUILD_MACHINE)\"" >> $@
else
Expand Down
2 changes: 1 addition & 1 deletion base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function complete_keyword(s::String)
end

function complete_path(path::AbstractString, pos; use_envpath=false)
if Base.is_unix(OS_NAME) && ismatch(r"^~(?:/|$)", path)
if Base.is_unix() && ismatch(r"^~(?:/|$)", path)
# if the path is just "~", don't consider the expanded username as a prefix
if path == "~"
dir, prefix = homedir(), ""
Expand Down
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ function vcat{T}(arrays::Vector{T}...)
if isbits(T)
elsz = sizeof(T)
else
elsz = div(WORD_SIZE,8)
elsz = div(WORD_SIZE, 8)
end
for a in arrays
nba = length(a)*elsz
Expand Down
5 changes: 3 additions & 2 deletions base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Core.Intrinsics: llvmcall

import Base: setindex!, getindex, unsafe_convert
import Base.Sys: Sys, WORD_SIZE

export
Atomic,
Expand All @@ -16,8 +17,8 @@ export
# Disable 128-bit types on 32-bit Intel sytems due to LLVM problems;
# see <https://github.com/JuliaLang/julia/issues/14818> (fixed on LLVM 3.9)
# 128-bit atomics do not exist on AArch32.
if (VersionNumber(Base.libllvm_version) < v"3.9-" && Base.ARCH === :i686) ||
startswith(string(Base.ARCH), "arm")
if (VersionNumber(Base.libllvm_version) < v"3.9-" && Sys.ARCH === :i686) ||
startswith(string(Sys.ARCH), "arm")
const inttypes = (Int8, Int16, Int32, Int64,
UInt8, UInt16, UInt32, UInt64)
else
Expand Down
4 changes: 2 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typealias Cshort Int16
typealias Cushort UInt16
typealias Cint Int32
typealias Cuint UInt32
if OS_NAME === :Windows
if is_windows()
typealias Clong Int32
typealias Culong UInt32
typealias Cwchar_t UInt16
Expand All @@ -35,7 +35,7 @@ typealias Culonglong UInt64
typealias Cfloat Float32
typealias Cdouble Float64

if OS_NAME !== :Windows
if !is_windows()
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
if sizeof_mode_t == 2
typealias Cmode_t Int16
Expand Down
2 changes: 1 addition & 1 deletion base/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ brokenSignedInt = Union{}
brokenUnsignedInt = Union{}
brokenSignedIntMul = Int128
brokenUnsignedIntMul = UInt128
if WORD_SIZE == 32
if Base.WORD_SIZE == 32
brokenSignedIntMul = Union{brokenSignedIntMul, Int64}
brokenUnsignedIntMul = Union{brokenUnsignedIntMul, UInt64}
end
Expand Down
16 changes: 16 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,22 @@ export
@osx_only,
@linux_only

const OS_NAME =
if Sys.KERNEL === :Darwin
:OSX
elseif Sys.KERNEL === :WINNT
:Windows
else
Sys.KERNEL
end
deprecate(:OS_NAME) # use Sys.KERNEL now

import .Sys.CPU_CORES
export CPU_CORES # use the export from Sys (can't deprecate this because it instead deprecates Sys.CPU_CORES)

export WORD_SIZE # use the export from Sys (can't deprecate this here since it's used in base)


# During the 0.5 development cycle, do not add any deprecations below this line
# To be deprecated in 0.6

Expand Down
4 changes: 2 additions & 2 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,7 @@ addprocs(n::Integer)
"""
addprocs() -> List of process identifiers
Equivalent to `addprocs(CPU_CORES)`
Equivalent to `addprocs(Sys.CPU_CORES)`
Note that workers do not run a `.juliarc.jl` startup script, nor do they synchronize their
global state (such as global variables, new method definitions, and loaded modules) with any
Expand Down Expand Up @@ -9578,7 +9578,7 @@ Matrix trace.
trace

"""
runtests([tests=["all"] [, numcores=iceil(CPU_CORES/2) ]])
runtests([tests=["all"] [, numcores=iceil(Sys.CPU_CORES / 2) ]])
Run the Julia unit tests listed in `tests`, which can be either a string or an array of
strings, using `numcores` processors. (not exported)
Expand Down
3 changes: 0 additions & 3 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,15 @@ export
# Global constants and variables
ARGS,
C_NULL,
CPU_CORES,
ENDIAN_BOM,
ENV,
JULIA_HOME,
LOAD_PATH,
OS_NAME,
PROGRAM_FILE,
STDERR,
STDIN,
STDOUT,
VERSION,
WORD_SIZE,

# Mathematical constants
Inf,
Expand Down
2 changes: 1 addition & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ if is_windows()
end
function symlink(p::AbstractString, np::AbstractString)
@static if is_windows()
if Base.windows_version() < Base.WINDOWS_VISTA_VER
if Sys.windows_version() < Base.WINDOWS_VISTA_VER
error("Windows XP does not support soft symlinks")
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fma_llvm(x::Float64, y::Float64, z::Float64) =
# 1.0000000009313226 = 1 + 1/2^30
# If fma_llvm() clobbers the rounding mode, the result of 0.1 + 0.2 will be 0.3
# instead of the properly-rounded 0.30000000000000004; check after calling fma
if (ARCH != :i686 && fma_llvm(1.0000305f0, 1.0000305f0, -1.0f0) == 6.103609f-5 &&
if (Sys.ARCH != :i686 && fma_llvm(1.0000305f0, 1.0000305f0, -1.0f0) == 6.103609f-5 &&
(fma_llvm(1.0000000009313226, 1.0000000009313226, -1.0) ==
1.8626451500983188e-9) && 0.1 + 0.2 == 0.30000000000000004)
fma(x::Float32, y::Float32, z::Float32) = fma_llvm(x,y,z)
Expand Down
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function early_init()
# make sure OpenBLAS does not set CPU affinity (#1070, #9639)
ENV["OPENBLAS_MAIN_FREE"] = get(ENV, "OPENBLAS_MAIN_FREE",
get(ENV, "GOTOBLAS_MAIN_FREE", "1"))
if CPU_CORES > 8 && !("OPENBLAS_NUM_THREADS" in keys(ENV)) && !("OMP_NUM_THREADS" in keys(ENV))
if Sys.CPU_CORES > 8 && !("OPENBLAS_NUM_THREADS" in keys(ENV)) && !("OMP_NUM_THREADS" in keys(ENV))
# Prevent openblas from starting too many threads, unless/until specifically requested
ENV["OPENBLAS_NUM_THREADS"] = 8
end
Expand Down
5 changes: 0 additions & 5 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,6 @@ end

## system word size ##

"""
WORD_SIZE
Standard word size on the current machine, in bits.
"""
const WORD_SIZE = convert(Int, Int.size)*8

## integer promotions ##
Expand Down
39 changes: 32 additions & 7 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, VIS
EDITOR as an environmental variable.
"""
function editor()
if OS_NAME == :Windows || OS_NAME == :Darwin
if is_windows() || is_apple()
default_editor = "open"
elseif isfile("/etc/alternatives/editor")
default_editor = "/etc/alternatives/editor"
Expand Down Expand Up @@ -42,10 +42,10 @@ function edit(path::AbstractString, line::Integer=0)
cmd = line != 0 ? `$command $path -l $line` : `$command $path`
elseif startswith(name, "subl") || name == "atom"
cmd = line != 0 ? `$command $path:$line` : `$command $path`
elseif OS_NAME == :Windows && (name == "start" || name == "open")
elseif is_windows() && (name == "start" || name == "open")
cmd = `cmd /c start /b $path`
line_unsupported = true
elseif OS_NAME == :Darwin && (name == "start" || name == "open")
elseif is_apple() && (name == "start" || name == "open")
cmd = `open -t $path`
line_unsupported = true
else
Expand Down Expand Up @@ -156,11 +156,36 @@ elseif is_windows()
end

else
clipboard(x="") = error("`clipboard` function not implemented for $OS_NAME")
clipboard(x="") = error("`clipboard` function not implemented for $(OSNAME)")
end

# system information

function show(io::IO, info::Sys.CPUinfo, header::Bool=true, prefix::AbstractString=" ")
tck = Sys.SC_CLK_TCK
if header
println(io, info.model, ": ")
print(io, " "^length(prefix))
if tck > 0
@printf(io, " %5s %9s %9s %9s %9s %9s\n",
"speed", "user", "nice", "sys", "idle", "irq")
else
@printf(io, " %5s %9s %9s %9s %9s %9s ticks\n",
"speed", "user", "nice", "sys", "idle", "irq")
end
end
print(io, prefix)
if tck > 0
@printf(io, "%5d MHz %9d s %9d s %9d s %9d s %9d s",
info.speed, info.cpu_times!user / tck, info.cpu_times!nice / tck,
info.cpu_times!sys / tck, info.cpu_times!idle / tck, info.cpu_times!irq / tck)
else
@printf(io, "%5d MHz %9d %9d %9d %9d %9d ticks",
info.speed, info.cpu_times!user, info.cpu_times!nice,
info.cpu_times!sys, info.cpu_times!idle, info.cpu_times!irq)
end
end

function versioninfo(io::IO=STDOUT, verbose::Bool=false)
println(io, "Julia Version $VERSION")
if !isempty(GIT_VERSION_INFO.commit_short)
Expand All @@ -170,7 +195,7 @@ function versioninfo(io::IO=STDOUT, verbose::Bool=false)
println(io, "DEBUG build")
end
println(io, "Platform Info:")
println(io, " System: ", Sys.OS_NAME, " (", Sys.MACHINE, ")")
println(io, " System: ", OSNAME, " (", Sys.KERNEL, " ", Sys.MACHINE, ")")

cpu = Sys.cpu_info()
println(io, " CPU: ", cpu[1].model)
Expand Down Expand Up @@ -487,7 +512,7 @@ end

# testing

function runtests(tests = ["all"], numcores = ceil(Int,CPU_CORES/2))
function runtests(tests = ["all"], numcores = ceil(Int, Sys.CPU_CORES / 2))
if isa(tests,AbstractString)
tests = split(tests)
end
Expand Down Expand Up @@ -573,7 +598,7 @@ summarysize(obj::Symbol, seen, excl) = 0
function summarysize(obj::DataType, seen, excl)
key = pointer_from_objref(obj)
haskey(seen, key) ? (return 0) : (seen[key] = true)
size = 7*sizeof(Int) + 6*sizeof(Int32) + 4*nfields(obj) + ifelse(WORD_SIZE==64,4,0)
size = 7*sizeof(Int) + 6*sizeof(Int32) + 4*nfields(obj) + ifelse(Sys.WORD_SIZE == 64, 4, 0)
size += summarysize(obj.parameters, seen, excl)::Int
size += summarysize(obj.types, seen, excl)::Int
return size
Expand Down
6 changes: 3 additions & 3 deletions base/libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ function dlpath(libname::Union{AbstractString, Symbol})
return path
end

if OS_NAME === :Darwin
if is_apple()
const dlext = "dylib"
elseif OS_NAME === :Windows
elseif is_windows()
const dlext = "dll"
else
#assume OS_NAME === :Linux, or similar
#assume is_linux, or similar
const dlext = "so"
end

Expand Down
8 changes: 4 additions & 4 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

# Cross-platform case-sensitive path canonicalization

if OS_NAME (:Linux, :FreeBSD)
# Case-sensitive filesystems, don't have to do anything
if is_unix() && !is_apple()
# assume case-sensitive filesystems, don't have to do anything
isfile_casesensitive(path) = isfile(path)
elseif OS_NAME == :Windows
elseif is_windows()
# GetLongPathName Win32 function returns the case-preserved filename on NTFS.
function isfile_casesensitive(path)
isfile(path) || return false # Fail fast
Filesystem.longpath(path) == path
end
elseif OS_NAME == :Darwin
elseif is_apple()
# HFS+ filesystem is case-preserving. The getattrlist API returns
# a case-preserved filename. In the rare event that HFS+ is operating
# in case-sensitive mode, this will still work but will be redundant.
Expand Down
Loading

0 comments on commit 5c0882e

Please sign in to comment.