summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-19 16:23:29 +0800
committerruki <[email protected]>2015-06-19 16:23:29 +0800
commit1d041891edec9d99a1922fd7f4a4770b60412cfd (patch)
treee5cd7add5e44a873544859a6e17afc998ec75d54 /xmake/scripts
parentc93c5254d82a621a116dbbcd0130b08f5e33ce2b (diff)
rebuild the main implementation
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/action/_build.lua13
-rw-r--r--xmake/scripts/action/_clean.lua13
-rw-r--r--xmake/scripts/action/_config.lua13
-rw-r--r--xmake/scripts/action/_create.lua7
-rw-r--r--xmake/scripts/action/_debug.lua13
-rw-r--r--xmake/scripts/action/_global.lua19
-rw-r--r--xmake/scripts/action/_lua.lua7
-rw-r--r--xmake/scripts/action/_man.lua13
-rw-r--r--xmake/scripts/action/_run.lua13
-rw-r--r--xmake/scripts/action/action.lua101
-rw-r--r--xmake/scripts/base/main.lua110
11 files changed, 207 insertions, 115 deletions
diff --git a/xmake/scripts/action/_build.lua b/xmake/scripts/action/_build.lua
index 9e031f380..b9bd05eef 100644
--- a/xmake/scripts/action/_build.lua
+++ b/xmake/scripts/action/_build.lua
@@ -31,6 +31,19 @@ local config = require("base/config")
local project = require("base/project")
local makefile = require("base/makefile")
+-- need access to the given file?
+function _build.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { config = true, global = true, project = true, platform = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _build.done()
diff --git a/xmake/scripts/action/_clean.lua b/xmake/scripts/action/_clean.lua
index 31b5209d3..a02eb3622 100644
--- a/xmake/scripts/action/_clean.lua
+++ b/xmake/scripts/action/_clean.lua
@@ -29,6 +29,19 @@ local config = require("base/config")
local project = require("base/project")
local platform = require("platform/platform")
+-- need access to the given file?
+function _clean.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { global = true, config = true, project = true, platform = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _clean.done()
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index 449d2bc03..c014d3bc7 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -30,6 +30,19 @@ local project = require("base/project")
local makefile = require("base/makefile")
local platform = require("platform/platform")
+-- need access to the given file?
+function _config.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { config = true, global = true, project = true, platform = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _config.done()
diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua
index 5b072b135..133e688d3 100644
--- a/xmake/scripts/action/_create.lua
+++ b/xmake/scripts/action/_create.lua
@@ -29,6 +29,13 @@ local config = require("base/config")
local template = require("base/template")
local platform = require("platform/platform")
+-- need access to the given file?
+function _create.need(name)
+
+ -- no accessors
+ return false
+end
+
-- done the given config
function _create.done()
diff --git a/xmake/scripts/action/_debug.lua b/xmake/scripts/action/_debug.lua
index 859191c26..457318222 100644
--- a/xmake/scripts/action/_debug.lua
+++ b/xmake/scripts/action/_debug.lua
@@ -28,6 +28,19 @@ local utils = require("base/utils")
local config = require("base/config")
local platform = require("platform/platform")
+-- need access to the given file?
+function _debug.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { config = true, global = true, project = true, platform = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _debug.done()
diff --git a/xmake/scripts/action/_global.lua b/xmake/scripts/action/_global.lua
index 2ae54483c..24dfe9567 100644
--- a/xmake/scripts/action/_global.lua
+++ b/xmake/scripts/action/_global.lua
@@ -28,9 +28,28 @@ local utils = require("base/utils")
local global = require("base/global")
local platform = require("platform/platform")
+-- need access to the given file?
+function _global.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { global = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _global.done()
+ -- probe the global platform configure
+ platform.probe(true)
+
+ -- clear up the global configure
+ global.clearup()
+
-- save the global configure
if not global.save() then
-- error
diff --git a/xmake/scripts/action/_lua.lua b/xmake/scripts/action/_lua.lua
index 11385a052..75500acb0 100644
--- a/xmake/scripts/action/_lua.lua
+++ b/xmake/scripts/action/_lua.lua
@@ -31,7 +31,14 @@ local config = require("base/config")
local string = require("base/string")
local tools = require("tools/tools")
local platform = require("platform/platform")
+
+-- need access to the given file?
+function _lua.need(name)
+ -- no accessors
+ return false
+end
+
-- done the given config
function _lua.done()
diff --git a/xmake/scripts/action/_man.lua b/xmake/scripts/action/_man.lua
index 25fa3340a..ea48704d5 100644
--- a/xmake/scripts/action/_man.lua
+++ b/xmake/scripts/action/_man.lua
@@ -28,6 +28,19 @@ local utils = require("base/utils")
local config = require("base/config")
local platform = require("platform/platform")
+-- need access to the given file?
+function _man.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { config = true, global = true, project = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _man.done()
diff --git a/xmake/scripts/action/_run.lua b/xmake/scripts/action/_run.lua
index 1a24874e0..bec3656b3 100644
--- a/xmake/scripts/action/_run.lua
+++ b/xmake/scripts/action/_run.lua
@@ -31,6 +31,19 @@ local config = require("base/config")
local project = require("base/project")
local platform = require("platform/platform")
+-- need access to the given file?
+function _run.need(name)
+
+ -- check
+ assert(name)
+
+ -- the accessors
+ local accessors = { config = true, global = true, project = true, platform = true }
+
+ -- need it?
+ return accessors[name]
+end
+
-- done the given config
function _run.done()
diff --git a/xmake/scripts/action/action.lua b/xmake/scripts/action/action.lua
index a0574ec58..5602bf4ab 100644
--- a/xmake/scripts/action/action.lua
+++ b/xmake/scripts/action/action.lua
@@ -24,8 +24,12 @@
local action = action or {}
-- load modules
-local os = require("base/os")
-local path = require("base/path")
+local os = require("base/os")
+local path = require("base/path")
+local global = require("base/global")
+local config = require("base/config")
+local project = require("base/project")
+local platform = require("platform/platform")
-- load the given action
function action._load(name)
@@ -34,15 +38,102 @@ function action._load(name)
return require("action/_" .. name)
end
+-- load the project file
+function action._load_project()
+
+ -- the options
+ local options = xmake._OPTIONS
+ assert(options)
+
+ -- check the project file
+ if not os.isfile(xmake._PROJECT_FILE) then
+ return string.format("not found the project file: %s", xmake._PROJECT_FILE)
+ end
+
+ -- init the build directory
+ if options.buildir and path.is_absolute(options.buildir) then
+ options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR)
+ end
+
+ -- xmake config or marked as "reconfig"?
+ if options._ACTION == "config" or config._RECONFIG then
+
+ -- probe the current project
+ project.probe()
+
+ -- clear up the configure
+ config.clearup()
+
+ end
+
+ -- load the project
+ return project.load()
+end
+
-- done the given action
function action.done(name)
+ -- the options
+ local options = xmake._OPTIONS
+ assert(options)
+
-- load the given action
- local a = action._load(name)
- if not a then return false end
+ local _action = action._load(name)
+ if not _action then return false end
+
+ -- load the global configure first
+ if _action.need("global") then global.load() end
+
+ -- load the project configure
+ if _action.need("config") then
+ local errors = config.load()
+ if errors then
+ -- error
+ utils.error(errors)
+ return false
+ end
+ end
+
+ -- probe the platform
+ if _action.need("platform") and (options._ACTION == "config" or config._RECONFIG) then
+ platform.probe(false)
+ end
+
+ -- merge the default options
+ for k, v in pairs(options._DEFAULTS) do
+ if nil == options[k] then options[k] = v end
+ end
+
+ -- make the platform configure
+ if _action.need("platform") and not platform.make() then
+ utils.error("make platform configure: %s failed!", config.get("plat"))
+ return false
+ end
+
+ -- load the project file
+ if _action.need("project") then
+ local errors = action._load_project()
+ if errors then
+ -- error
+ utils.error(errors)
+ return false
+ end
+ end
+
+ -- reconfig it first if marked as "reconfig"
+ if _action.need("config") and config._RECONFIG then
+
+ -- config it
+ local _action_config = action._load("config")
+ if not _action_config or not _action_config.done() then
+ -- error
+ utils.error("reconfig failed for the changed host!")
+ return false
+ end
+ end
-- done the given action
- return a.done()
+ return _action.done()
end
-- list the all actions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index c8ce0fe37..852ee9104 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -28,11 +28,7 @@ local os = require("base/os")
local path = require("base/path")
local utils = require("base/utils")
local option = require("base/option")
-local config = require("base/config")
-local global = require("base/global")
-local project = require("base/project")
local action = require("action/action")
-local platform = require("platform/platform")
-- init the option menu
local menu =
@@ -86,84 +82,6 @@ local menu =
}
--- prepare global
-function main._init_global()
-
- -- the options
- local options = xmake._OPTIONS
- assert(options)
-
- -- load global configure
- global.load()
-
- -- xmake global?
- if options._ACTION == "global" then
-
- -- probe the global platform configure
- platform.probe(true)
-
- -- clear up the global configure
- global.clearup()
- end
-
- -- ok
- return true
-end
-
--- init project
-function main._init_project()
-
- -- the options
- local options = xmake._OPTIONS
- assert(options)
-
- -- check the project file
- if not os.isfile(xmake._PROJECT_FILE) then
- return string.format("not found the project file: %s", xmake._PROJECT_FILE)
- end
-
- -- init the build directory
- if options.buildir and path.is_absolute(options.buildir) then
- options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR)
- end
-
- -- load xmake.xconf file first
- local errors = config.load()
- if errors then return errors end
-
- -- xmake config or marked as "reconfig"?
- if options._ACTION == "config" or config._RECONFIG then
-
- -- probe the current platform
- platform.probe(false)
-
- end
-
- -- merge the default options
- for k, v in pairs(options._DEFAULTS) do
- if nil == options[k] then options[k] = v end
- end
-
- -- make the current platform configure
- if not platform.make() then
- return string.format("make platform configure: %s failed!", config.get("plat"))
- end
-
- -- xmake config or marked as "reconfig"?
- if options._ACTION == "config" or config._RECONFIG then
-
- -- probe the current project
- project.probe()
-
- -- clear up the configure
- config.clearup()
-
- end
-
- -- load the project
- return project.load()
-end
-
-- done help
function main._done_help()
@@ -210,34 +128,6 @@ function main._done_option()
return true
end
- -- done lua?
- if options._ACTION == "lua" then
- return action.done("lua")
- end
-
- -- init global
- main._init_global()
-
- -- done global?
- if options._ACTION == "global" then
- return action.done("global")
- end
-
- -- init project
- local errors = main._init_project()
- if errors then
- -- error
- utils.error(errors)
- return false
- end
-
- -- reconfig it first if marked as "reconfig"
- if config._RECONFIG and not action.done("config") then
- -- error
- utils.error("reconfig failed for the changed host!")
- return false
- end
-
-- done action
return action.done(options._ACTION or "build")
end