diff options
| author | ruki <[email protected]> | 2016-05-31 15:49:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-05-31 15:49:37 +0800 |
| commit | 5769dba5932aad3a97c8db36c80a15064b71f556 (patch) | |
| tree | cd08ffc12af5dc735fd1714adcaa2657e4b0f730 | |
| parent | 2258b6be79c6b07a197ca27f79c89baaf8fd3779 (diff) | |
add history
| -rw-r--r-- | xmake/core/base/option.lua | 22 | ||||
| -rw-r--r-- | xmake/core/main.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/cache.lua | 5 | ||||
| -rw-r--r-- | xmake/core/project/history.lua | 64 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 15 | ||||
| -rw-r--r-- | xmake/core/project/template.lua | 13 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/config.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/history.lua | 43 |
8 files changed, 155 insertions, 20 deletions
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 5e1ee1adf..eb9af790e 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -119,11 +119,28 @@ function option.restore() end end +-- the command line +function option.cmdline() + + -- make command + local line = "xmake" + local argv = xmake._ARGV + for _, arg in ipairs(argv) do + if arg:find("%s") then + arg = "\"" .. arg .. "\"" + end + line = line .. " " .. arg + end + + -- ok? + return line +end + -- init the option -function option.init(argv, menu) +function option.init(menu) -- check - assert(argv and menu) + assert(menu) -- translate menu option._translate(menu) @@ -137,6 +154,7 @@ function option.init(argv, menu) assert(context) -- parse _ARGV + local argv = xmake._ARGV local _iter, _s, _k = ipairs(argv) while true do diff --git a/xmake/core/main.lua b/xmake/core/main.lua index b2177db57..4abb59c67 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -31,6 +31,7 @@ local option = require("base/option") local profiler = require("base/profiler") local deprecated = require("base/deprecated") local task = require("project/task") +local history = require("project/history") -- init the option menu local menu = @@ -108,10 +109,13 @@ function main.done() main._init() -- init option - if not option.init(xmake._ARGV, menu) then + if not option.init(menu) then return -1 end + -- save command lines to history + history.save("cmdlines", option.cmdline()) + -- run help? if main._help() then return 1 diff --git a/xmake/core/project/cache.lua b/xmake/core/project/cache.lua index 5ea212dfc..1a81ee4dc 100644 --- a/xmake/core/project/cache.lua +++ b/xmake/core/project/cache.lua @@ -54,6 +54,11 @@ function cache._instance(scopename) -- init instance local instance = table.inherit(cache) + -- check scopename + if not scopename:find("local%.") and not scopename:find("global%.") then + os.raise("invalid cache scope: %s", scopename) + end + -- make the cache path local cachepath = (scopename:gsub("%.", "/")) cachepath = (cachepath:gsub("^local%/", path.join(config.directory(), "cache") .. "/")) diff --git a/xmake/core/project/history.lua b/xmake/core/project/history.lua new file mode 100644 index 000000000..8e44d459b --- /dev/null +++ b/xmake/core/project/history.lua @@ -0,0 +1,64 @@ +--!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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file history.lua +-- + +-- define module: history +local history = history or {} + +-- load modules +local os = require("base/os") +local io = require("base/io") +local table = require("base/table") +local utils = require("base/utils") +local string = require("base/string") +local cache = require("project/cache")("local.history") + +-- save history +function history.save(key, value) + + -- check + assert(key and value ~= nil) + + -- load history values first + local values = history.load(key) or {} + + -- remove the oldest value if be full + if #values > 64 then + table.remove(values, 1) + end + + -- append this value + table.insert(values, value) + + -- save history + cache:set(key, values) + cache:flush() +end + +-- load history +function history.load(key) + + -- load it + return cache:get(key) +end + +-- return module: history +return history diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 9d10717f3..5d2effef8 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -327,7 +327,7 @@ function project._interpreter() assert(interp) -- set root directory - interp:rootdir_set(xmake._PROJECT_DIR) + interp:rootdir_set(project.directory()) -- set root scope interp:rootscope_set("target") @@ -495,7 +495,7 @@ function project._interpreter() , curdir = os.curdir() , globaldir = global.directory() , configdir = config.directory() - , projectdir = xmake._PROJECT_DIR + , projectdir = project.directory() , packagedir = package.directory() } @@ -514,11 +514,18 @@ function project._interpreter() return interp end +-- get the project directory +function project.directory() + + -- get it + return xmake._PROJECT_DIR +end + -- check the project function project.check() -- enter the project directory - local ok, errors = os.cd(xmake._PROJECT_DIR) + local ok, errors = os.cd(project.directory()) if not ok then return false, errors end @@ -602,7 +609,7 @@ function project.load() assert(interp) -- enter the project directory - local ok, errors = os.cd(xmake._PROJECT_DIR) + local ok, errors = os.cd(project.directory()) if not ok then return false, errors end diff --git a/xmake/core/project/template.lua b/xmake/core/project/template.lua index 6e7b617bf..11f38cb77 100644 --- a/xmake/core/project/template.lua +++ b/xmake/core/project/template.lua @@ -32,6 +32,7 @@ local utils = require("base/utils") local string = require("base/string") local filter = require("base/filter") local sandbox = require("sandbox/sandbox") +local project = require("project/project") local interpreter = require("base/interpreter") -- the interpreter @@ -176,7 +177,7 @@ function template.create(language, templateid, targetname) local maps = { targetname = targetname - , projectdir = xmake._PROJECT_DIR + , projectdir = project.directory() , packagesdir = xmake._PACKAGES_DIR } @@ -213,19 +214,19 @@ function template.create(language, templateid, targetname) -- ensure the project directory - if not os.isdir(xmake._PROJECT_DIR) then - os.mkdir(xmake._PROJECT_DIR) + if not os.isdir(project.directory()) then + os.mkdir(project.directory()) end -- copy the project files - local ok, errors = os.cp(path.join(module.projectdir, "*"), xmake._PROJECT_DIR) + local ok, errors = os.cp(path.join(module.projectdir, "*"), project.directory()) if not ok then return false, errors end -- enter the project directory - if not os.cd(xmake._PROJECT_DIR) then - return false, string.format("can not enter %s!", xmake._PROJECT_DIR) + if not os.cd(project.directory()) then + return false, string.format("can not enter %s!", project.directory()) end -- replace macros diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 9e54b2428..99f48ace0 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -36,13 +36,6 @@ function sandbox_core_project_config.buildir() return config.get("buildir") end --- get the project directory -function sandbox_core_project_config.projectdir() - - -- get it - return xmake._PROJECT_DIR -end - -- get the current platform function sandbox_core_project_config.plat() diff --git a/xmake/core/sandbox/modules/import/core/project/history.lua b/xmake/core/sandbox/modules/import/core/project/history.lua new file mode 100644 index 000000000..fd10a22e7 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/project/history.lua @@ -0,0 +1,43 @@ +--!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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file history.lua +-- + +-- define module +local sandbox_core_project_history = sandbox_core_project_history or {} + +-- load modules +local os = require("base/os") +local io = require("base/io") +local table = require("base/table") +local option = require("base/option") +local string = require("base/string") +local history = require("project/history") +local raise = require("sandbox/modules/raise") + +-- load the history data +function sandbox_core_project_history.load(key) + + -- load it + return history.load(key) +end + +-- return module +return sandbox_core_project_history |
