diff options
| author | ruki <[email protected]> | 2015-10-08 16:41:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-10-08 16:41:47 +0800 |
| commit | 950af3b39e7b728797c030bd4640914fdb186c40 (patch) | |
| tree | 63d623bdc7d224f70cdc699655aa9ab7f4a6767d /xmake/scripts | |
| parent | 34b6123628ccce51f23207cea7c9c5f025f0a3c1 (diff) | |
add set_runscript api
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_install.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/action/_run.lua | 58 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 1 |
3 files changed, 49 insertions, 12 deletions
diff --git a/xmake/scripts/action/_install.lua b/xmake/scripts/action/_install.lua index d9aec0b4f..28ef3650d 100644 --- a/xmake/scripts/action/_install.lua +++ b/xmake/scripts/action/_install.lua @@ -64,7 +64,7 @@ function _install._makeconf(configs, target_name, target) end end if target.installscript and type(installscript) ~= "function" then - utils.error("invalid package script!") + utils.error("invalid install script!") return false end configs_target.installscript = installscript diff --git a/xmake/scripts/action/_run.lua b/xmake/scripts/action/_run.lua index 2d22bb987..64649fcb8 100644 --- a/xmake/scripts/action/_run.lua +++ b/xmake/scripts/action/_run.lua @@ -59,6 +59,12 @@ function _run.done() return false end + -- the arguments + local arguments = options.arguments or {} + if type(arguments) ~= "table" then + arguments = {} + end + -- the targets local targets = project.targets() if not targets or not targets[name] then @@ -69,11 +75,6 @@ function _run.done() -- the target local target = targets[name] - if not target.kind or type(target.kind) ~= "string" or target.kind ~= "binary" then - -- error - utils.error("the target %s is not executale!", name) - return false - end -- the target file local targetfile = rule.targetfile(name, target) @@ -81,6 +82,47 @@ function _run.done() targetfile = path.absolute(targetfile, xmake._PROJECT_DIR) end + -- load the run script + local runscript = target.runscript + if type(runscript) == "string" and os.isfile(runscript) then + local script, errors = loadfile(runscript) + if script then + runscript = script() + if type(runscript) == "table" and runscript.main then + runscript = runscript.main + end + else + utils.error(errors) + return false + end + end + + -- run script + if runscript ~= nil then + if type(runscript) == "function" then + + -- make passed target + local target_passed = {} + target_passed.name = name + target_passed.arguments = arguments + target_passed.targetfile = targetfile + + -- run it + local ok = runscript(target_passed) + if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end + else + utils.error("invalid run script!") + return false + end + end + + -- not executale? + if not target.kind or type(target.kind) ~= "string" or target.kind ~= "binary" then + -- error + utils.error("the target %s is not executale!", name) + return false + end + -- check the target file if not targetfile and not os.isfile(targetfile) then -- error @@ -88,12 +130,6 @@ function _run.done() return false end - -- the arguments - local arguments = options.arguments or {} - if type(arguments) ~= "table" then - arguments = {} - end - -- done local ok = os.execute(string.format("%s %s", targetfile, table.concat(arguments, " "))) diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 89bee0cd6..0a5f41317 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -1097,6 +1097,7 @@ function project._load_targets(file) , "warnings" , "optimize" , "languages" + , "runscript" , "installscript" , "packagescript"} |
