os
The system operation module belongs to the built-in module. It can be called directly by the script scope without using import.
This module is also a native module of lua, and xmake has been extended to provide more practical interfaces.
editâš Only some readonly interfaces (for example:
os.getenv
,os.arch
) in the os module can be used in the description scope. Other interfaces can only be used in the script domain, for example:os.cp
,os.rm
etc.
os.arch
string os.arch()
Get current system architecture
That is the default architecture of the current host system, for example, I execute xmake on linux x86_64
to build, then the return value is: x86_64
.
Introduced in version 2.0.1
See also
os.is_arch, is_arch, os.subarch
editos.cpuinfo
table os.cpuinfo()
Get cpu information
print(os.cpuinfo())
-- got {
-- ncpu = 8,
-- usagerate = 0.0,
-- model_name = "Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz",
-- march = "Kaby Lake",
-- vendor = "GenuineIntel",
-- model = 158,
-- family = 6
-- }
print(os.cpuinfo("march")) -- got "Kaby Lake"
Introduced in version 2.1.5
See also
editos.curdir
string os.curdir()
Get the current directory path
Consistent with the result of $(curdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
Usage reference: os.tmpdir.
Introduced in version 2.0.1
See also
editos.date
table os.date(string format, numeric datetime)
See Date and Time.
See also
editos.default_njob
numeric os.default_njob()
Get default number of parallel jobs
print(os.default_njob()) -- got 10
Introduced in version 2.5.8
See also
editos.dirs
table os.dirs(string path_pattern[, function callback])
Traverse to get all the directories under the specified directory
Supports pattern matching in add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:
-- Recursive traversal to get all subdirectories
for _, dir in ipairs(os.dirs("$(buildir)/inc/**")) do
print(dir)
end
Introduced in version 2.0.1
See also
os.files, os.filedirs, os.isdir, os.match
editos.exists
bool os.exists(string path)
Determine if a file or directory exists
Return false
if the file or directory does not exist
-- Judging the existence of the directory
if os.exists("$(buildir)") then
-- ...
end
-- Judging the existence of the file
if os.exists("$(buildir)/libxxx.a") then
-- ...
end
Introduced in version 2.0.1
See also
os.isfile, os.isdir, os.isexec
editos.filedirs
table os.filedirs(string path_pattern[, function callback])
Traverse to get all files and directories under the specified directory
Supports pattern matching in target.add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:
-- Recursive traversal to get all child files and directories
for _, filedir in ipairs(os.filedirs("$(buildir)/**")) do
print(filedir)
end
Introduced in version 2.0.1
See also
editos.files
table os.files(string path_pattern[, function callback])
Traverse to get all the files in the specified directory
Supports pattern matching in target.add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:
-- Non-recursive traversal to get all child files
for _, filepath in ipairs(os.files("$(buildir)/inc/*.h")) do
print(filepath)
end
Introduced in version 2.0.1
See also
os.isfile, os.dirs, os.filedirs, os.match
editos.filesize
numeric os.filesize(string path)
Get file size
print(os.filesize("/tmp/a"))
Introduced in version 2.1.9
editos.getenv
string os.getenv(string envname)
Get system environment variables
print(os.getenv("PATH"))
Introduced in version 2.0.1
See also
os.getenvs, $(env), os.addenv, os.setenv
editos.host
string os.host()
Get the operating system of the current host
Consistent with the result of $(host), for example, if I execute xmake on linux x86_64
to build, the return value is: linux
Introduced in version 2.0.1
See also
editos.isdir
bool os.isdir(string path)
Determine if it is a directory
Return false
if the directory does not exist
if os.isdir("src") then
-- ...
end
Introduced in version 2.3.1
See also
os.isfile, os.islink, os.isexec, os.exists
editos.isfile
bool os.isfile(string path)
Determine if it is a file
Return false
if the file does not exist
if os.isfile("$(buildir)/libxxx.a") then
-- ...
end
Introduced in version 2.0.1
See also
os.isdir, os.islink, os.isexec, os.exists
editos.mclock
numeric os.mclock()
local time = os.mclock()
os.execv(program)
time = os.mclock() - time
print("time %0.3fs", time / 1000.)
See also
editos.mtime
numeric os.mtime(string path)
Get file modification time
local time = os.mtime("$(buildir)/file.o")
See also
editos.programdir
string os.programdir()
Get the xmake installation main program script directory
Consistent with the result of $(programdir), it is just a direct get returned to a variable, which can be maintained with subsequent strings.
Introduced in version 2.1.5
See also
editos.programfile
string os.programfile()
Get the path of the xmake executable
Introduced in version 2.1.5
See also
editos.projectdir
string os.projectdir()
Get the project home directory
Consistent with the result of $(projectdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
Introduced in version 2.1.5
See also
editos.projectfile
string os.projectfile()
Get the path to the current project xmake.lua file
See also
editos.scriptdir
string os.scriptdir()
Get the path of the current description script
Consistent with the result of $(scriptdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
Usage reference: os.tmpdir.
Introduced in version 2.0.1
See also
$(scriptdir), os.projectfile, os.projectdir
editos.subarch
string os.subarch()
Get Subsystem host architecture
print(os.subarch())
-- got x64
Introduced in version 2.3.1
See also
is_subarch, os.is_subarch, os.arch
editos.subhost
string os.subhost()
Get Subsystem host, e.g. msys, cygwin on windows
print(os.subhost())
-- got linux
Introduced in version 2.3.1
See also
os.is_subhost, is_subhost, os.host
editos.term
string os.term()
Get current terminal (windows-terminal, vscode, ... )
print(os.term())
-- got xterm
Introduced in version 2.7.3
See also
editos.time
numeric os.time([table time])
See Date and Time.
See also
editos.tmpdir
string os.tmpdir([table opt])
Get temporary directory
Consistent with the result of $(tmpdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
print(path.join(os.tmpdir(), "file.txt"))
Equivalent to:
print("$(tmpdir)/file.txt")
Valid field for opt
is:
bool ramdisk
, default value istrue