summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-01-05 13:20:57 +0800
committerruki <[email protected]>2017-01-06 17:20:08 +0800
commit63463f04bee8ea369c2bbe0306f1e9316333f0dc (patch)
treebdc6c663fa8877f20779d6032c18db84c2626440
parent06a7207823add9becd9f0929c9ed1b4eb2a1ab44 (diff)
uses loaded return value for language and platform
-rw-r--r--xmake/core/language/language.lua75
-rw-r--r--xmake/core/platform/platform.lua6
-rw-r--r--xmake/core/sandbox/sandbox.lua2
-rw-r--r--xmake/languages/c++/load.lua93
-rwxr-xr-xxmake/languages/c++/xmake.lua65
-rwxr-xr-xxmake/languages/golang/xmake.lua1
-rwxr-xr-xxmake/languages/objc++/xmake.lua1
-rwxr-xr-xxmake/languages/swift/xmake.lua1
-rwxr-xr-xxmake/platforms/android/xmake.lua3
-rwxr-xr-xxmake/platforms/iphoneos/xmake.lua3
-rwxr-xr-xxmake/platforms/linux/xmake.lua5
-rwxr-xr-xxmake/platforms/macosx/xmake.lua2
-rwxr-xr-xxmake/platforms/mingw/xmake.lua3
-rwxr-xr-xxmake/platforms/watchos/xmake.lua3
-rw-r--r--xmake/platforms/windows/environment.lua2
-rwxr-xr-xxmake/platforms/windows/xmake.lua2
16 files changed, 135 insertions, 132 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index f1134d614..566b1ccdc 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -34,60 +34,6 @@ local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local global = require("project/global")
--- load the language module
-function _instance:_load(modulename)
-
- -- return it directly if cached
- local cachename = "_" .. modulename:upper()
- if self[cachename] then
- return self[cachename]
- end
-
- -- no this module?
- if not self._INFO[modulename] then
- return nil
- end
-
- -- get the script path
- local scriptpath = path.join(self._ROOTDIR, self._INFO[modulename] .. ".lua")
-
- -- not exists?
- if not scriptpath or not os.isfile(scriptpath) then
- return nil, string.format("the %s of %s not found!", modulename, self._NAME)
- end
-
- -- load script
- local script, errors = loadfile(scriptpath)
- if script then
-
- -- make sandbox instance with the given script
- local instance, errors = sandbox.new(script, nil, self._ROOTDIR)
- if not instance then
- return nil, errors
- end
-
- -- import the module
- local module, errors = instance:import()
- if not module then
- return nil, errors
- end
-
- -- init the module
- if module.init then
- module.init()
- end
-
- -- save it to the cache
- self[cachename] = module
-
- -- ok?
- return module
- end
-
- -- failed
- return nil, errors
-end
-
-- new an instance
function _instance.new(name, info, rootdir)
@@ -109,23 +55,27 @@ function _instance:get(name)
-- the info
local info = self._INFO
- -- load it first
+ -- get if from info first
+ local value = info[name]
+ if value ~= nil then
+ return value
+ end
+
+ -- load _g
if self._g == nil and info.load ~= nil then
-- load it
- local ok, errors = sandbox.load(info.load)
+ local ok, results = sandbox.load(info.load)
if not ok then
- os.raise(errors)
+ os.raise(results)
end
-- save _g
- self._g = getfenv(info.load)._g
+ self._g = results
end
- -- get it
- if self._g ~= nil then
- return self._g[name]
- end
+ -- get it from _g
+ return self._g[name]
end
-- get the language sourcekinds
@@ -281,6 +231,7 @@ function language.apis()
os.raise(errors)
end
+
-- merge apis for each language
local apis = {values = {}, pathes = {}}
for name, instance in pairs(languages) do
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index ded064214..e066f2a36 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -119,13 +119,13 @@ function _instance:get(name)
if self._g == nil and info.load ~= nil then
-- load it
- local ok, errors = sandbox.load(info.load)
+ local ok, results = sandbox.load(info.load)
if not ok then
- os.raise(errors)
+ os.raise(results)
end
-- save _g
- self._g = getfenv(info.load)._g
+ self._g = results
end
-- get it from _g
diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua
index cac1a8baf..432346171 100644
--- a/xmake/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/sandbox.lua
@@ -176,7 +176,7 @@ function sandbox.new(script, filter, rootdir)
script = function (...)
-- import it
- import(modulename).main(...)
+ return import(modulename).main(...)
end
end
diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua
new file mode 100644
index 000000000..b13b81bb4
--- /dev/null
+++ b/xmake/languages/c++/load.lua
@@ -0,0 +1,93 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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 load.lua
+--
+
+-- imports
+
+
+-- load it
+function main()
+
+ -- init flags
+ _g.cflags = {}
+ _g.cxflags = {}
+ _g.cxxflags = {}
+ _g.ldflags = {}
+ _g.arflags = {}
+ _g.shflags = {}
+
+ -- init apis
+ _g.apis = {}
+ _g.apis.values =
+ {
+ -- target.set_xxx
+ "target.set_config_h_prefix"
+ -- target.add_xxx
+ , "target.add_links"
+ , "target.add_cflags"
+ , "target.add_cxflags"
+ , "target.add_cxxflags"
+ , "target.add_ldflags"
+ , "target.add_arflags"
+ , "target.add_shflags"
+ , "target.add_defines"
+ , "target.add_undefines"
+ , "target.add_defines_h"
+ , "target.add_undefines_h"
+ -- option.add_xxx
+ , "option.add_cincludes"
+ , "option.add_cxxincludes"
+ , "option.add_cfuncs"
+ , "option.add_cxxfuncs"
+ , "option.add_ctypes"
+ , "option.add_cxxtypes"
+ , "option.add_links"
+ , "option.add_cflags"
+ , "option.add_cxflags"
+ , "option.add_cxxflags"
+ , "option.add_ldflags"
+ , "option.add_arflags"
+ , "option.add_shflags"
+ , "option.add_defines"
+ , "option.add_defines_if_ok"
+ , "option.add_defines_h_if_ok"
+ , "option.add_undefines"
+ , "option.add_undefines_if_ok"
+ , "option.add_undefines_h_if_ok"
+ }
+ _g.apis.pathes =
+ {
+ -- target.set_xxx
+ "target.set_headerdir"
+ , "target.set_config_h"
+ -- target.add_xxx
+ , "target.add_headers"
+ , "target.add_linkdirs"
+ , "target.add_includedirs"
+ -- option.add_xxx
+ , "option.add_linkdirs"
+ , "option.add_includedirs"
+ }
+
+ return _g
+end
+
+
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 7854a6e98..40f71cf0c 100755
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -27,70 +27,7 @@ language("c++")
set_sourcekinds(".c", ".cc", ".cpp")
-- on load
- on_load(function ()
-
- -- init flags
- _g.cflags = {}
- _g.cxflags = {}
- _g.cxxflags = {}
- _g.ldflags = {}
- _g.arflags = {}
- _g.shflags = {}
-
- -- init apis
- _g.apis = {}
- _g.apis.values =
- {
- -- target.set_xxx
- "target.set_config_h_prefix"
- -- target.add_xxx
- , "target.add_links"
- , "target.add_cflags"
- , "target.add_cxflags"
- , "target.add_cxxflags"
- , "target.add_ldflags"
- , "target.add_arflags"
- , "target.add_shflags"
- , "target.add_defines"
- , "target.add_undefines"
- , "target.add_defines_h"
- , "target.add_undefines_h"
- -- option.add_xxx
- , "option.add_cincludes"
- , "option.add_cxxincludes"
- , "option.add_cfuncs"
- , "option.add_cxxfuncs"
- , "option.add_ctypes"
- , "option.add_cxxtypes"
- , "option.add_links"
- , "option.add_cflags"
- , "option.add_cxflags"
- , "option.add_cxxflags"
- , "option.add_ldflags"
- , "option.add_arflags"
- , "option.add_shflags"
- , "option.add_defines"
- , "option.add_defines_if_ok"
- , "option.add_defines_h_if_ok"
- , "option.add_undefines"
- , "option.add_undefines_if_ok"
- , "option.add_undefines_h_if_ok"
- }
- _g.apis.pathes =
- {
- -- target.set_xxx
- "target.set_headerdir"
- , "target.set_config_h"
- -- target.add_xxx
- , "target.add_headers"
- , "target.add_linkdirs"
- , "target.add_includedirs"
- -- option.add_xxx
- , "option.add_linkdirs"
- , "option.add_includedirs"
- }
-
- end)
+ on_load("load")
diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua
index c1a20fff8..1ee1f63d0 100755
--- a/xmake/languages/golang/xmake.lua
+++ b/xmake/languages/golang/xmake.lua
@@ -60,6 +60,7 @@ language("golang")
, "option.add_linkdirs"
}
+ return _g
end)
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index 00642035b..31959ec2e 100755
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -90,6 +90,7 @@ language("objc++")
, "option.add_includedirs"
}
+ return _g
end)
diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua
index 255957a41..c14d00fb3 100755
--- a/xmake/languages/swift/xmake.lua
+++ b/xmake/languages/swift/xmake.lua
@@ -60,6 +60,7 @@ language("swift")
, "option.add_linkdirs"
}
+ return _g
end)
diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua
index 83ad9d17d..9f8b44bd1 100755
--- a/xmake/platforms/android/xmake.lua
+++ b/xmake/platforms/android/xmake.lua
@@ -116,6 +116,9 @@ platform("android")
end
end
end
+
+ -- ok
+ return _g
end)
-- set menu
diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua
index dfbf3a1c7..446e1a910 100755
--- a/xmake/platforms/iphoneos/xmake.lua
+++ b/xmake/platforms/iphoneos/xmake.lua
@@ -104,6 +104,9 @@ platform("iphoneos")
-- save swift link directory for tools
config.set("__swift_linkdirs", xcode_dir .. "/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos")
end
+
+ -- ok
+ return _g
end)
-- set menu
diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua
index bfefad521..b546fbbd8 100755
--- a/xmake/platforms/linux/xmake.lua
+++ b/xmake/platforms/linux/xmake.lua
@@ -68,7 +68,7 @@ platform("linux")
end
-- ok
- return
+ return _g
end
-- init flags for architecture
@@ -89,6 +89,9 @@ platform("linux")
-- init linkdirs and includedirs
_g.linkdirs = {"/usr/lib", "/usr/local/lib"}
_g.includedirs = {"/usr/include", "/usr/local/include"}
+
+ -- ok
+ return _g
end)
diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua
index e6248e7c2..c4c428afd 100755
--- a/xmake/platforms/macosx/xmake.lua
+++ b/xmake/platforms/macosx/xmake.lua
@@ -91,6 +91,8 @@ platform("macosx")
-- save swift link directory for tools
config.set("__swift_linkdirs", xcode_dir .. "/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx")
+ -- ok
+ return _g
end)
-- set menu
diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua
index 03e259186..e46e5c5cc 100755
--- a/xmake/platforms/mingw/xmake.lua
+++ b/xmake/platforms/mingw/xmake.lua
@@ -69,5 +69,8 @@ platform("mingw")
_g.includedirs = {path.join(sdkdir, "include")}
_g.linkdirs = {path.join(sdkdir, "lib")}
end
+
+ -- ok
+ return _g
end)
diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua
index 54e179e57..a48e50073 100755
--- a/xmake/platforms/watchos/xmake.lua
+++ b/xmake/platforms/watchos/xmake.lua
@@ -104,6 +104,9 @@ platform("watchos")
-- save swift link directory for tools
config.set("__swift_linkdirs", xcode_dir .. "/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/watchos")
end
+
+ -- ok
+ return _g
end)
-- set menu
diff --git a/xmake/platforms/windows/environment.lua b/xmake/platforms/windows/environment.lua
index 961ae84d0..bb233db98 100644
--- a/xmake/platforms/windows/environment.lua
+++ b/xmake/platforms/windows/environment.lua
@@ -17,7 +17,7 @@
-- Copyright (C) 2015 - 2016, ruki All rights reserved.
--
-- @author ruki
--- @file vsenv.lua
+-- @file environment.lua
--
-- imports
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 46ae56054..ab54b0f2e 100755
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -52,6 +52,8 @@ platform("windows")
_g.formats.binary = {"", ".exe"}
_g.formats.symbol = {"", ".pdb"}
+ -- ok
+ return _g
end)
-- set menu