diff options
| author | ruki <[email protected]> | 2016-03-28 13:04:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-28 13:04:24 +0800 |
| commit | 7edb31caaa3d1a0d58737324b6af85cb3b2d2c75 (patch) | |
| tree | e041e67878bdaef387742986debb08b639274995 | |
| parent | f86b3d2ae37f1bb0633246f7d1cea81f996b7d48 (diff) | |
optimizate option menu
| -rw-r--r-- | xmake/core/base/option.lua | 55 | ||||
| -rw-r--r-- | xmake/core/main.lua | 4 | ||||
| -rw-r--r-- | xmake/core/platform/compiler.lua | 52 | ||||
| -rw-r--r-- | xmake/core/project/task.lua | 232 |
4 files changed, 191 insertions, 152 deletions
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 5a98a6eff..053bb85dd 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -55,6 +55,30 @@ function option._translate(menu) end +-- get the task menu +function option._taskmenu(task) + + -- check + assert(option._MENU) + + -- the current task + task = task or option._TASK or "main" + + -- get the task menu + local taskmenu = option._MENU[task] + if type(taskmenu) == "function" then + + -- load this task menu + taskmenu = taskmenu() + + -- save this task menu + option._MENU[task] = taskmenu + end + + -- get it + return taskmenu +end + -- init the option function option.init(argv, menu) @@ -65,7 +89,7 @@ function option.init(argv, menu) option._translate(menu) -- the main menu - local main = menu.main + local main = option._taskmenu("main") assert(main) -- init _OPTIONS @@ -126,7 +150,7 @@ function option.init(argv, menu) -- find this option local opt = nil - for _, o in ipairs(menu[option._TASK or "main"].options) do + for _, o in ipairs(option._taskmenu().options) do -- check assert(o) @@ -208,11 +232,8 @@ function option.init(argv, menu) -- find the current task for taskname, taskinfo in pairs(main.tasks) do - -- check - assert(menu[taskname]) - -- ok? - if taskname == key or menu[taskname].shortname == key then + if taskname == key or taskinfo.shortname == key then -- save this task option._TASK = taskname break @@ -238,7 +259,7 @@ function option.init(argv, menu) -- find a value option with name local opt = nil - for _, o in ipairs(menu[option._TASK or "main"].options) do + for _, o in ipairs(option._taskmenu().options) do -- the mode local mode = o[3] @@ -298,7 +319,7 @@ function option.init(argv, menu) end -- init the default value - for _, o in ipairs(menu[option._TASK or "main"].options) do + for _, o in ipairs(option._taskmenu().options) do -- key=value? if o[3] == "kv" then @@ -404,7 +425,7 @@ function option.defaults(task) -- get the default options for the given task local defaults = {} - for _, o in ipairs(option._MENU[task or "main"].options) do + for _, o in ipairs(option._taskmenu(task).options) do -- key=value? if o[3] == "kv" then @@ -440,7 +461,7 @@ function option.print_menu(task) assert(menu) -- the task menu - local taskmenu = menu[task] + local taskmenu = option._taskmenu(task) assert(taskmenu) -- print title @@ -479,7 +500,7 @@ function option.print_main() assert(menu) -- the main menu - local main = menu.main + local main = option._taskmenu("main") assert(main) -- print title @@ -553,14 +574,10 @@ function option.print_main() -- print tasks for taskname, taskinfo in pairs(categorytask) do - -- the task menu - local taskmenu = taskinfo.menu - assert(taskmenu) - -- init the task line local taskline = " " - if taskmenu.shortname then - taskline = taskline .. taskmenu.shortname .. ", " + if taskinfo.shortname then + taskline = taskline .. taskinfo.shortname .. ", " else taskline = taskline .. " " end @@ -574,8 +591,8 @@ function option.print_main() end -- append the task description - if taskmenu.description then - taskline = taskline .. taskmenu.description + if taskinfo.description then + taskline = taskline .. taskinfo.description end -- print task line diff --git a/xmake/core/main.lua b/xmake/core/main.lua index d856fc686..dab1627db 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -101,7 +101,7 @@ end function main.done() -- start profiling - profiler:start() +-- profiler:start() -- init main._init() @@ -123,7 +123,7 @@ function main.done() end -- stop profiling - profiler:stop() +-- profiler:stop() -- ok return 0 diff --git a/xmake/core/platform/compiler.lua b/xmake/core/platform/compiler.lua index d37ed06c1..e703ef933 100644 --- a/xmake/core/platform/compiler.lua +++ b/xmake/core/platform/compiler.lua @@ -175,7 +175,7 @@ function compiler._addflags_from_platform(self, flags, flagnames) end end - +-- TODO optimize speed, cache it -- add flags from the target function compiler._addflags_from_target(self, flags, flagnames, target) @@ -188,37 +188,37 @@ function compiler._addflags_from_target(self, flags, flagnames, target) end -- add the symbols flags from the current project - table.join2(flags, compiler._getflags(self, target:get("symbols"), { debug = "-g" - , hidden = "-fvisibility=hidden" - })) + table.join2(flags, compiler._getflags(self, target:get("symbols"), { debug = "-g" + , hidden = "-fvisibility=hidden" + })) -- add the warning flags from the current project - table.join2(flags, compiler._getflags(self, target:get("warnings"), { none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-Wall" - , error = "-Werror" - })) + table.join2(flags, compiler._getflags(self, target:get("warnings"), { none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-Wall" + , error = "-Werror" + })) -- add the optimize flags from the current project - table.join2(flags, compiler._getflags(self, target:get("optimize"), { none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Os" - , aggressive = "-Ofast" - })) + table.join2(flags, compiler._getflags(self, target:get("optimize"), { none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" + })) -- add the vector extensions flags from the current project - table.join2(flags, compiler._getflags(self, target:get("vectorexts"), { mmx = "-mmmx" - , sse = "-msse" - , sse2 = "-msse2" - , sse3 = "-msse3" - , ssse3 = "-mssse3" - , avx = "-mavx" - , avx2 = "-mavx2" - , neon = "-mfpu=neon" - })) + table.join2(flags, compiler._getflags(self, target:get("vectorexts"), { mmx = "-mmmx" + , sse = "-msse" + , sse2 = "-msse2" + , sse3 = "-msse3" + , ssse3 = "-mssse3" + , avx = "-mavx" + , avx2 = "-mavx2" + , neon = "-mfpu=neon" + })) -- add the language flags from the current project local languages = {} diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index eb93012b2..b4690c027 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -43,6 +43,109 @@ function task._directories() } end +-- translate menu +function task._translate_menu(menu) + + -- check + assert(menu) + + -- the interpreter + local interp = task._interpreter() + assert(interp) + + -- translate options + local options = menu.options + if options then + + -- make full options + local options_full = {} + for _, opt in ipairs(options) do + + -- this option is function? translate it + if type(opt) == "function" then + + -- call menu script in the sandbox + local ok, results = sandbox.load(opt) + if ok then + if results then + for _, opt in ipairs(results) do + table.insert(options_full, opt) + end + end + else + -- errors + os.raise("taskmenu: %s", results) + end + else + table.insert(options_full, opt) + end + end + + -- update the options + options = options_full + menu.options = options_full + + -- filter options + if interp:filter() then + + -- filter option + for _, opt in ipairs(options) do + + -- filter default + local default = opt[4] + if type(default) == "string" then + opt[4] = interp:filter():handle(default) + end + + -- filter description + for i = 5, 64 do + + -- the description, @note some option may be nil + local description = opt[i] + if not description then break end + + -- the description is string? + if type(description) == "string" then + opt[i] = interp:filter():handle(description) + + -- the description is function? wrap it for calling it in the sandbox + elseif type(description) == "function" then + opt[i] = function () + + -- call it in the sandbox + local ok, results = sandbox.load(description) + if not ok then + -- errors + os.raise("taskmenu: %s", results) + end + + -- ok + return results + end + end + end + end + end + + -- add common options + table.insert(options, 1, {'v', "verbose", "k", nil, "Print lots of verbose information." }) + table.insert(options, 2, {nil, "version", "k", nil, "Print the version number and exit." }) + table.insert(options, 3, {'h', "help", "k", nil, "Print this help message and exit." }) + table.insert(options, 4, {}) + table.insert(options, 5, {'f', "file", "kv", nil, "Read a given xmake.lua file." }) + table.insert(options, 6, {'P', "project", "kv", nil, "Change to the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" }) + table.insert(options, 7, {}) + + end + + -- ok + return menu +end + -- the interpreter function task._interpreter() @@ -323,10 +426,6 @@ function task.menu() local tasks = task.tasks() assert(tasks) - -- the interpreter - local interp = task._interpreter() - assert(interp) - -- make menu local menu = {} for taskname, taskinfo in pairs(tasks) do @@ -334,117 +433,40 @@ function task.menu() -- has menu? if taskinfo.menu then - -- translate options - local options = taskinfo.menu.options - if options then - - -- make full options - local options_full = {} - for _, opt in ipairs(options) do - - -- this option is function? translate it - if type(opt) == "function" then - - -- call menu script in the sandbox - local ok, results = sandbox.load(opt) - if ok then - if results then - for _, opt in ipairs(results) do - table.insert(options_full, opt) - end - end - else - -- errors - os.raise("taskmenu: %s", results) - end - else - table.insert(options_full, opt) - end - end - - -- update the options - options = options_full - taskinfo.menu.options = options_full - - -- filter options - if interp:filter() then - - -- filter option - for _, opt in ipairs(options) do - - -- filter default - local default = opt[4] - if type(default) == "string" then - opt[4] = interp:filter():handle(default) - end + -- main? + if taskinfo.category == "main" then - -- filter description - for i = 5, 64 do + -- delay to load main menu + menu.main = function () - -- the description, @note some option may be nil - local description = opt[i] - if not description then break end + -- translate main menu + local mainmenu = task._translate_menu(taskinfo.menu) - -- the description is string? - if type(description) == "string" then - opt[i] = interp:filter():handle(description) + -- make tasks for the main menu + mainmenu.tasks = {} + for name, info in pairs(tasks) do - -- the description is function? wrap it for calling it in the sandbox - elseif type(description) == "function" then - opt[i] = function () - - -- call it in the sandbox - local ok, results = sandbox.load(description) - if not ok then - -- errors - os.raise("taskmenu: %s", results) - end + -- has menu? + if info.menu then - -- ok - return results - end - end + -- add task + mainmenu.tasks[name] = + { + category = info.category + , shortname = info.menu.shortname + , description = info.menu.description + } end end - end - - -- add common options - table.insert(options, 1, {'v', "verbose", "k", nil, "Print lots of verbose information." }) - table.insert(options, 2, {nil, "version", "k", nil, "Print the version number and exit." }) - table.insert(options, 3, {'h', "help", "k", nil, "Print this help message and exit." }) - table.insert(options, 4, {}) - table.insert(options, 5, {'f', "file", "kv", nil, "Read a given xmake.lua file." }) - table.insert(options, 6, {'P', "project", "kv", nil, "Change to the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" }) - table.insert(options, 7, {}) + -- ok + return mainmenu + end end - -- main? - if taskinfo.category == "main" then - menu.main = taskinfo.menu - end - - -- add menu - menu[taskname] = taskinfo.menu - end - end - - -- add tasks to the main menu - if menu.main then - - -- make tasks for the main menu - menu.main.tasks = menu.main.tasks or {} - for taskname, taskinfo in pairs(tasks) do - - -- has menu? - if taskinfo.menu then - - -- add task - menu.main.tasks[taskname] = taskinfo + -- delay to load task menu + menu[taskname] = function () + return task._translate_menu(taskinfo.menu) end end end |
