summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-12-28 00:38:02 +0800
committerruki <[email protected]>2018-12-27 21:48:17 +0800
commitb7fcf6c2262341a9a19579fc56349ff98711e809 (patch)
tree6a0847cb3f82c58cb07053bde8563551e31833e2
parent21cf476235945d90933de6784283f042ded6f13e (diff)
improve environment scripts for platform
-rw-r--r--xmake/core/platform/environment.lua36
-rw-r--r--xmake/core/platform/platform.lua37
-rw-r--r--xmake/platforms/windows/check.lua2
-rw-r--r--xmake/platforms/windows/environment/enter.lua (renamed from xmake/platforms/windows/environment.lua)61
-rw-r--r--xmake/platforms/windows/environment/leave.lua48
-rw-r--r--xmake/platforms/windows/xmake.lua9
6 files changed, 117 insertions, 76 deletions
diff --git a/xmake/core/platform/environment.lua b/xmake/core/platform/environment.lua
index 5bb53e7c4..d435c1199 100644
--- a/xmake/core/platform/environment.lua
+++ b/xmake/core/platform/environment.lua
@@ -26,12 +26,12 @@
local environment = environment or {}
-- load modules
-local os = require("base/os")
-local global = require("base/global")
-local platform = require("platform/platform")
-local sandbox = require("sandbox/sandbox")
-local package = require("package/package")
-local import = require("sandbox/modules/import")
+local os = require("base/os")
+local global = require("base/global")
+local platform_core = require("platform/platform")
+local sandbox = require("sandbox/sandbox")
+local package = require("package/package")
+local import = require("sandbox/modules/import")
-- enter the toolchains environment
function environment._enter_toolchains()
@@ -101,6 +101,12 @@ end
-- enter the environment for the current platform
function environment.enter(name)
+ -- get the current platform
+ local platform, errors = platform_core.load()
+ if not platform then
+ return false, errors
+ end
+
-- the maps
local maps = {toolchains = environment._enter_toolchains, run = environment._enter_run}
@@ -111,9 +117,9 @@ function environment.enter(name)
end
-- enter the environment of the given platform
- local module = platform.get("environment")
- if module then
- local ok, errors = sandbox.load(module.enter, name)
+ local on_enter = platform:script("environment_enter")
+ if on_enter then
+ local ok, errors = sandbox.load(on_enter, platform, name)
if not ok then
return false, errors
end
@@ -126,10 +132,16 @@ end
-- leave the environment for the current platform
function environment.leave(name)
+ -- get the current platform
+ local platform, errors = platform_core.load()
+ if not platform then
+ return false, errors
+ end
+
-- leave the environment of the given platform
- local module = platform.get("environment")
- if module then
- local ok, errors = sandbox.load(module.leave, name)
+ local on_leave = platform:script("environment_leave")
+ if on_leave then
+ local ok, errors = sandbox.load(on_leave, platform, name)
if not ok then
return false, errors
end
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 8eaa56907..b281864bd 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -113,12 +113,33 @@ function _instance:archs()
return self._INFO.archs
end
+-- get the platform script
+function _instance:script(name)
+ return self._INFO[name]
+end
+
+-- get user private data
+function _instance:data(name)
+ return self._DATA and self._DATA[name] or nil
+end
+
+-- set user private data
+function _instance:data_set(name, data)
+ self._DATA = self._DATA or {}
+ self._DATA[name] = data
+end
+
+-- add user private data
+function _instance:data_add(name, data)
+ self._DATA = self._DATA or {}
+ self._DATA[name] = table.unwrap(table.join(self._DATA[name] or {}, data))
+end
+
-- the directories of platform
function platform._directories()
-- the directories
- return { path.join(config.directory(), "platforms")
- , path.join(global.directory(), "platforms")
+ return { path.join(global.directory(), "platforms")
, path.join(os.programdir(), "platforms")
}
end
@@ -150,17 +171,12 @@ function platform._interpreter()
{
-- platform.on_xxx
"platform.on_load"
- , "platform.on_check"
+ , "platform.on_check" -- TODO removed
, "platform.on_config_check"
, "platform.on_global_check"
, "platform.on_environment_enter"
, "platform.on_environment_leave"
}
- , module =
- {
- -- platform.set_xxx
- "platform.set_environment"
- }
, dictionary =
{
-- platform.set_xxx
@@ -230,7 +246,7 @@ function platform.load(plat)
end
-- get result
- local result = utils.ifelse(cross, results["cross"], results[plat])
+ local result = cross and results["cross"] or results[plat]
-- check the platform name
if not result then
@@ -238,7 +254,7 @@ function platform.load(plat)
end
-- new an instance
- local instance, errors = _instance.new(plat, result, platform._interpreter():rootdir())
+ local instance, errors = _instance.new(plat, result, interp:rootdir())
if not instance then
return nil, errors
end
@@ -248,7 +264,6 @@ function platform.load(plat)
-- ok
return instance
-
end
-- get the given platform configure
diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua
index 4bcc123e0..f25b349fa 100644
--- a/xmake/platforms/windows/check.lua
+++ b/xmake/platforms/windows/check.lua
@@ -24,7 +24,7 @@
-- imports
import("platforms.checker", {rootdir = os.programdir()})
-import("environment")
+import("core.platform.environment")
import("core.base.option")
import("detect.sdks.find_vstudio")
import("lib.detect.find_tool")
diff --git a/xmake/platforms/windows/environment.lua b/xmake/platforms/windows/environment/enter.lua
index fd634c110..b117c5681 100644
--- a/xmake/platforms/windows/environment.lua
+++ b/xmake/platforms/windows/environment/enter.lua
@@ -19,7 +19,7 @@
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
--- @file environment.lua
+-- @file enter.lua
--
-- imports
@@ -28,7 +28,7 @@ import("core.base.global")
import("detect.sdks.find_vstudio")
-- enter the given environment
-function _enter(name)
+function _enter(platform, name)
-- get vcvarsall
local vcvarsall = config.get("__vcvarsall") or global.get("__vcvarsall")
@@ -76,61 +76,24 @@ function _enter(name)
os.setenv(name, new)
end
- -- return the previous environment
- return old
-end
-
--- leave the given environment
-function _leave(name, old)
-
- -- restore the previous environment
- if old then
- os.setenv(name, old)
- end
+ -- save the previous environment
+ platform:data_set("windows.environment." .. name, old)
end
-- enter the toolchains environment
-function _enter_toolchains()
-
- -- enter vs toolchains
- _g.pathes = _enter("path")
- _g.libs = _enter("lib")
- _g.includes = _enter("include")
- _g.libpathes = _enter("libpath")
-end
-
--- leave the toolchains environment
-function _leave_toolchains()
-
- -- leave vs toolchains
- _leave("path", _g.pathes)
- _leave("lib", _g.libs)
- _leave("include", _g.includes)
- _leave("libpath", _g.libpathes)
+function _enter_toolchains(platform)
+ _enter(platform, "path")
+ _enter(platform, "lib")
+ _enter(platform, "include")
+ _enter(platform, "libpath")
end
--- enter the toolchains environment
-function enter(name)
-
- -- the maps
+-- enter environment
+function main(platform, name)
local maps = {toolchains = _enter_toolchains}
-
- -- enter it
local func = maps[name]
if func then
- func()
+ func(platform)
end
end
--- leave the toolchains environment
-function leave(name)
-
- -- the maps
- local maps = {toolchains = _leave_toolchains}
-
- -- leave it
- local func = maps[name]
- if func then
- func()
- end
-end
diff --git a/xmake/platforms/windows/environment/leave.lua b/xmake/platforms/windows/environment/leave.lua
new file mode 100644
index 000000000..653ec6843
--- /dev/null
+++ b/xmake/platforms/windows/environment/leave.lua
@@ -0,0 +1,48 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file leave.lua
+--
+
+-- leave the given environment
+function _leave(platform, name)
+ local old = platform:data("windows.environment." .. name)
+ if old then
+ os.setenv(name, old)
+ end
+end
+
+-- leave the toolchains environment
+function _leave_toolchains(platform)
+ _leave(platform, "path")
+ _leave(platform, "lib")
+ _leave(platform, "include")
+ _leave(platform, "libpath")
+end
+
+-- leave environment
+function main(platform, name)
+ local maps = {toolchains = _leave_toolchains}
+ local func = maps[name]
+ if func then
+ func(platform)
+ end
+end
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 95874ec55..961062ad2 100644
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -34,15 +34,18 @@ platform("windows")
-- set archs
set_archs("x86", "x64")
- -- set environment
- set_environment("environment")
-
-- set formats
set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"}
-- on check
on_check("check")
+ -- on environment enter
+ on_environment_enter("environment.enter")
+
+ -- on environment leave
+ on_environment_leave("environment.leave")
+
-- on load
on_load("load")