summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-21 23:27:00 +0800
committerruki <[email protected]>2017-09-21 14:42:01 +0800
commit034185734b5bc91f8188c15c9e02b0ce8ebaa850 (patch)
tree17788345197514d464006129d76a0d36f2addf35
parent253e814d11d2af31088a22401a28b4a6abef70e3 (diff)
improve option and add require option
-rw-r--r--xmake/actions/clean/main.lua2
-rw-r--r--xmake/actions/config/main.lua9
-rw-r--r--xmake/actions/config/xmake.lua3
-rw-r--r--xmake/actions/require/environment.lua164
-rw-r--r--xmake/actions/require/install.lua1
-rw-r--r--xmake/actions/require/list.lua3
-rw-r--r--xmake/actions/require/main.lua2
-rw-r--r--xmake/actions/uninstall/main.lua2
-rw-r--r--xmake/core/base/option.lua29
-rw-r--r--xmake/core/package/package.lua3
-rw-r--r--xmake/core/project/project.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/base/option.lua15
-rw-r--r--xmake/core/sandbox/modules/import/core/base/semver.lua10
-rw-r--r--xmake/modules/package/manager/install.lua2
-rw-r--r--xmake/packages/git/xmake.lua17
-rw-r--r--xmake/platforms/windows/environment.lua19
16 files changed, 81 insertions, 202 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 3858e8adc..fbc9adc40 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -159,7 +159,7 @@ function main()
local targetname = option.get("target")
-- config it first
- task.run("config", {target = targetname})
+ task.run("config", {target = targetname, require = false})
-- init finished states
_g.finished = {}
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 9170e75cf..f8c748876 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -261,12 +261,13 @@ function main()
_check_target(targetname)
-- install and update requires and config header
- if recheck then
-
- -- install requires
+ local require_enable = option.boolean(option.get("require"))
+ if (recheck or require_enable) and require_enable ~= false then
install_requires()
+ end
- -- generate config header
+ -- update the config header
+ if recheck then
generate_configheader()
end
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 0fa00d358..7b7e6523a 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -46,6 +46,9 @@ task("config")
, options =
{
{'c', "clean", "k", nil, "Clean the cached configure and configure all again." }
+ , {nil, "require", "kv", nil, "Require all dependent packages?",
+ " - y: force to enable",
+ " - n: disable" }
, {}
, {'p', "plat", "kv", "$(host)", "Compile for the given platform."
diff --git a/xmake/actions/require/environment.lua b/xmake/actions/require/environment.lua
index 79848387d..bbbe1e587 100644
--- a/xmake/actions/require/environment.lua
+++ b/xmake/actions/require/environment.lua
@@ -23,165 +23,7 @@
--
-- imports
-import("core.base.option")
import("core.platform.environment")
-import("net.http")
-import("net.fasturl")
-import("utils.archive")
-
--- enter linux environment
-function _enter_linux()
-
- -- add $programdir to $path for running xmake
- os.addenv("PATH", os.programdir())
-end
-
--- enter macosx environment
-function _enter_macosx()
-
- -- add $programdir to $path for running xmake
- os.addenv("PATH", os.programdir())
-end
-
--- enter windows environment (xmake/winenv/cmd)
---
--- @note curl and tar has been placed in the xmake installation package
---
-function _enter_windows()
-
- -- init winenv directory
- local winenv_dir = path.translate("~/.xmake/winenv")
-
- -- add $programdir/winenv/cmd to $path
- os.addenv("PATH", path.join(os.programdir(), "winenv", "bin"))
-
- -- load winenv
- for _, script_dir in ipairs(os.files(path.join(winenv_dir, "**", "winenv.lua")), path.directory) do
- import("winenv", {rootdir = script_dir}).main(script_dir)
- return
- end
-
- -- trace
- cprintf("installing winenv .. ")
- if option.get("verbose") then
- print("")
- end
-
- -- init winenv.zip file path
- local winenv_zip = os.tmpfile() .. ".zip"
- local winenv_zip_tmp = winenv_zip .. ".tmp"
-
- -- init winenv.zip urls
- local winenv_arch = ifelse(os.arch() == "x64", "win64", "win32")
- local winenv_urls =
- {
- format("https://github.com/tboox/xmake-%senv/archive/master.zip", winenv_arch)
- , format("https://coding.net/u/waruqi/p/xmake-%senv/git/archive/master", winenv_arch)
- }
- fasturl.add(winenv_urls)
-
- -- download winenv.zip file
- for _, winenv_url in ipairs(fasturl.sort(winenv_urls)) do
- local ok = try
- {
- function ()
-
- -- no cached winenv.zip file?
- if not os.isfile(winenv_zip) or option.get("force") then
-
- -- remove winenv.zip.tmp file first
- os.rm(winenv_zip_tmp)
-
- -- create a download task
- local task = function ()
- http.download(winenv_url, winenv_zip_tmp)
- end
-
- -- download winenv.zip
- if option.get("verbose") then
- task()
- else
- process.asyncrun(task)
- end
-
- -- attempt to remove previous winenv.zip first
- os.rm(winenv_zip)
-
- -- rename winenv.zip.tmp to winenv.zip
- os.mv(winenv_zip_tmp, winenv_zip)
- end
-
- -- ok
- return true
- end,
-
- catch
- {
- function (errors)
-
- -- verbose?
- if option.get("verbose") then
- cprint("${bright red}error: ${clear}%s", errors)
- end
- end
- }
- }
-
- -- ok?
- if ok then
-
- -- remove winenv directory first
- os.rm(winenv_dir)
-
- -- extract winenv.zip file
- archive.extract(winenv_zip, winenv_dir)
-
- -- load winenv
- for _, script_dir in ipairs(os.files(path.join(winenv_dir, "**", "winenv.lua")), path.directory) do
- import("winenv", {rootdir = script_dir}).main(script_dir)
- break
- end
-
- -- trace
- cprint("${green}ok")
-
- -- ok
- return
- end
- end
-
- -- failed
- cprint("${red}failed")
- raise()
-end
-
--- enter host environment
-function _enter_host()
-
- -- save old $path environment
- _g._PATH_ENV = os.getenv("PATH")
-
- -- init loaders
- local loaders =
- {
- linux = _enter_linux
- , macosx = _enter_macosx
- , windows = _enter_windows
- }
-
- -- enter host environment
- local loader = loaders[os.host()]
- if loader then
- loader()
- end
-end
-
--- leave host environment
-function _leave_host()
-
- -- restore old $path environment
- os.setenv("PATH", _g._PATH_ENV)
-end
-- enter environment
--
@@ -191,9 +33,6 @@ end
--
function enter()
- -- enter host environment
- _enter_host()
-
-- set search pathes of toolchains
environment.enter("toolchains")
@@ -212,7 +51,4 @@ function leave()
-- TODO set flags of toolchains
-
- -- leave host environment
- _leave_host()
end
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 1cdc406df..48fc37b25 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -232,7 +232,6 @@ function main(requires)
if _g.installed then return end
_g.installed = true
- -- TODO move the global modules
-- enter environment
environment.enter()
diff --git a/xmake/actions/require/list.lua b/xmake/actions/require/list.lua
index 3964ff284..d809b9694 100644
--- a/xmake/actions/require/list.lua
+++ b/xmake/actions/require/list.lua
@@ -54,12 +54,11 @@ function main()
return
end
- -- TODO
-- enter environment
environment.enter()
-- pull all repositories first if not exists
- if not repository.exists() then
+ if not repository.pulled() then
task.run("repo", {update = true})
end
diff --git a/xmake/actions/require/main.lua b/xmake/actions/require/main.lua
index 1190460f6..3c3f64f7e 100644
--- a/xmake/actions/require/main.lua
+++ b/xmake/actions/require/main.lua
@@ -60,7 +60,7 @@ import("install")
function _load_project()
-- config it first
- task.run("config")
+ task.run("config", {require = false})
-- enter project directory
os.cd(project.directory())
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
index ed7e5f497..339dfe1ef 100644
--- a/xmake/actions/uninstall/main.lua
+++ b/xmake/actions/uninstall/main.lua
@@ -57,7 +57,7 @@ function main()
local targetname = option.get("target")
-- config it first
- task.run("config", {target = targetname})
+ task.run("config", {target = targetname, require = "n"})
-- get install directory
local installdir = _installdir()
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index de87014ab..c8a613d0e 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -326,11 +326,7 @@ function option.init(menu)
end
-- value is "true" or "false", translate it
- if type(value) == "string" then
- if value == "true" or value == "yes" or value == "y" then value = true
- elseif value == "false" or value == "no" or value == "n" then value = false
- end
- end
+ value = option.boolean(value)
-- save option
context.options[longname] = value
@@ -592,11 +588,7 @@ function option.parse(argv, options)
end
-- value is "true" or "false", translate it
- if type(value) == "string" then
- if value == "true" or value == "yes" or value == "y" then value = true
- elseif value == "false" or value == "no" or value == "n" then value = false
- end
- end
+ value = option.boolean(value)
-- save option
results[longname] = value
@@ -712,7 +704,11 @@ function option.get(name)
-- the options
local options = option.options()
if options then
- return options[name] or option.default(name)
+ local value = options[name]
+ if value == nil then
+ value = option.default(name)
+ end
+ return value
end
end
@@ -733,6 +729,17 @@ function option.set(name, value)
options[name] = value
end
+-- get the boolean value
+function option.boolean(value)
+
+ if type(value) == "string" then
+ if value == "true" or value == "yes" or value == "y" then value = true
+ elseif value == "false" or value == "no" or value == "n" then value = false
+ end
+ end
+ return value
+end
+
-- get the given default option value for the current task
function option.default(name)
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 6df0f5326..04b243105 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -377,7 +377,10 @@ function package.apis()
, "package.set_description"
-- package.add_xxx
, "package.add_deps"
+ , "package.add_urls"
+ , "package.add_sha256s"
, "package.add_imports"
+ , "package.add_versions"
}
, script =
{
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 2d6543fe0..2323151d7 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -124,7 +124,7 @@ end
function project._api_is_host(interp, ...)
-- get the current host
- local host = xmake._HOST
+ local host = os.host()
if not host then return false end
-- exists this host? and escape '-'
diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua
index 048901587..0f6770902 100644
--- a/xmake/core/sandbox/modules/import/core/base/option.lua
+++ b/xmake/core/sandbox/modules/import/core/base/option.lua
@@ -32,36 +32,26 @@ local raise = require("sandbox/modules/raise")
-- get the option value
function sandbox_core_base_option.get(name)
-
- -- get it
return option.get(name)
end
-- set the option value
function sandbox_core_base_option.set(name, value)
-
- -- set it
option.set(name, value)
end
-- get the default option value
function sandbox_core_base_option.default(name)
-
- -- get it
return option.default(name)
end
-- get the options
function sandbox_core_base_option.options()
-
- -- get it
return assert(option.options())
end
-- get the defaults
function sandbox_core_base_option.defaults()
-
- -- get it
return option.defaults() or {}
end
@@ -121,5 +111,10 @@ function sandbox_core_base_option.restore()
option.restore()
end
+-- get the boolean value
+function sandbox_core_base_option.boolean(value)
+ return option.boolean(value)
+end
+
-- return module
return sandbox_core_base_option
diff --git a/xmake/core/sandbox/modules/import/core/base/semver.lua b/xmake/core/sandbox/modules/import/core/base/semver.lua
index 85642195b..57b0924d3 100644
--- a/xmake/core/sandbox/modules/import/core/base/semver.lua
+++ b/xmake/core/sandbox/modules/import/core/base/semver.lua
@@ -73,8 +73,16 @@ end
--
function sandbox_core_base_semver.select(range, versions, tags, branches)
+ -- only master?
+ versions = table.wrap(versions)
+ tags = table.wrap(tags)
+ branches = table.wrap(branches)
+ if #versions == 0 and #tags == 0 and #branches == 0 and range == "master" then
+ return "master", "versions"
+ end
+
-- select version
- local verinfo, errors = semver.select(range, versions or {}, tags or {}, branches or {})
+ local verinfo, errors = semver.select(range, table.wrap(versions), table.wrap(tags), table.wrap(branches))
if not verinfo then
raise(errors)
end
diff --git a/xmake/modules/package/manager/install.lua b/xmake/modules/package/manager/install.lua
index 7ebd34180..175a1cecf 100644
--- a/xmake/modules/package/manager/install.lua
+++ b/xmake/modules/package/manager/install.lua
@@ -40,6 +40,8 @@ function main(name, opt)
table.insert(scripts, import("yum.install", {anonymous = true}))
table.insert(scripts, import("pacman.install", {anonymous = true}))
table.insert(scripts, import("brew.install", {anonymous = true}))
+ elseif host = "windows" then
+ table.insert(scripts, import("pacman.install", {anonymous = true})) -- msys/mingw
end
assert(#scripts > 0, "package manager not found!")
diff --git a/xmake/packages/git/xmake.lua b/xmake/packages/git/xmake.lua
index b1825dc4d..1029771b1 100644
--- a/xmake/packages/git/xmake.lua
+++ b/xmake/packages/git/xmake.lua
@@ -3,7 +3,14 @@ package("git")
set_kind("binary")
set_homepage("https://git-scm.com/")
set_description("A free and open source distributed version control system")
- add_imports("package.manager.install", "lib.detect.find_tool")
+
+ if os.host() == "windows" then
+ local winenv_arch = ifelse(os.arch() == "x64", "win64", "win32")
+ add_urls(format("https://github.com/tboox/xmake-%senv/archive/master.zip", winenv_arch))
+ add_urls(format("https://coding.net/u/waruqi/p/xmake-%senv/git/archive/master", winenv_arch))
+ else
+ add_imports("package.manager.install")
+ end
on_build(function (package)
end)
@@ -13,5 +20,13 @@ package("git")
end)
on_install("windows", function (package)
+
+ -- install winenv with git
+ local winenv_dir = path.translate("~/.xmake/winenv")
+ os.mkdir(winenv_dir)
+ os.cp("*", winenv_dir)
+
+ -- load winenv
+ import("winenv", {rootdir = winenv_dir})(winenv_dir)
end)
diff --git a/xmake/platforms/windows/environment.lua b/xmake/platforms/windows/environment.lua
index a6f597e6a..8039fa31f 100644
--- a/xmake/platforms/windows/environment.lua
+++ b/xmake/platforms/windows/environment.lua
@@ -69,25 +69,36 @@ function _leave(name, old)
end
end
--- enter the toolchains environment (vs)
+-- enter the toolchains environment
function _enter_toolchains()
+ -- enter vs toolchains
_g.pathes = _enter("path")
_g.libs = _enter("lib")
_g.includes = _enter("include")
_g.libpathes = _enter("libpath")
+
+ -- add $programdir/winenv/bin to $path
+ os.addenv("path", path.join(os.programdir(), "winenv", "bin"))
+
+ -- attempt to load winenv
+ local winenv_dir = path.translate("~/.xmake/winenv")
+ if os.isdir(winenv_dir) then
+ import("winenv", {rootdir = winenv_dir, try = true, anonymous = true})(winenv_dir)
+ end
end
--- leave the toolchains environment (vs)
+-- leave the toolchains environment
function _leave_toolchains()
+ -- leave vs toolchains
_leave("path", _g.pathes)
_leave("lib", _g.libs)
_leave("include", _g.includes)
_leave("libpath", _g.libpathes)
end
--- enter the toolchains environment (vs)
+-- enter the toolchains environment
function enter(name)
-- the maps
@@ -100,7 +111,7 @@ function enter(name)
end
end
--- leave the toolchains environment (vs)
+-- leave the toolchains environment
function leave(name)
-- the maps