diff options
| author | ruki <[email protected]> | 2016-02-23 09:25:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-23 09:25:13 +0800 |
| commit | c4bf7b21d9789dba232369ecfe36052acfebf54e (patch) | |
| tree | 388f9249aa44ff16ace68798c2741bd05378b28e | |
| parent | 0b720a8418cf5a52e658cc3069fed435f1fc4a4f (diff) | |
add task
| -rw-r--r-- | xmake/core/base/platform.lua | 9 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 88 | ||||
| -rw-r--r-- | xmake/core/base/template.lua | 2 | ||||
| -rwxr-xr-x | xmake/core/tasks/config.lua | 124 | ||||
| -rwxr-xr-x | xmake/core/tasks/lua.lua | 43 |
5 files changed, 260 insertions, 6 deletions
diff --git a/xmake/core/base/platform.lua b/xmake/core/base/platform.lua index d3dd92903..cfc6641bc 100644 --- a/xmake/core/base/platform.lua +++ b/xmake/core/base/platform.lua @@ -30,10 +30,9 @@ local utils = require("base/utils") local config = require("base/config") local global = require("base/global") --- load platform directories -function platform._load_directories() +-- the directories of platforms +function platform._directories() - -- load platform directories return { path.join(global.directory(), "platforms") , path.join(xmake._CORE_DIR, "platforms") } @@ -104,7 +103,7 @@ function platform._load(plat) if module then return module end -- load module - local dirs = platform._load_directories() + local dirs = platform._directories() for _, dir in ipairs(dirs) do module = platform._load_from(dir, plat) @@ -262,7 +261,7 @@ function platform.plats() -- make list local list = {} - local dirs = platform._load_directories() + local dirs = platform._directories() for _, dir in ipairs(dirs) do -- get the platform list diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua new file mode 100644 index 000000000..d520e9a68 --- /dev/null +++ b/xmake/core/base/task.lua @@ -0,0 +1,88 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file task.lua +-- + +-- define module: task +local task = task or {} + +-- load modules +local table = require("base/table") +local utils = require("base/utils") +local string = require("base/string") +local global = require("base/global") +local interpreter = require("base/interpreter") + +-- the directories of tasks +function task._directories() + + return { path.join(global.directory(), "plugins") + , path.join(xmake._PROGRAM_DIR, "plugins") + , path.join(xmake._CORE_DIR, "tasks") + } +end + +-- the interpreter +function task._interpreter() + + -- the interpreter has been initialized? return it directly + if task._INTERPRETER then + return task._INTERPRETER + end + + -- init interpreter + local interp = interpreter.init() + assert(interp) + + -- register api: task() + interp:api_register_scope("task") + + -- register api: set_task_menu() + interp:api_register_set_values("task", "task", "menu") + + -- save interpreter + task._INTERPRETER = interp + + -- ok? + return interp +end + +-- load the given task from the given directory +function task._load_from(dir, taskname) + + -- the file path + local filepath = path.join(dir, taskname .. ".lua") + + -- get interpreter + local interp = task._interpreter() + assert(interp) + + -- load task + local results, errors = interp:load(filepath, nil, true, true) + if not results then + -- trace + utils.error(errors) + utils.abort() + end +end + + +-- return module: task +return task diff --git a/xmake/core/base/template.lua b/xmake/core/base/template.lua index 8e739a3fe..185a1a5cd 100644 --- a/xmake/core/base/template.lua +++ b/xmake/core/base/template.lua @@ -34,7 +34,7 @@ local filter = require("base/filter") local sandbox = require("base/sandbox") local interpreter = require("base/interpreter") --- get interpreter +-- the interpreter function template._interpreter() -- the interpreter has been initialized? return it directly diff --git a/xmake/core/tasks/config.lua b/xmake/core/tasks/config.lua new file mode 100755 index 000000000..09f5d9ef1 --- /dev/null +++ b/xmake/core/tasks/config.lua @@ -0,0 +1,124 @@ +-- define task +task("config") + + -- set menu + set_task_menu({ + -- xmake f + shortname = 'f' + + -- usage + , usage = "xmake config|f [options] [target]" + + -- description + , description = "Configure the project." + + -- options + , options = + { + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + + , {} +--[[ , {'p', "plat", "kv", xmake._HOST, "Compile for the given platform." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat + end + end + return descriptions + end } + , {'a', "arch", "kv", "auto", "Compile for the given architecture." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat .. ":" + local archs = platform.archs(plat) + if archs then + for _, arch in ipairs(archs) do + descriptions[i] = descriptions[i] .. " " .. arch + end + end + end + end + return descriptions + end }]] + , {'m', "mode", "kv", "release", "Compile for the given mode." + , " - debug" + , " - release" + , " - profile" } + , {'k', "kind", "kv", "static", "Compile for the given target kind." + , " - static" + , " - shared" + , " - binary" } +-- , {nil, "host", "kv", xmake._HOST, "The current host environment." } + + -- the options for project +-- , function () return project.menu() end + + , {} + , {nil, "make", "kv", "auto", "Set the make path." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } + + , {} + , {nil, "cross", "kv", nil, "The cross toolchains prefix" + , ".e.g" + , " - i386-mingw32-" + , " - arm-linux-androideabi-" } + , {nil, "toolchains", "kv", nil, "The cross toolchains directory" } + + , {} + , {nil, "cc", "kv", nil, "The C Compiler" } + , {nil, "cxx", "kv", nil, "The C++ Compiler" } + , {nil, "cflags", "kv", nil, "The C Compiler Flags" } + , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } + , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } + + , {} + , {nil, "as", "kv", nil, "The Assembler" } + , {nil, "asflags", "kv", nil, "The Assembler Flags" } + + , {} + , {nil, "sc", "kv", nil, "The Swift Compiler" } + , {nil, "scflags", "kv", nil, "The Swift Compiler Flags" } + + , {} + , {nil, "ld", "kv", nil, "The Linker" } + , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } + + , {} + , {nil, "ar", "kv", nil, "The Static Library Linker" } + , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } + + , {} + , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } + + -- the options for all platforms +-- , function () return platform.menu("config") end + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {'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" } + , {'o', "buildir", "kv", "build", "Set the build directory." } + + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "target", "v", "all", "Configure for the given target." } + } + }) + + + diff --git a/xmake/core/tasks/lua.lua b/xmake/core/tasks/lua.lua new file mode 100755 index 000000000..be5bea0d0 --- /dev/null +++ b/xmake/core/tasks/lua.lua @@ -0,0 +1,43 @@ +-- define task +task("lua") + + -- set menu + set_task_menu({ + -- xmake l + shortname = 'l' + + -- usage + , usage = "xmake lua|l [options] [script] [arguments]" + + -- description + , description = "Run the lua script." + + -- options + , options = + { + {'f', "file", "kv", nil, "Read a given xmake.lua file." } + , {'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" } + + , {} + , {'s', "string", "k", nil, "Run the lua string script." } + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "script", "v", nil, "Run the given lua script." + , " - The script name from the xmake tool directory" + , " - The script file" + , " - The script string" } + , {nil, "arguments", "vs", nil, "The script arguments" } + } + }) + + + |
