summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/core/base/action.lua6
-rw-r--r--xmake/core/base/config.lua12
-rw-r--r--xmake/core/base/global.lua4
-rw-r--r--xmake/core/base/main.lua4
-rw-r--r--xmake/core/base/option.lua56
5 files changed, 53 insertions, 29 deletions
diff --git a/xmake/core/base/action.lua b/xmake/core/base/action.lua
index 3e713221e..d210b2874 100644
--- a/xmake/core/base/action.lua
+++ b/xmake/core/base/action.lua
@@ -64,7 +64,7 @@ function action._load_project()
end
-- xmake config or marked as "reconfig"?
- if options._TASK == "config" or config._RECONFIG then
+ if option.task() == "config" or config._RECONFIG then
-- probe the current project
project.probe()
@@ -103,14 +103,14 @@ function action.done(name)
end
-- probe the platform
- if _action.need("platform") and (options._TASK == "config" or config._RECONFIG) then
+ if _action.need("platform") and (option.task() == "config" or config._RECONFIG) then
if not platform.probe(false) then
return false
end
end
-- merge the default options
- for k, v in pairs(options._DEFAULTS) do
+ for k, v in pairs(option.defaults()) do
if nil == options[k] then options[k] = v end
end
diff --git a/xmake/core/base/config.lua b/xmake/core/base/config.lua
index f41340e2e..f3469ce17 100644
--- a/xmake/core/base/config.lua
+++ b/xmake/core/base/config.lua
@@ -104,7 +104,7 @@ function config._target()
assert(configs)
-- the target name
- local name = options.target or options._DEFAULTS.target
+ local name = options.target or option.default("target")
assert(name and type(name) == "string")
-- for all targets?
@@ -206,7 +206,7 @@ function config.load()
assert(option._MENU.config)
-- the target name
- local name = options.target or options._DEFAULTS.target
+ local name = options.target or option.default("target")
if not name then
return "no given target name!"
end
@@ -237,7 +237,7 @@ function config.load()
config._CONFIGS = { __rebuild = true }
-- mark as "reconfig" if the current action is not "config"
- if options._TASK ~= "config" then
+ if option.task() ~= "config" then
config._RECONFIG = true
end
end
@@ -275,7 +275,7 @@ function config.load()
config._CONFIGS = { __rebuild = true }
-- mark as "reconfig" if the current action is not "config"
- if options._TASK ~= "config" then
+ if option.task() ~= "config" then
config._RECONFIG = true
end
end
@@ -292,7 +292,7 @@ function config.load()
local defaults = nil
if not configs._DEFAULTS then
if config._RECONFIG then defaults = option.defaults("config")
- elseif options._TASK == "config" then defaults = options._DEFAULTS
+ elseif option.task() == "config" then defaults = option.defaults()
end
if defaults then
for k, v in pairs(defaults) do
@@ -323,7 +323,7 @@ function config.load()
assert(target and type(target) == "table")
-- merge option.options() to target
- if options._TASK == "config" then
+ if option.task() == "config" then
for k, v in pairs(options) do
-- check
diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua
index 2c178af71..42ba754e5 100644
--- a/xmake/core/base/global.lua
+++ b/xmake/core/base/global.lua
@@ -169,7 +169,7 @@ function global.load()
local configs = global._CONFIGS
-- xmake global?
- if options._TASK == "global" then
+ if option.task() == "global" then
-- merge option.options() to the global configure
for k, v in pairs(options) do
@@ -184,7 +184,7 @@ function global.load()
end
-- merge the default global configure options to the global configure
- local defaults = options._DEFAULTS
+ local defaults = option.defaults()
if defaults then
for k, v in pairs(defaults) do
diff --git a/xmake/core/base/main.lua b/xmake/core/base/main.lua
index 4bc077ff6..e8f687e5d 100644
--- a/xmake/core/base/main.lua
+++ b/xmake/core/base/main.lua
@@ -56,7 +56,7 @@ function main._done_help()
if options.help then
-- print menu
- option.print_menu(options._TASK)
+ option.print_menu(option.task())
-- ok
return true
@@ -92,7 +92,7 @@ function main._done_option()
end
-- done action
- return action.done(options._TASK or "build")
+ return action.done(option.task() or "build")
end
-- the init function for main
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index 70d5e31be..28af2c299 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -115,7 +115,7 @@ function option.init(argv, menu)
print("invalid option: " .. arg)
-- print menu
- option.print_menu(option._OPTIONS._TASK)
+ option.print_menu(option._TASK)
-- failed
return false
@@ -126,7 +126,7 @@ function option.init(argv, menu)
-- find this option
local opt = nil
- for _, o in ipairs(menu[option._OPTIONS._TASK or "main"].options) do
+ for _, o in ipairs(menu[option._TASK or "main"].options) do
-- check
assert(o)
@@ -149,7 +149,7 @@ function option.init(argv, menu)
print("invalid option: " .. arg)
-- print menu
- option.print_menu(option._OPTIONS._TASK)
+ option.print_menu(option._TASK)
-- failed
return false
@@ -169,7 +169,7 @@ function option.init(argv, menu)
print("invalid option: " .. option._ifelse(idx, arg, key))
-- print menu
- option.print_menu(option._OPTIONS._TASK)
+ option.print_menu(option._TASK)
-- failed
return false
@@ -186,7 +186,7 @@ function option.init(argv, menu)
print("invalid option: " .. arg)
-- print menu
- option.print_menu(option._OPTIONS._TASK)
+ option.print_menu(option._TASK)
-- failed
return false
@@ -214,13 +214,13 @@ function option.init(argv, menu)
-- ok?
if taskname == key or menu[taskname].shortname == key then
-- save this task
- option._OPTIONS._TASK = taskname
+ option._TASK = taskname
break
end
end
-- not found?
- if not option._OPTIONS._TASK or not menu[option._OPTIONS._TASK] then
+ if not option._TASK or not menu[option._TASK] then
-- invalid task
print("invalid task: " .. key)
@@ -238,7 +238,7 @@ function option.init(argv, menu)
-- find a value option with name
local opt = nil
- for _, o in ipairs(menu[option._OPTIONS._TASK or "main"].options) do
+ for _, o in ipairs(menu[option._TASK or "main"].options) do
-- the mode
local mode = o[3]
@@ -288,7 +288,7 @@ function option.init(argv, menu)
print("invalid option: " .. arg)
-- print menu
- option.print_menu(option._OPTIONS._TASK)
+ option.print_menu(option._TASK)
-- failed
return false
@@ -298,7 +298,7 @@ function option.init(argv, menu)
end
-- init the default value
- for _, o in ipairs(menu[option._OPTIONS._TASK or "main"].options) do
+ for _, o in ipairs(menu[option._TASK or "main"].options) do
-- key=value?
if o[3] == "kv" then
@@ -352,7 +352,14 @@ function option.find(argv, name, shortname)
end
end
--- get the given option
+-- get the current task
+function option.task()
+
+ -- get it
+ return option._TASK
+end
+
+-- get the given option value for the current task
function option.get(name)
-- check
@@ -366,20 +373,37 @@ function option.get(name)
return options[name]
end
--- get all options
+-- get the given default option value for the current task
+function option.default(name)
+
+ -- check
+ assert(name)
+
+ -- the defaults
+ local defaults = option.defaults()
+ assert(defaults)
+
+ -- get it
+ return defaults[name]
+end
+
+-- get the current options
function option.options()
-- get it
return option._OPTIONS
end
--- get all default options from the given task
+-- get all default options for the current or given task
function option.defaults(task)
- -- make defaults
- local defaults = {}
+ -- get the default options for the current task
+ if task == nil then
+ return option._OPTIONS._DEFAULTS
+ end
- -- init the default value
+ -- get the default options for the given task
+ local defaults = {}
for _, o in ipairs(option._MENU[task or "main"].options) do
-- key=value?