diff options
| author | ruki <[email protected]> | 2015-06-10 11:10:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-10 11:10:25 +0800 |
| commit | 177400e62e74d5ad3539573cfd3143cd19d3d30f (patch) | |
| tree | b6fa15adda822c3cb1d6b8c2967bb2c6690e572c /xmake/scripts/base | |
| parent | 7a2f8c098db24b46c37ab0db79d6e511b1681a77 (diff) | |
add project menu
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/config.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/base/io.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 47 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 71 | ||||
| -rw-r--r-- | xmake/scripts/base/utils.lua | 3 |
5 files changed, 82 insertions, 44 deletions
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua index f8fb8afca..62db41dee 100644 --- a/xmake/scripts/base/config.lua +++ b/xmake/scripts/base/config.lua @@ -114,7 +114,7 @@ end function config.get(name) -- check - assert(config._CURRENT) + if not config._CURRENT then return end -- the value local value = config._CURRENT[name] diff --git a/xmake/scripts/base/io.lua b/xmake/scripts/base/io.lua index 4a5a3b65a..db2164c04 100644 --- a/xmake/scripts/base/io.lua +++ b/xmake/scripts/base/io.lua @@ -29,9 +29,6 @@ local utils = require("base/utils") -- save object with the level function io._save_with_level(file, object, level) - -- check - assert(object) - -- save string if type(object) == "string" then file:write(string.format("%q", object)) diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 8f61b6940..77db5b2de 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -129,21 +129,6 @@ function main._prepare_project() local options = xmake._OPTIONS assert(options) - -- init the project directory - options.project = options.project or options._DEFAULTS.project or xmake._PROJECT_DIR - options.project = path.absolute(options.project) - assert(options.project) - - -- save the project directory - xmake._PROJECT_DIR = options.project - - -- init the xmake.lua file path - options.file = options.file or options._DEFAULTS.file or "xmake.lua" - if not path.is_absolute(options.file) then - options.file = path.absolute(options.file, options.project) - end - assert(options.file) - -- init the build directory if options.buildir and path.is_absolute(options.buildir) then options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR) @@ -182,7 +167,7 @@ function main._prepare_project() end -- load xmake.lua file - return project.load(options.file) + return project.load(xmake._PROJECT_FILE) end -- done help @@ -283,14 +268,34 @@ function main._done_option() return action.done(options._ACTION or "build") end +-- the init function for main +function main._init() + + -- init the project directory + local projectdir = option.find(xmake._ARGV, "project", "P") or xmake._PROJECT_DIR + if projectdir and not path.is_absolute(projectdir) then + projectdir = path.absolute(projectdir) + elseif projectdir then + projectdir = path.translate(projectdir) + end + xmake._PROJECT_DIR = projectdir + assert(projectdir) + + -- init the xmake.lua file path + local projectfile = option.find(xmake._ARGV, "file", "f") or xmake._PROJECT_FILE + if projectfile and not path.is_absolute(projectfile) then + projectfile = path.absolute(projectfile, projectdir) + end + xmake._PROJECT_FILE = projectfile + assert(projectfile) + +end + -- the main function function main.done() - -- init project directory first - local projectdir = option.find(xmake._ARGV, "project", "P") - if projectdir then - xmake._PROJECT_DIR = path.absolute(projectdir) - end + -- init + main._init() -- init option if not option.init(xmake._ARGV, menu) then diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index db4600307..27041ac81 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -34,7 +34,7 @@ function project._api_modes(env, ...) -- get the current mode local mode = config.get("mode") - assert(mode) + if not mode then return false end -- exists this mode? for _, m in ipairs(table.join(...)) do @@ -49,7 +49,7 @@ function project._api_plats(env, ...) -- get the current platform local plat = config.get("plat") - assert(plat) + if not plat then return false end -- exists this platform? for _, p in ipairs(table.join(...)) do @@ -64,7 +64,7 @@ function project._api_archs(env, ...) -- get the current architecture local arch = config.get("arch") - assert(arch) + if not arch then return false end -- exists this architecture? for _, a in ipairs(table.join(...)) do @@ -373,18 +373,8 @@ function project._make(configs) end end --- get the current configure for targets -function project.targets() - - -- check - assert(project._TARGETS) - - -- return it - return project._TARGETS -end - -- load the project file -function project.load(file) +function project._load(file) -- check assert(file) @@ -491,8 +481,25 @@ function project.load(file) return errors end - -- make the current project configure - project._make(newenv._CONFIGS) + -- get the project configure + return newenv._CONFIGS +end + +-- get the current configure for targets +function project.targets() + + -- check + assert(project._TARGETS) + + -- return it + return project._TARGETS +end + +-- load the project file +function project.load(file) + + -- load and make the project configure + project._make(project._load(file)) end -- dump the current configure @@ -540,5 +547,37 @@ function project.makeconf(target_name) return true end +-- get the project menu +function project.menu() + + -- attempt to load project configure + local configs = nil + local projectfile = xmake._PROJECT_FILE + if projectfile and os.isfile(projectfile) then + configs = project._load(projectfile) + end + + -- the options + local options = nil + if configs then options = configs._OPTIONS end + if not options then return {} end + + -- make menu + local menu = {{}} + for name, opt in pairs(options) do + + -- the default + local default = utils.unwrap(opt.default) + if default then default = "true" + else default = "auto" end + + -- append it + table.insert(menu, {nil, name, "kv", default, utils.unwrap(opt.description)}) + end + + -- ok? + return menu +end + -- return module: project return project diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua index 469fb4a4a..a2efbb482 100644 --- a/xmake/scripts/base/utils.lua +++ b/xmake/scripts/base/utils.lua @@ -53,9 +53,6 @@ end -- dump object with the level function utils._dump_with_level(object, exclude, level) - -- check - assert(object) - -- dump string if type(object) == "string" then io.write(string.format("%q", object)) |
