summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-09 09:34:34 +0800
committerruki <[email protected]>2015-06-09 09:34:34 +0800
commit387b3666c4d952e01b96bce7e9bc51ed86fe986f (patch)
tree22f84c87354ecf8bc5c9bb2be3d21a207dba1667
parent723ec3e970e17f48a601fe2a919b9802b5e516fa (diff)
update the configure format
-rwxr-xr-xcore/project.mak2
-rw-r--r--tests/console/.xmake.xconf23
-rw-r--r--xmake/scripts/action/_build.lua2
-rw-r--r--xmake/scripts/action/_config.lua2
-rw-r--r--xmake/scripts/base/config.lua154
-rw-r--r--xmake/scripts/base/io.lua74
-rw-r--r--xmake/scripts/base/main.lua2
7 files changed, 85 insertions, 174 deletions
diff --git a/core/project.mak b/core/project.mak
index a909da33c..f25529731 100755
--- a/core/project.mak
+++ b/core/project.mak
@@ -10,7 +10,7 @@ PRO_VERSION_MAJOR = 1
PRO_VERSION_MINOR = 0
# the project alter version
-PRO_VERSION_ALTER = 1
+PRO_VERSION_ALTER = 2
# the project prefix
PRO_PREFIX = XM_
diff --git a/tests/console/.xmake.xconf b/tests/console/.xmake.xconf
deleted file mode 100644
index 0a855eee1..000000000
--- a/tests/console/.xmake.xconf
+++ /dev/null
@@ -1,23 +0,0 @@
-config:
-{
- __vsenv_devenvdir: "C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE"
- __vsenv_vsinstalldir: "C:\\Program Files\\Microsoft Visual Studio 9.0"
- plat: "windows"
- entitlements: "auto"
- buildir: "build"
- codesign: "auto"
- arch: "x86"
- __vsenv_libpath: "C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5;C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\ATLMFC\\LIB;C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\LIB;"
- __vsenv_include: "C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\ATLMFC\\INCLUDE;C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE;C:\\Program Files\\\\Microsoft SDKs\\Windows\\v6.0A\\include;"
- __vsenv_vcinstalldir: "C:\\Program Files\\Microsoft Visual Studio 9.0\\VC"
- __vsenv_path: "C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE;C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\BIN;C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\Tools;C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5;C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\VCPackages;C:\\Program Files\\\\Microsoft SDKs\\Windows\\v6.0A\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\Bitvise SSH Client;C:\\Program Files\\Kingsoft\\WPSOffice\\9.1.0.4993\\office6;C:\\Program Files\\xmake"
- __vsenv_lib: "C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\ATLMFC\\LIB;C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\LIB;C:\\Program Files\\\\Microsoft SDKs\\Windows\\v6.0A\\lib;"
- host: "windows"
- ndk_sdkver: "auto"
- xcode_sdkver: "auto"
- xcode_dir: "auto"
- packages: "pkg"
- vs: "2008"
- mode: "release"
- mobileprovision: "auto"
-}
diff --git a/xmake/scripts/action/_build.lua b/xmake/scripts/action/_build.lua
index cf5c1ea93..c644c223a 100644
--- a/xmake/scripts/action/_build.lua
+++ b/xmake/scripts/action/_build.lua
@@ -64,7 +64,7 @@ function _build.done()
config.set("__rebuild", nil)
-- save the configure
- if not config.savexconf() then
+ if not config.save() then
-- error
utils.error("update configure failed!")
end
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index 7726be958..2c1046ecf 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -40,7 +40,7 @@ function _config.done()
config.dump()
-- save the configure
- if not config.savexconf() then
+ if not config.save() then
-- error
utils.error("save configure failed!")
return false
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index a4cc7f3f2..f8fb8afca 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -29,102 +29,6 @@ local os = require("base/os")
local utils = require("base/utils")
local option = require("base/option")
local global = require("base/global")
-local preprocessor = require("base/preprocessor")
-
--- save object with the level
-function config._save_with_level(file, object, level)
-
- -- check
- assert(object)
-
- -- save string
- if type(object) == "string" then
- file:write(string.format("%q", object))
- -- save boolean
- elseif type(object) == "boolean" then
- file:write(tostring(object))
- -- save number
- elseif type(object) == "number" then
- file:write(object)
- -- save table
- elseif type(object) == "table" then
-
- -- save head
- file:write(utils.ifelse(level == 0, "config:\n", "\n"))
- for l = 1, level do
- file:write(" ")
- end
- file:write("{\n")
-
- -- save body
- for k, v in pairs(object) do
-
- -- save _TARGET
- if type(k) == "string" and k == "_TARGET" then
-
- for _k, _v in pairs(v) do
-
- -- save spaces
- for l = 0, level do
- file:write(" ")
- end
-
- -- save key
- file:write("target: ", _k)
-
- -- save value
- if not config._save_with_level(file, _v, level + 1) then
- return false
- end
-
- -- save newline
- file:write("\n")
- end
-
- -- exclude _PARENT
- elseif type(k) ~= "string" or k ~= "_PARENT" then
-
- -- save spaces
- for l = 0, level do
- file:write(" ")
- end
-
- -- save key
- if type(k) == "string" then
- file:write(k, ": ")
- end
-
- -- save value
- if not config._save_with_level(file, v, level + 1) then
- return false
- end
-
- -- save newline
- file:write("\n")
- end
- end
-
- -- save tail
- for l = 1, level do
- file:write(" ")
- end
- file:write("}\n")
- else
- -- error
- utils.error("invalid object type: %s", type(object))
- return false
- end
-
- -- ok
- return true
-end
-
--- save object
-function config._save(file, object)
-
- -- save it
- return config._save_with_level(file, object, 0)
-end
-- make configure for the current target
function config._make()
@@ -174,7 +78,7 @@ end
function config._file()
-- get it
- return config.directory() .. "/xmake.xconf"
+ return config.directory() .. "/xmake.conf"
end
-- need configure?
@@ -259,39 +163,18 @@ function config.directory()
return dir
end
--- save xmake.xconf
-function config.savexconf()
+-- save xmake.conf
+function config.save()
-- the configs
local configs = config._CONFIGS
assert(configs)
- -- open the configure file
- local path = config._file()
- local file = io.open(path, "w")
- if not file then
- -- error
- utils.error("open %s failed!", path)
- return false
- end
-
- -- save configs to file
- if not config._save(file, configs) then
- -- error
- utils.error("save %s failed!", path)
- file:close()
- return false
- end
-
- -- close file
- file:close()
-
- -- ok
- return true
+ -- save to the configure file
+ return io.save(config._file(), configs)
end
-
--- load xmake.xconf
-function config.loadxconf()
+
+function config.load()
-- the options
local options = xmake._OPTIONS
@@ -301,30 +184,21 @@ function config.loadxconf()
assert(option._MENU)
assert(option._MENU.config)
- -- get all configure names
- local i = 1
- local configures = {}
- for _, o in ipairs(option._MENU.config.options) do
- local name = o[2]
- if config._need(name) then
- configures[i] = name
- i = i + 1
- end
- end
-
-- does not clean the cached configure?
if not options.clean then
-- load and execute the xmake.xconf
- local path = config._file()
- if os.isfile(path) then
- local newenv, errors = preprocessor.loadfile(path, "config", configures, {"target"})
+ local filepath = config._file()
+ if os.isfile(filepath) then
+
+ -- load the configure file
+ local configs, errors = io.load(filepath)
-- exists local configures?
- if newenv then
+ if configs then
-- save configs
- config._CONFIGS = newenv._CONFIGS
+ config._CONFIGS = configs
-- clear configs and mark as "rebuild" and "reconfig" if the host has been changed
local target = config._target()
diff --git a/xmake/scripts/base/io.lua b/xmake/scripts/base/io.lua
index a1ac152ce..4a5a3b65a 100644
--- a/xmake/scripts/base/io.lua
+++ b/xmake/scripts/base/io.lua
@@ -88,18 +88,78 @@ function io._save_with_level(file, object, level)
return true
end
--- save object
-function io.save(file, object, prefix)
+-- save object to given file
+function io._save(file, object)
- -- save prefix
- if prefix and type(prefix) == "string" then
- file:write(prefix)
- end
-
-- save it
return io._save_with_level(file, object, 0)
end
+-- save object the the given filepath
+function io.save(filepath, object)
+
+ -- open the file
+ local file = io.open(filepath, "w")
+ if not file then
+ -- error
+ return false, string.format("open %s failed!", filepath)
+ end
+
+ -- save object to file
+ if not io._save(file, object) then
+ -- error
+ file:close()
+ return false, string.format("save %s failed!", filepath)
+ end
+
+ -- close file
+ file:close()
+
+ -- ok
+ return true
+end
+
+-- load object from the given file
+function io.load(filepath)
+
+ -- open the file
+ local file = io.open(filepath, "r")
+ if not file then
+ -- error
+ return nil, string.format("open %s failed!", filepath)
+ end
+
+ -- load data
+ local result = nil
+ local errors = nil
+ local data = file:read("*all")
+ if data and type(data) == "string" then
+
+ -- load script
+ local script = loadstring("return " .. data)
+ if script then
+
+ -- load object
+ local ok, object = pcall(script)
+ if ok and object then
+ result = object
+ elseif object then
+ -- error
+ errors = object
+ else
+ -- error
+ errors = string.format("load %s failed!", filepath)
+ end
+ end
+ end
+
+ -- close file
+ file:close()
+
+ -- ok?
+ return result, errors
+end
+
-- cat the given file
function io.cat(filepath)
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 962f1b873..7f8087180 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -466,7 +466,7 @@ function main._prepare_project()
end
-- load xmake.xconf file first
- local errors = config.loadxconf()
+ local errors = config.load()
if errors then return errors end
-- xmake config or marked as "reconfig"?