summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-16 12:09:34 +0800
committerruki <[email protected]>2015-05-16 12:09:34 +0800
commit05c2b5a567c1e2174ae136e18ca254d98a6b257c (patch)
treeca197db72dffb009ed457b65c046ef5ff7927360
parent9eb348a32a7472d533b9084d3b53491078987149 (diff)
reimpl project configure
-rw-r--r--tests/console/xmake.xproj6
-rw-r--r--xmake/scripts/base/config.lua12
-rw-r--r--xmake/scripts/base/project.lua220
3 files changed, 47 insertions, 191 deletions
diff --git a/tests/console/xmake.xproj b/tests/console/xmake.xproj
index 4fa71797e..7af84782a 100644
--- a/tests/console/xmake.xproj
+++ b/tests/console/xmake.xproj
@@ -63,17 +63,17 @@ project: console
mxflags: -DHELLO3
ldflags: -lhello3, -L$(buildir)/lib
- plarforms: linux
+ platforms: linux
{
defines: PLAT="linux"
}
- plarforms: windows
+ platforms: windows
{
defines: PLAT=windows
}
- plarforms: macosx, ios
+ platforms: macosx, ios
{
ldflags: -framework Cocoa, "-framework IOKit"
, -framework UIKit
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index 26272fcf9..cb169550e 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -24,9 +24,10 @@
local config = config or {}
-- load modules
-local io = require("base/io")
-local utils = require("base/utils")
-local option = require("base/option")
+local io = require("base/io")
+local utils = require("base/utils")
+local option = require("base/option")
+local preprocessor = require("base/preprocessor")
-- auto configs
function config._auto(name)
@@ -220,7 +221,7 @@ function config.loadxconf()
end
end
- -- load and execute the xmake.xproj
+ -- load and execute the xmake.xconf
local path = options.project .. "/xmake.xconf"
local configs, errors = preprocessor.loadfile(path, "config", configures, {"target"})
@@ -293,9 +294,6 @@ function config.loadxconf()
end
end
end
-
- -- ok
- return nil
end
-- dump configs
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index a14b1a8ed..a85941b78 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -20,28 +20,13 @@
-- @file project.lua
--
--- load modules
-local utils = require("base/utils")
-local config = require("base/config")
-
--- enter project
-local _PROJECT = _PROJECT or {}
-local _MAINENV = getfenv()
-setmetatable(_PROJECT, {__index = _G})
-setfenv(1, _PROJECT)
-
--- init the current scope
-local current = nil
-
--- configure scope end
-function _end()
+-- define module: config
+local project = project or {}
- -- check
- assert(current)
-
- -- leave the current scope
- current = current._PARENT
-end
+-- load modules
+local utils = require("base/utils")
+local config = require("base/config")
+local preprocessor = require("base/preprocessor")
-- preprocess value
function _preprocess(value)
@@ -65,183 +50,56 @@ function _preprocess(value)
return value
end
--- register configures
-function _register(names)
-
- -- check
- assert(_PROJECT)
- assert(names and type(names) == "table")
-
- -- register all configures
- for _, name in ipairs(names) do
-
- -- register the configure
- _PROJECT[name] = _PROJECT[name] or function(...)
-
- -- check
- assert(current)
-
- -- init ldflags
- current[name] = current[name] or {}
-
- -- get arguments
- local arg = arg or {...}
- if table.getn(arg) == 0 then
- -- no argument
- current[name] = nil
- elseif table.getn(arg) == 1 then
- -- save only one argument
- current[name] = _preprocess(arg[1])
- else
- -- save all arguments
- for i, v in ipairs(arg) do
- current[name][i] = _preprocess(v)
- end
- end
- end
- end
-end
-
--- init project
-function _init()
-
- -- register all configures
- _register { "kind"
- , "deps"
- , "files"
- , "links"
- , "mflags"
- , "headers"
- , "headerdir"
- , "targetdir"
- , "objectdir"
- , "linkdirs"
- , "includedirs"
- , "cflags"
- , "cxxflags"
- , "ldflags"
- , "mxflags"
- , "defines"}
-end
-
--- configure platforms
-function plarforms(...)
-
- -- check
- assert(current)
-
- -- init platforms
- current._PLATFORMS = current._PLATFORMS or {}
-
- -- init scope
- local scope = {}
-
- -- configure all platforms
- local arg = arg or {...}
- for _, name in ipairs(arg) do
-
- -- check
- if current._PLATFORMS[name] then
- -- error
- utils.error("the platform: %s has been defined repeatly!", name)
- assert(false)
- end
-
- -- init the platform scope
- current._PLATFORMS[name] = scope
-
- end
-
- -- enter scope
- local parent = current
- current = scope
- current._PARENT = parent
-end
-
--- configure target
-function target(name)
-
- -- check
- assert(name and current)
-
- -- init targets
- current._TARGETS = current._TARGETS or {}
-
- -- init target scope
- current._TARGETS[name] = {}
-
- -- enter target scope
- local parent = current
- current = current._TARGETS[name]
- current._PARENT = parent
-end
-
--- configure project
-function project(name)
-
- -- check
- assert(name)
-
- -- init the root scope, must be only one project
- if not _CONFIGS then
- _CONFIGS = {}
- else
- -- error
- utils.error("the project: %s is redundant!", name)
- return
- end
-
- -- init the project name
- _CONFIGS.name = name
-
- -- init the current scope
- current = _CONFIGS
- current._PARENT = nil
-
-end
-
-- load xproj
-function loadxproj(file)
+function project.loadxproj(file)
-- check
assert(file)
- -- load and execute the xmake.xproj
- local script = preprocessor.loadx(file)
- if script then
-
- -- init the project envirnoment
- _PROJECT._init()
- setfenv(script, _PROJECT)
+ -- init configures
+ local configures = { "kind"
+ , "deps"
+ , "files"
+ , "links"
+ , "mflags"
+ , "headers"
+ , "headerdir"
+ , "targetdir"
+ , "objectdir"
+ , "linkdirs"
+ , "includedirs"
+ , "cflags"
+ , "cxxflags"
+ , "ldflags"
+ , "mxflags"
+ , "defines"}
- -- execute it
- local ok, err = pcall(script)
- if not ok then
- -- error
- return err
- end
+ -- load and execute the xmake.xproj
+ local configs, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms"})
+ if configs then
+ -- ok
+ project._CONFIGS = configs
+ elseif errors then
+ -- error
+ return errors
else
-- error
return string.format("load %s failed!", file)
end
-
- -- ok
- return nil
end
--- dump all configures
-function dump()
-
+-- dump configs
+function project.dump()
+
-- check
- assert(_CONFIGS)
+ assert(project._CONFIGS)
-- dump
if xmake._OPTIONS.verbose then
- utils.dump(_CONFIGS, "_PARENT")
+ utils.dump(project._CONFIGS, "_PARENT")
end
end
--- leave project
-setfenv(1, _MAINENV)
-return _PROJECT
+-- return module: project
+return project