summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-13 16:27:02 +0800
committerruki <[email protected]>2016-04-13 16:27:02 +0800
commit3126beb37ff78520bdb23bb9c0548b9c6a80cf22 (patch)
tree2fbe08cd057fb57f4c941adfca6e2d8abd78fad1
parent097a0d5eb612d898fb8de01d6db7760aed947b4b (diff)
impl inherit
-rw-r--r--xmake/core/base/table.lua2
-rw-r--r--xmake/core/sandbox/modules/import.lua60
-rw-r--r--xmake/core/sandbox/modules/inherit.lua39
-rwxr-xr-xxmake/tools/compiler/clang++.lua33
-rwxr-xr-xxmake/tools/compiler/clang.lua110
-rwxr-xr-xxmake/tools/compiler/g++.lua33
-rwxr-xr-xxmake/tools/compiler/gcc.lua11
7 files changed, 169 insertions, 119 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 7427f3a53..746947bd9 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -345,7 +345,7 @@ function table.inherit2(self, clasz)
-- init instance
for k, v in pairs(clasz) do
- if type(v) == "function" then
+ if type(v) == "function" and self[k] == nil then
self[k] = v
end
end
diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua
index 2a01f7282..4338ec221 100644
--- a/xmake/core/sandbox/modules/import.lua
+++ b/xmake/core/sandbox/modules/import.lua
@@ -70,7 +70,7 @@ function sandbox_import._loadfile(filepath, instance)
end
-- import module
- return instance:import()
+ return instance:import(), instance:script()
end
-- load module without sandbox
@@ -80,7 +80,7 @@ function sandbox_import._loadfile(filepath, instance)
end
-- ok?
- return result
+ return result, script
end
-- find module
@@ -125,6 +125,7 @@ function sandbox_import._load(dir, name, instance)
-- load the single module?
local module = nil
+ local script = nil
if os.isfile(path.join(dir, name .. ".lua")) then
-- load module
@@ -136,6 +137,9 @@ function sandbox_import._load(dir, name, instance)
-- save module
module = result
+ -- save script
+ script = errors
+
-- load modules
elseif os.isdir(path.join(dir, name)) then
@@ -160,6 +164,9 @@ function sandbox_import._load(dir, name, instance)
-- init the root module
module = module or {}
+ -- save script
+ script = errors
+
-- save module
local scope = module
for _, modulename in ipairs(path.split(modulepath)) do
@@ -193,7 +200,7 @@ function sandbox_import._load(dir, name, instance)
end
-- return it
- return module
+ return module, script
end
-- import module
@@ -214,6 +221,11 @@ end
-- => core
-- => core.platform
--
+-- import("core.platform", {inherit = true})
+-- => inherit the all interfaces of core.platform to the current scope
+--
+-- @note the polymiorphism is not supported for import.inherit mode now.
+--
function sandbox_import.import(name, args)
-- check
@@ -246,6 +258,9 @@ function sandbox_import.import(name, args)
raise("cannot import module: %s, %s", name, errors)
end
+ -- get module script
+ local script = errors
+
-- get module name
local modulename = sandbox_import._modulename(name)
if not modulename then
@@ -256,13 +271,48 @@ function sandbox_import.import(name, args)
local scope_parent = getfenv(2)
assert(scope_parent)
+ -- the imported name
+ local imported_name = args.alias or modulename
+
+ -- inherit?
+ if args.inherit then
+
+ -- inherit this module into the parent scope
+ table.inherit2(scope_parent, module)
+
+ -- import as super module
+ imported_name = "_super"
+
+ -- public the script scope for the super module
+ --
+ -- we can access the all scope members of _super in the child module
+ --
+ -- .e.g
+ --
+ -- import("core.platform.xxx", {inherit = true})
+ --
+ -- print(_super._g)
+ --
+ if script ~= nil then
+ setmetatable(module, { __index = function (tbl, key)
+ local val = rawget(tbl, key)
+ if val == nil then
+ val = rawget(getfenv(script), key)
+ end
+ return val
+ end})
+
+ end
+
+ end
+
-- this module has been imported?
- if rawget(scope_parent, modulename) then
+ if rawget(scope_parent, imported_name) then
raise("this module: %s has been imported!", name)
end
-- import this module into the parent scope
- scope_parent[args.alias or modulename] = module
+ scope_parent[imported_name] = module
-- return it
return module
diff --git a/xmake/core/sandbox/modules/inherit.lua b/xmake/core/sandbox/modules/inherit.lua
new file mode 100644
index 000000000..7a7f95370
--- /dev/null
+++ b/xmake/core/sandbox/modules/inherit.lua
@@ -0,0 +1,39 @@
+--!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 inherit.lua
+--
+
+-- load modules
+local import = require("sandbox/modules/import")
+
+-- inherit module
+--
+-- we can access all super interfaces by _super
+--
+-- @note the polymiorphism is not supported for import.inherit mode now.
+function sandbox_inherit(name)
+
+ -- import and inherit it
+ return import(name, {inherit = true})
+end
+
+-- load module
+return sandbox_inherit
+
diff --git a/xmake/tools/compiler/clang++.lua b/xmake/tools/compiler/clang++.lua
new file mode 100755
index 000000000..6b2feaa2f
--- /dev/null
+++ b/xmake/tools/compiler/clang++.lua
@@ -0,0 +1,33 @@
+--!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 clang++.lua
+--
+
+-- inherit clang
+inherit("clang")
+
+-- init it
+function init(shellname)
+
+ -- init super
+ _super.init(shellname or "clang++")
+
+end
+
diff --git a/xmake/tools/compiler/clang.lua b/xmake/tools/compiler/clang.lua
index 90dd4150b..253e14270 100755
--- a/xmake/tools/compiler/clang.lua
+++ b/xmake/tools/compiler/clang.lua
@@ -20,113 +20,19 @@
-- @file clang.lua
--
+-- inherit gcc
+inherit("gcc")
+
-- init it
function init(shellname)
- -- save the shell name
- _g.shellname = shellname or "clang"
-
- -- init mxflags
- _g.mxflags = { "-fmessage-length=0"
- , "-pipe"
- , "-fpascal-strings"
- , "\"-DIBOutlet=__attribute__((iboutlet))\""
- , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\""
- , "\"-DIBAction=void)__attribute__((ibaction)\""}
-
- -- init shflags
- _g.shflags = { "-dynamiclib", "-fPIC" }
+ -- init super
+ _super.init(shellname or "clang")
-- suppress warning
- _g.cxflags = {"-Qunused-arguments"}
- _g.mxflags = {"-Qunused-arguments"}
- _g.asflags = {"-Qunused-arguments"}
-
- -- init cxflags for the kind: shared
- _g.shared = {}
- _g.shared.cxflags = {"-fPIC"}
-
- -- init flags map
- _g.mapflags =
- {
- -- warnings
- ["-W1"] = "-Wall"
- , ["-W2"] = "-Wall"
- , ["-W3"] = "-Wall"
-
- -- strip
- , ["-s"] = "-Wl,-S"
- , ["-S"] = "-Wl,-S"
-
- }
-end
-
--- get the property
-function get(name)
-
- -- get it
- return _g[name]
-end
-
--- make the define flag
-function define(macro)
-
- -- make it
- return "-D" .. macro:gsub("\"", "\\\"")
-end
-
--- make the undefine flag
-function undefine(macro)
-
- -- make it
- return "-U" .. macro
-end
-
--- make the includedir flag
-function includedir(dir)
-
- -- make it
- return "-I" .. dir
-end
-
--- make the command
-function command(srcfile, objfile, flags, logfile)
-
- -- redirect
- local redirect = ""
- if logfile then redirect = format(" > %s 2>&1", logfile) end
-
- -- make it
- return format("%s -c %s -o %s %s%s", _g.shellname, flags, objfile, srcfile, redirect)
-end
-
--- check the given flags
-function check(flags)
-
- -- done
- local ok = false
- try
- {
- function ()
-
- -- check it
- os.run("%s %s -S -o $(nuldev) -xc $(nuldev) > $(nuldev) 2>&1", _g.shellname, flags)
-
- -- ok
- ok = true
-
- end
- }
-
- -- ok?
- return ok
-end
-
--- run the command
-function run(cmd, ...)
+ _super._g.cxflags = {"-Qunused-arguments"}
+ _super._g.mxflags = {"-Qunused-arguments"}
+ _super._g.asflags = {"-Qunused-arguments"}
- -- run it
- os.run(cmd, ...)
-
end
diff --git a/xmake/tools/compiler/g++.lua b/xmake/tools/compiler/g++.lua
new file mode 100755
index 000000000..7b2837b8e
--- /dev/null
+++ b/xmake/tools/compiler/g++.lua
@@ -0,0 +1,33 @@
+--!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 g++.lua
+--
+
+-- inherit gcc
+inherit("gcc")
+
+-- init it
+function init(shellname)
+
+ -- init super
+ _super.init(shellname or "g++")
+
+end
+
diff --git a/xmake/tools/compiler/gcc.lua b/xmake/tools/compiler/gcc.lua
index 72fb8aede..9d6e8a484 100755
--- a/xmake/tools/compiler/gcc.lua
+++ b/xmake/tools/compiler/gcc.lua
@@ -34,9 +34,6 @@ function init(shellname)
, "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\""
, "\"-DIBAction=void)__attribute__((ibaction)\""}
- -- init shflags
- _g.shflags = { "-shared", "-fPIC" }
-
-- init cxflags for the kind: shared
_g.shared = {}
_g.shared.cxflags = {"-fPIC"}
@@ -117,11 +114,3 @@ function check(flags)
return ok
end
--- run the command
-function run(cmd, ...)
-
- -- check it
- os.run(cmd, ...)
-
-end
-