diff options
| author | ruki <[email protected]> | 2017-07-03 10:22:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-03 10:22:20 +0800 |
| commit | 73716b52c62f407697249e8e15dd42d6163e3019 (patch) | |
| tree | 87a3e9d7d877fcb6c9ab63b6c458b4e17e429110 | |
| parent | 9c49f6fc62b248690e8a74627e1a749a8468c6e1 (diff) | |
add option.xxx_check
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 35 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 12 |
4 files changed, 49 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f766eb9c4..dcd4a3ed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Add `val()` api to get the value of builtin-variable, .e.g `val("host")`, `val("env PATH")`, `val("shell echo hello")` and `val("reg HKEY_LOCAL_MACHINE\\XX;Value")` * Support to compile the microsoft resource file (.rc) * Add `has_flags` module interfaces. +* Add `option.on_check`, `option.after_check` and `option.before_check` api ### Changes @@ -313,6 +314,7 @@ * 添加`val()`接口去获取内置变量,例如:`val("host")`, `val("env PATH")`, `val("shell echo hello")` and `val("reg HKEY_LOCAL_MACHINE\\XX;Value")` * 增加对微软.rc资源文件的编译支持,当在windows上编译时,可以增加资源文件了 * 增加`has_flags`模块接口 +* 添加`option.on_check`, `option.after_check` 和 `option.before_check` 接口 ### 改进 diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index cc0fe97fb..501f9ce69 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -135,8 +135,8 @@ function option:_check() -- trace utils.cprint("checking for the %s ... %s", name, utils.ifelse(ok, "${green}ok", "${red}no")) - if not ok and option_.get("verbose") and errors then - utils.cprint("${red}%s", errors) + if not ok and errors then + os.raise(errors) end -- ok? @@ -160,6 +160,13 @@ function option:check(force) default = self:get("enable") end + -- before and after check + local check_before = self:get("check_before") + local check_after = self:get("check_after") + if check_before then + check_before(self) + end + -- need check? (only force to check the automatical option without the default value) if config.get(name) == nil or (default == nil and force) then @@ -196,10 +203,25 @@ function option:check(force) self:save() end + -- after check + if check_after then + check_after(self) + end + -- checked self._CHECKED = true end +-- this option is enabled? +function option:enabled() + return config.get(self:name()) +end + +-- dump this option +function option:dump() + table.dump(self._INFO) +end + -- get the option info function option:get(infoname) return self._INFO[infoname] @@ -208,7 +230,12 @@ end -- set the value to the option info function option:set(name_or_info, ...) if type(name_or_info) == "string" then - self._INFO[name_or_info] = table.unique(table.join(...)) + local args = ... + if args ~= nil then + self._INFO[name_or_info] = table.unique(table.join(...)) + else + self._INFO[name_or_info] = nil + end elseif type(name_or_info) == "table" and #name_or_info == 0 then for name, info in pairs(name_or_info) do self:set(name, info) @@ -238,6 +265,8 @@ function option:save() -- clear scripts for caching to file self:set("check", nil) + self:set("check_after", nil) + self:set("check_before", nil) -- save this option to cache option._cache():set(self:name(), self._INFO) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 62ed8683b..89728889e 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -265,8 +265,12 @@ function project._interpreter() , "target.after_package" , "target.after_install" , "target.after_uninstall" + -- option.before_xxx + , "option.before_check" -- option.on_xxx , "option.on_check" + -- option.after_xxx + , "option.after_check" -- target.on_xxx , "task.on_run" } diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 67c2a5d4e..ce84f5714 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -73,7 +73,12 @@ end -- set the value to the target info function target:set(name_or_info, ...) if type(name_or_info) == "string" then - self._INFO[name_or_info] = table.unique(table.join(...)) + local args = ... + if args ~= nil then + self._INFO[name_or_info] = table.unique(table.join(...)) + else + self._INFO[name_or_info] = nil + end elseif type(name_or_info) == "table" and #name_or_info == 0 then for name, info in pairs(name_or_info) do self:set(name, info) @@ -92,6 +97,11 @@ function target:add(name_or_info, ...) end end +-- dump this target +function target:dump() + table.dump(self._INFO) +end + -- get the target name function target:name() return self._NAME |
