summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-19 00:56:23 +0800
committerruki <[email protected]>2021-01-19 00:56:23 +0800
commitfbaadb6a0f41d29dd14afb3910e2ff9be3719e04 (patch)
tree714d8023390891e53a911af99b0b5793627cee8e
parentabd2bcb586035ac27358e7c6f31f446284ae36be (diff)
improve config
-rw-r--r--xmake/core/project/config.lua117
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua14
2 files changed, 30 insertions, 101 deletions
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index f27fc2857..78bdc2907 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -29,32 +29,6 @@ local table = require("base/table")
local utils = require("base/utils")
local option = require("base/option")
--- load the project configure
-function config._load(targetname)
-
- -- check
- targetname = targetname or "all"
-
- -- load configure from the file first
- local filepath = config.filepath()
- if os.isfile(filepath) then
-
- -- load it
- local results, errors = io.load(filepath)
- if not results then
- return nil, errors
- end
-
- -- load the target configure
- if results._TARGETS then
- return table.wrap(results._TARGETS[targetname])
- end
- end
-
- -- empty
- return {}
-end
-
-- get the current given configure
function config.get(name)
@@ -107,18 +81,15 @@ end
-- get all options
function config.options()
- -- check
- assert(config._CONFIGS)
-
-- remove values with "auto" and private item
local configs = {}
- for name, value in pairs(config._CONFIGS) do
- if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then
- configs[name] = value
+ if config._CONFIGS then
+ for name, value in pairs(config._CONFIGS) do
+ if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then
+ configs[name] = value
+ end
end
end
-
- -- get it
return configs
end
@@ -169,69 +140,31 @@ function config.directory()
return config._DIRECTORY
end
--- load the project configure
-function config.load(targetname)
-
- -- load configure
- local results, errors = config._load(targetname)
- if not results then
- utils.error(errors)
- return false
- end
-
- -- merge the target configure first
- local ok = false
- for name, value in pairs(results) do
- if config.get(name) == nil then
- config.set(name, value)
- ok = true
+-- load the project configuration
+function config.load()
+ local configs, errors
+ if os.isfile(config.filepath()) then
+ configs, errors = io.load(config.filepath())
+ if not configs then
+ utils.error(errors)
+ return false
end
end
-
- -- ok?
- return ok
+ config._CONFIGS = configs
+ return true
end
--- save the project configure
-function config.save(targetname)
-
- -- check
- targetname = targetname or "all"
-
- -- load the previous results from configure
- local results = {}
- local filepath = config.filepath()
- if os.isfile(filepath) then
- results = io.load(filepath) or {}
- end
-
- -- the targets
- local targets = results._TARGETS or {}
- results._TARGETS = targets
-
- -- clear target first
- targets[targetname] = {}
-
- -- update target
- local target = targets[targetname]
- for name, value in pairs(config.options()) do
- target[name] = value
- end
-
- -- add version
- results.__version = xmake._VERSION_SHORT
-
- -- save it
- return io.save(config.filepath(), results)
+-- save the project configuration
+function config.save()
+ return io.save(config.filepath(), config.options())
end
--- read value from the configure file directly
-function config.read(name, targetname)
-
- -- load configs
- local configs = config._load(targetname)
-
- -- get it
+-- read value from the configuration file directly
+function config.read(name)
+ local configs
+ if os.isfile(config.filepath()) then
+ configs = io.load(config.filepath())
+ end
local value = nil
if configs then
value = configs[name]
@@ -239,8 +172,6 @@ function config.read(name, targetname)
value = nil
end
end
-
- -- ok?
return value
end
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index 9b122c2e6..76647e313 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -87,23 +87,21 @@ function sandbox_core_project_config.readonly(name)
end
-- load the configuration
-function sandbox_core_project_config.load(targetname)
- return config.load(targetname)
+function sandbox_core_project_config.load()
+ return config.load()
end
-- save the configuration
-function sandbox_core_project_config.save(targetname)
-
- -- save it
- local ok, errors = config.save(targetname)
+function sandbox_core_project_config.save()
+ local ok, errors = config.save()
if not ok then
raise(errors)
end
end
-- read the value from the configuration file directly
-function sandbox_core_project_config.read(name, targetname)
- return config.read(name, targetname)
+function sandbox_core_project_config.read(name)
+ return config.read(name)
end
-- clear the configuration