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.

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.rmetc.

edit

os.addenv

edit

os.addenvp

edit

os.addenvs

edit

os.arch

edit

os.args

edit

os.argv

edit

os.atexit

edit

os.cd

edit

os.cp

nil os.cp(string src, string dst, table opt)

Copy files or directories

The behavior is similar to the cp command in the shell, supporting path wildcard matching (using lua pattern matching), support for multi-file copying, and built-in variable support.

Valid fields for opt are:

e.g:

os.cp("$(scriptdir)/*.h", "$(buildir)/inc")
os.cp("$(projectdir)/src/test/**.h", "$(buildir)/inc")

The above code will: all the header files in the current xmake.lua directory, the header files in the project source test directory are all copied to the $(buildir) output directory.

Among them $(scriptdir), $(projectdir) These variables are built-in variables of xmake. For details, see the related documentation of built-in variables.

The matching patterns in *.h and **.h are similar to those in add_files, the former is a single-level directory matching, and the latter is a recursive multi-level directory matching.

This interface also supports `recursive replication' of directories, for example:

-- Recursively copy the current directory to a temporary directory
os.cp("$(curdir)/test/", "$(tmpdir)/test")

The copy at the top will expand and copy all files to the specified directory, and lose the source directory hierarchy. If you want to copy according to the directory structure that maintains it, you can set the rootdir parameter:

os.cp("src/**.h", "/tmp/", {rootdir="src"})

The above script can press the root directory of src to copy all sub-files under src in the same directory structure.

Try to use the os.cp interface instead of os.run("cp .."), which will ensure platform consistency and cross-platform build description.

Under 2.5.7, the parameter {symlink = true} is added to keep the symbolic link when copying files.

os.cp("/xxx/foo", "/xxx/bar", {symlink = true})

被引入的版本 2.0.1

参考

os.trycp

edit

os.cpuinfo

edit

os.curdir

edit

os.date

edit

os.default_njob

edit

os.dirs

edit

os.emptydir

edit

os.exec

edit

os.execv

edit

os.exists

edit

os.exit

edit

os.features

edit

os.filedirs

edit

os.files

edit

os.filesize

edit

os.fscase

edit

os.getenv

edit

os.getenvs

edit

os.getpid

edit

os.getwinsize

edit

os.host

edit

os.iorun

edit

os.iorunv

edit

os.is_arch

edit

os.is_host

edit

os.is_subarch

edit

os.is_subhost

edit

os.isdir

edit

os.isexec

edit

os.isfile

edit

os.islink

edit

os.isroot

edit

os.joinenvs

edit

os.ln

edit

os.match

edit

os.mclock

edit

os.meminfo

edit

os.mkdir

edit

os.mtime

edit

os.mv

nil os.mv(string src, string dst, table opt)

Move to rename a file or directory

Similar to the use of os.cp, it also supports multi-file move operations and pattern matching, for example:

-- Move multiple files to a temporary directory
os.mv("$(buildir)/test1", "$(tmpdir)")

-- File movement does not support bulk operations, which is file renaming
os.mv("$(buildir)/libtest.a", "$(buildir)/libdemo.a")

被引入的版本 2.0.1

参考

os.cp, os_trycp, os_rm

edit

os.nuldev

edit

os.pbcopy

edit

os.pbpaste

edit

os.programdir

edit

os.programfile

edit

os.projectdir

edit

os.projectfile

edit

os.raise

edit

os.readlink

edit

os.rm

edit

os.rmdir

edit

os.run

edit

os.runv

edit

os.scriptdir

edit

os.setenv

edit

os.setenvp

edit

os.setenvs

edit

os.shell

edit

os.sleep

edit

os.strerror

edit

os.subarch

edit

os.subhost

edit

os.syserror

edit

os.term

edit

os.time

edit

os.tmpdir

edit

os.tmpfile

edit

os.touch

edit

os.trycp

edit

os.trymv

edit

os.tryrm

edit

os.vcp

edit

os.vexec

edit

os.vexecv

edit

os.vln

edit

os.vmv

edit

os.vrm

edit

os.vrun

edit

os.vrunv

edit

os.workingdir

edit

os.xmakever

edit
接口
os.addenv
os.addenvp
os.addenvs
os.arch
os.args
os.argv
os.atexit
os.cd
os.cp
os.cpuinfo
os.curdir
os.date
os.default_njob
os.dirs
os.emptydir
os.exec
os.execv
os.exists
os.exit
os.features
os.filedirs
os.files
os.filesize
os.fscase
os.getenv
os.getenvs
os.getpid
os.getwinsize
os.host
os.iorun
os.iorunv
os.is_arch
os.is_host
os.is_subarch
os.is_subhost
os.isdir
os.isexec
os.isfile
os.islink
os.isroot
os.joinenvs
os.ln
os.match
os.mclock
os.meminfo
os.mkdir
os.mtime
os.mv
os.nuldev
os.pbcopy
os.pbpaste
os.programdir
os.programfile
os.projectdir
os.projectfile
os.raise
os.readlink
os.rm
os.rmdir
os.run
os.runv
os.scriptdir
os.setenv
os.setenvp
os.setenvs
os.shell
os.sleep
os.strerror
os.subarch
os.subhost
os.syserror
os.term
os.time
os.tmpdir
os.tmpfile
os.touch
os.trycp
os.trymv
os.tryrm
os.vcp
os.vexec
os.vexecv
os.vln
os.vmv
os.vrm
os.vrun
os.vrunv
os.workingdir
os.xmakever