From 0c7483eb5c2148ad1ad77a1d5c9fdcc3eca04a65 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Aug 2019 23:00:09 +0800 Subject: add set_runenv docs --- manual/project_target.md | 31 +++++++++++++++++++++++++------ zh-cn/manual/project_target.md | 23 +++++++++++++++++++++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/manual/project_target.md b/manual/project_target.md index f1ca3703..c4244015 100644 --- a/manual/project_target.md +++ b/manual/project_target.md @@ -117,6 +117,7 @@ target("test2") | [add_values](#targetadd_values) | Add custom configuartion values | >= 2.2.1 | | [set_rundir](#targetset_rundir) | Set run directory | >= 2.2.7 | | [add_runenvs](#targetadd_runenvs) | Add run environments | >= 2.2.7 | +| [set_runenv](#targetset_runenv) | Set run environment | >= 2.2.8 | | [set_installdir](#targetset_installdir) | Set the installation directory | >= 2.2.5 | | [add_installfiles](#targetadd_installfiles) | add installation files | >= 2.2.5 | | [add_headerfiles](#targetadd_headerfiles) | Add header files | >= 2.2.5 | @@ -2047,16 +2048,34 @@ target("test") ### target:add_runenvs -#### Adding runtime variables +#### Adding runtime environment variables -This interface is used to add environment variables that set the default run target program. +This interface is used to add an environment variable that sets the default running target program. Unlike [set_runenv](#targetset_runenv), this interface appends the value in the existing system env and does not overwrite it. + +Therefore, for PATH, it is very convenient to append values through this interface, and this interface supports multi-value settings, so it is usually used to set multi-value env with path sep. . ```lua target("test") -     set_kind("binary") -     add_files("src/*.c") -     add_runenvs("PATH", "/tmp/bin", "xxx/bin") -     add_runenvs("NAME", "value") +    set_kind("binary") +    add_files("src/*.c") +    add_runenvs("PATH", "/tmp/bin", "xxx/bin") +    add_runenvs("LD_LIBRARY_PATH", "/tmp/lib", "xxx/lib") +``` + +### target:set_runenv + +#### Setting the runtime environment variable + +This interface differs from [add_runenvs](#targetadd_runenvs) in that `set_runenv` is an override setting for an environment variable that overrides the env value of the original system environment, and this interface is singular and cannot pass multiple parameters. + +So, if you want to override the env that sets the multipath in PATH, you need to splicing yourself: + +```lua +target("test") +    set_kind("binary") +    add_files("src/*.c") +    set_runenv("PATH", path.joinenv("/tmp/bin", "xxx/bin")) +    set_runenv("NAME", "value") ``` ### target:set_installdir diff --git a/zh-cn/manual/project_target.md b/zh-cn/manual/project_target.md index 43708ffe..e802a618 100644 --- a/zh-cn/manual/project_target.md +++ b/zh-cn/manual/project_target.md @@ -118,6 +118,7 @@ target("test2") | [add_values](#targetadd_values) | 添加一些扩展配置值 | >= 2.2.1 | | [set_rundir](#targetset_rundir) | 设置运行目录 | >= 2.2.7 | | [add_runenvs](#targetadd_runenvs) | 添加运行环境变量 | >= 2.2.7 | +| [set_runenv](#targetset_runenv) | 设置运行环境变量 | >= 2.2.8 | | [set_installdir](#targetset_installdir) | 设置安装目录 | >= 2.2.5 | | [add_installfiles](#targetadd_installfiles) | 添加安装文件 | >= 2.2.5 | | [add_headerfiles](#targetadd_headerfiles) | 添加安装头文件 | >= 2.2.5 | @@ -2043,14 +2044,32 @@ target("test") #### 添加运行环境变量 -此接口用于添加设置默认运行target程序的环境变量。 +此接口用于添加设置默认运行target程序的环境变量,跟[set_runenv](#targetset_runenv)不同的是,此接口是对已有系统env中的值进行追加,并不会覆盖。 + +所以,对于PATH这种,通过此接口追加值是非常方便的,而且此接口支持多值设置,所以通常就是用来设置带有path sep的多值env。。 ```lua target("test") set_kind("binary") add_files("src/*.c") add_runenvs("PATH", "/tmp/bin", "xxx/bin") - add_runenvs("NAME", "value") + add_runenvs("LD_LIBRARY_PATH", "/tmp/lib", "xxx/lib") +``` + +### target:set_runenv + +#### 设置运行环境变量 + +此接口跟[add_runenvs](#targetadd_runenvs)不同的是,`set_runenv`是对某个环境变量的覆盖设置,会覆盖原有系统环境的env值,并且此接口是单数设置,不能传递多参。 + +所以,如果要覆盖设置PATH这中多路径的env,需要自己去拼接: + +```lua +target("test") + set_kind("binary") + add_files("src/*.c") + set_runenv("PATH", path.joinenv("/tmp/bin", "xxx/bin")) + set_runenv("NAME", "value") ``` ### target:set_installdir -- cgit v1.2.3