diff options
| author | ruki <[email protected]> | 2016-04-15 11:29:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-15 11:29:31 +0800 |
| commit | 8783f5a604a928f414059b77d2bcc4eb6ef10803 (patch) | |
| tree | 48b0b1015268cbae60186a60010652fddfad46a7 | |
| parent | f6942112a7377b99c0be9eac45b269519ab4ac56 (diff) | |
add checker for macosx
| -rwxr-xr-x | xmake/actions/config/main.lua | 6 | ||||
| -rwxr-xr-x | xmake/actions/global/main.lua | 2 | ||||
| -rw-r--r-- | xmake/core/platform/checker.lua | 179 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 56 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/task.lua | 10 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/platform.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/config.lua | 12 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/global.lua | 12 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/tool.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 22 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 27 | ||||
| -rw-r--r-- | xmake/platforms/macosx/checker.lua | 270 | ||||
| -rwxr-xr-x | xmake/tools/compiler/gcc.lua | 2 | ||||
| -rwxr-xr-x | xmake/tools/linker/gcc.lua | 2 |
16 files changed, 510 insertions, 116 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 1c5311cf2..6f427b08e 100755 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -77,7 +77,7 @@ function main() end -- merge the checked configure - config.probe() + config.check() -- merge the cached configure if not option.get("clean") then @@ -93,8 +93,8 @@ function main() config.set("buildir", path.relative(buildir, project.directory())) end - -- probe the project options - project.probe() + -- check the project options + project.check() -- load project project.load() diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index cf8ab67a3..7c03e08d0 100755 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -48,7 +48,7 @@ function main() end -- merge the checked configure - global.probe() + global.check() -- merge the cached configure if not option.get("clean") then diff --git a/xmake/core/platform/checker.lua b/xmake/core/platform/checker.lua new file mode 100644 index 000000000..52bff4f48 --- /dev/null +++ b/xmake/core/platform/checker.lua @@ -0,0 +1,179 @@ +--!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 checker.lua +-- + +-- define module +local checker = checker or {} + +-- load modules +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local config = require("project/config") +local global = require("project/global") +local sandbox = require("sandbox/sandbox") +local platform = require("platform/platform") + +-- the directories of checker +function checker._directories(plat) + + -- the directories + return { path.join(path.join(config.directory(), "platforms"), plat) + , path.join(path.join(global.directory(), "platforms"), plat) + , path.join(path.join(xmake._PROGRAM_DIR, "platforms"), plat) + } +end + +-- check the list +function checker._checklist(funclist, ...) + + -- check all + for _, func in ipairs(table.wrap(funclist)) do + + -- call it + local ok, errors = sandbox.load(func, ...) + if not ok then + return false, errors + end + end + + -- ok + return true +end + +-- load the given checker from the given platform +function checker.load(plat) + + -- check + assert(plat) + + -- get it directly from cache dirst + checker._CHECKERS = checker._CHECKERS or {} + if checker._CHECKERS[plat] then + return checker._CHECKERS[plat] + end + + -- find the checker script path + local scriptpath = nil + for _, dir in ipairs(checker._directories(plat)) do + + -- find this directory + scriptpath = path.join(dir, "checker.lua") + if os.isfile(scriptpath) then + break + end + + end + + -- not exists? + if not scriptpath or not os.isfile(scriptpath) then + return nil, string.format("the checker of %s not found!", plat) + 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, path.directory(scriptpath)) + 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 tool to the cache + checker._CHECKERS[plat] = module + + -- ok? + return module + end + + -- failed + return nil, errors +end + +-- check the project or global configure +-- +-- @param name the configure name: global or config +-- +function checker.check(name) + + -- check the project configure? + if name == "config" then + + -- get the current platform + local plat = config.get("plat") + if not plat then + return false, string.format("the current platform is unknown!") + end + + -- load the checker module + local module, errors = checker.load(plat) + if not module then + return false, errors + end + + -- check it + return checker._checklist(module.get("config"), config) + + -- check the global configure? + elseif name == "global" then + + -- check all platforms with the current host + for _, plat in ipairs(table.wrap(platform.plats())) do + + -- load the checker module + local module, errors = checker.load(plat) + if not module then + return false, errors + end + + -- belong to the current host? + if module.get("host") == xmake._HOST then + + -- check it + local ok, errors = checker._checklist(module.get("global"), global) + if not ok then + return false, errors + end + end + end + + -- ok + return true + end + + -- failed + return false, string.format("unknown check name: %s", name) +end + +-- return module +return checker diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index f552ea3ef..1d454178d 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -38,28 +38,6 @@ function platform._directories() } end --- load prober the given platform directory -function platform._load_prober(platdir) - - -- the platform file path - local filepath = path.join(platdir, "prober.lua") - if os.isfile(filepath) then - - -- load script - local script = loadfile(filepath) - if script then - - -- load prober - local prober = script() - if prober then - - -- ok - return prober - end - end - end -end - -- load the given platform from the given directory function platform._load_from(dir, plat) @@ -79,9 +57,6 @@ function platform._load_from(dir, plat) module._DIRECTORY = path.directory(filepath) assert(module._DIRECTORY) - -- attempt to load prober - module._PROBER = platform._load_prober(module._DIRECTORY) - -- ok return module end @@ -334,36 +309,5 @@ function platform.menu(action) return menus end --- probe the platform configure -function platform.probe(is_global) - - -- probe global - if is_global then - - -- get all platforms - local plats = platform.plats() - assert(plats) - - -- probe all platforms with the current host - for _, plat in ipairs(plats) do - local module = platform._load(plat) - if module and module._PROBER and module._PROBER.global and module._HOST and module._HOST == xmake._HOST then - if not module._PROBER.global() then return false end - end - end - - -- probe config - else - -- probe it - local module = platform.module() - if module and module._PROBER and module._PROBER.config then - if not module._PROBER.config() then return false end - end - end - - -- ok - return true -end - -- return module: platform return platform diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 252e75ab6..cc9072369 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -474,8 +474,8 @@ function project._interpreter() return interp end --- probe the project -function project.probe() +-- check the project +function project.check() -- enter the project directory local ok, errors = os.cd(xmake._PROJECT_DIR) diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index 98cf00454..f095772b1 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -128,12 +128,12 @@ function task._translate_menu(menu) end -- add common options - table.insert(options, 1, {'v', "verbose", "k", nil, "Print lots of verbose information." }) - table.insert(options, 2, {nil, "version", "k", nil, "Print the version number and exit." }) - table.insert(options, 3, {'h', "help", "k", nil, "Print this help message and exit." }) + table.insert(options, 1, {'v', "verbose", "k", nil, "Print lots of verbose information." }) + table.insert(options, 2, {nil, "version", "k", nil, "Print the version number and exit." }) + table.insert(options, 3, {'h', "help", "k", nil, "Print this help message and exit." }) table.insert(options, 4, {}) - table.insert(options, 5, {'f', "file", "kv", nil, "Read a given xmake.lua file." }) - table.insert(options, 6, {'P', "project", "kv", nil, "Change to the given project directory." + table.insert(options, 5, {'f', "file", "kv", nil, "Read a given xmake.lua file." }) + table.insert(options, 6, {'P', "project", "kv", nil, "Change to the given project directory." , "Search priority:" , " 1. The Given Command Argument" , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 1498abd79..05718b0b3 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -39,12 +39,5 @@ function sandbox_core_platform_platform.load(plat) end end --- get the current host -function sandbox_core_platform_platform.host() - - -- get it - return xmake._HOST -end - -- return module return sandbox_core_platform_platform diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 2275db69a..729bfa105 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -25,6 +25,7 @@ local sandbox_core_project_config = sandbox_core_project_config or {} -- load modules local config = require("project/config") +local checker = require("platform/checker") local platform = require("platform/platform") local raise = require("sandbox/modules/raise") @@ -122,12 +123,13 @@ function sandbox_core_project_config.init() config.init() end --- probe the configure -function sandbox_core_project_config.probe() +-- check the configure +function sandbox_core_project_config.check() - -- probe it - if not platform.probe(false) then - raise("probe the project configure failed!") + -- check it + local ok, errors = checker.check("config") + if not ok then + raise(errors) end end diff --git a/xmake/core/sandbox/modules/import/core/project/global.lua b/xmake/core/sandbox/modules/import/core/project/global.lua index 5e0d8b594..2239f4e3a 100644 --- a/xmake/core/sandbox/modules/import/core/project/global.lua +++ b/xmake/core/sandbox/modules/import/core/project/global.lua @@ -25,6 +25,7 @@ local sandbox_core_project_global = sandbox_core_project_global or {} -- load modules local global = require("project/global") +local checker = require("platform/checker") local platform = require("platform/platform") local raise = require("sandbox/modules/raise") @@ -76,12 +77,13 @@ function sandbox_core_project_global.init() global.init() end --- probe the configure -function sandbox_core_project_global.probe() +-- check the configure +function sandbox_core_project_global.check() - -- probe it - if not platform.probe(true) then - raise("probe the global configure failed!") + -- check it + local ok, errors = checker.check("global") + if not ok then + raise(errors) end end diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 568d588bc..cbf4832c0 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -38,11 +38,11 @@ function sandbox_core_project_project.load() end end --- probe project options -function sandbox_core_project_project.probe() +-- check project options +function sandbox_core_project_project.check() - -- probe it - local ok, errors = project.probe() + -- check it + local ok, errors = project.check() if not ok then raise(errors) end diff --git a/xmake/core/sandbox/modules/import/core/tool/tool.lua b/xmake/core/sandbox/modules/import/core/tool/tool.lua index 2735d92a1..3b2f054c1 100644 --- a/xmake/core/sandbox/modules/import/core/tool/tool.lua +++ b/xmake/core/sandbox/modules/import/core/tool/tool.lua @@ -51,5 +51,12 @@ function sandbox_core_tool.run(name, ...) instance.run(...) end +-- check the tool and return the absolute path if exists +function sandbox_core_tool.check(shellname, dirs) + + -- check it + return tool.check(shellname, dirs) +end + -- return module return sandbox_core_tool diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index e6fa1018a..81378c66e 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -241,6 +241,28 @@ function sandbox_os.raise(msg, ...) os.raise(msg, ...) end +-- get the system host +function sandbox_os.host() + + -- get it + return xmake._HOST +end + +-- get the system architecture +function sandbox_os.arch() + + -- get it + return xmake._ARCH +end + +-- get the system null device +function sandbox_os.nuldev() + + -- get it + return xmake._NULDEV +end + + -- return module return sandbox_os diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 64965db4a..22831ba00 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -122,31 +122,6 @@ function tool._find(root, name) return file_ok end --- the tool filter -function tool._filter() - - -- new filter - return filter.new(function (variable) - - -- check - assert(variable) - - -- init maps - local maps = - { - host = xmake._HOST - , nuldev = xmake._NULDEV - , tmpdir = os.tmpdir() - , curdir = os.curdir() - } - - -- map it - return maps[variable] - - end) - -end - -- load the given tool from the given kind -- -- the kinds: @@ -190,7 +165,7 @@ function tool.load(kind) if script then -- make sandbox instance with the given script - local instance, errors = sandbox.new(script, tool._filter(), path.directory(toolpath)) + local instance, errors = sandbox.new(script, nil, path.directory(toolpath)) if not instance then return nil, errors end diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua new file mode 100644 index 000000000..97e8e981f --- /dev/null +++ b/xmake/platforms/macosx/checker.lua @@ -0,0 +1,270 @@ +--!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 checker.lua +-- + +-- imports +import("core.tool.tool") + +-- check the architecture +function _check_arch(config) + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + + end +end + +-- check the xcode application directory +function _check_xcode(config) + + -- get the xcode directory + local xcode_dir = config.get("xcode_dir") + if not xcode_dir then + + -- attempt to get the default directory + if not xcode_dir then + if os.isdir("/Applications/Xcode.app") then + xcode_dir = "/Applications/Xcode.app" + end + end + + -- attempt to match the other directories + if not xcode_dir then + local dirs = os.match("/Applications/Xcode*.app", true) + if dirs and #dirs ~= 0 then + xcode_dir = dirs[1] + end + end + + -- check ok? update it + if xcode_dir then + + -- save it + config.set("xcode_dir", xcode_dir) + + -- trace + print("checking for the Xcode application directory ... %s", xcode_dir) + else + -- failed + raise("checking for the Xcode application directory ... no\n" .. + " - xmake config --xcode_dir=xxx\n" .. + "or - xmake global --xcode_dir=xxx") + end + end +end + +-- probe the xcode sdk version +function _check_xcode_sdkver(config) + + -- get the xcode sdk version + local xcode_sdkver = config.get("xcode_sdkver") + if not xcode_sdkver then + + -- attempt to match the directory + if not xcode_sdkver then + local dirs = os.match(config.get("xcode_dir") .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.sdk", true) + if dirs then + for _, dir in ipairs(dirs) do + xcode_sdkver = string.match(dir, "%d+%.%d+") + if xcode_sdkver then break end + end + end + end + + -- check ok? update it + if xcode_sdkver then + + -- save it + config.set("xcode_sdkver", xcode_sdkver) + + -- trace + print("checking for the Xcode SDK version for %s ... %s", config.get("plat"), xcode_sdkver) + else + -- failed + raise("checking for the Xcode SDK version for %s ... no\n" .. + " - xmake config --xcode_sdkver=xxx" .. + "or - xmake global --xcode_sdkver=xxx", config.get("plat")) + end + end +end + +-- check the target minimal version +function _check_target_minver(config) + + -- get the target minimal version + local target_minver = config.get("target_minver") + if not target_minver then + + -- init the default target minimal version + config.set("target_minver", "10.9") + + -- trace + print("checking for the target minimal version ... %s", config.get("target_minver")) + + end +end + +-- check the make +function _check_make(config) + + -- ok? + local make = config.get("make") + if not make then + + -- check the make path + make = tool.check("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"}) + + -- check ok? update it + if make then config.set("make", make) end + + -- trace + print("checking for the make ... %s", ifelse(make, make, "no")) + + end +end + +-- check the ccache +function _check_ccache(config) + + -- ok? + local ccache = config.get("ccache") + if ccache ~= nil then + + -- check the ccache path + local ccache_path = tool.check("ccache", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"}) + + -- check ok? update it + if ccache_path then + config.set("ccache", true) + config.set("__ccache", ccache_path) + else + config.set("ccache", false) + end + + -- trace + print("checking for the ccache ... %s", ifelse(ccache_path, ccache_path, "no")) + + end +end + +-- check the tool path +function _check_toolpath(config, kind, cross, names, description) + + -- get the cross + cross = config.get("cross") or cross + + -- done + local toolpath = nil + local toolchains = config.get("toolchains") + for _, name in ipairs(names) do + + -- attempt to get it from the given cross toolchains + if toolchains then + toolpath = tool.check(cross .. (config.get(kind) or name), toolchains) + end + + -- attempt to get it directly from the configure + if not toolpath then + toolpath = config.get(kind) + end + + -- attempt to run it directly + if not toolpath then + toolpath = tool.check(cross .. name) + end + + -- check ok? + if toolpath then + + -- update config + config.set(kind, toolpath) + + -- end + break + end + + end + + -- trace + if toolpath then + print("checking for %s (%s) ... %s", description, kind, path.filename(toolpath)) + else + print("checking for %s (%s) ... no", description, kind) + end + +end + +-- check the toolchains +function _check_toolchains(config) + + -- done + _check_toolpath(config, "cc", "xcrun -sdk macosx ", "clang", "the c compiler") + _check_toolpath(config, "cxx", "xcrun -sdk macosx ", {"clang++", "clang"}, "the c++ compiler") + _check_toolpath(config, "mm", "xcrun -sdk macosx ", "clang", "the objc compiler") + _check_toolpath(config, "mxx", "xcrun -sdk macosx ", {"clang++", "clang"}, "the objc++ compiler") + _check_toolpath(config, "as", "xcrun -sdk macosx ", "clang", "the assember") + _check_toolpath(config, "ld", "xcrun -sdk macosx ", {"clang++", "clang"}, "the linker") + _check_toolpath(config, "ar", "xcrun -sdk macosx ", "ar", "the static library linker") + _check_toolpath(config, "sh", "xcrun -sdk macosx ", {"clang++", "clang"}, "the shared library linker") + _check_toolpath(config, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler") +end + +-- init it +function init() + + -- init host + _g.host = "macosx" + + -- init the check list of config + _g.config = + { + _check_arch + , _check_xcode + , _check_xcode_sdkver + , _check_target_minver + , _check_make + , _check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + _check_xcode + , _check_ccache + } + +end + +-- get the property +function get(name) + + -- get it + return _g[name] +end + diff --git a/xmake/tools/compiler/gcc.lua b/xmake/tools/compiler/gcc.lua index 522d1a12d..ebe5c492f 100755 --- a/xmake/tools/compiler/gcc.lua +++ b/xmake/tools/compiler/gcc.lua @@ -98,7 +98,7 @@ function check(flags) function () -- check it - os.run("%s %s -S -o $(nuldev) -xc $(nuldev) > $(nuldev) 2>&1", _g.shellname, flags) + os.run("%s %s -S -o %s -xc %s > %s 2>&1", _g.shellname, flags, os.nuldev(), os.nuldev(), os.nuldev()) -- ok ok = true diff --git a/xmake/tools/linker/gcc.lua b/xmake/tools/linker/gcc.lua index 7c3146628..35c263e34 100755 --- a/xmake/tools/linker/gcc.lua +++ b/xmake/tools/linker/gcc.lua @@ -81,7 +81,7 @@ function check(flags) function () -- check it - os.run("%s %s -S -o $(nuldev) -xc $(nuldev) > $(nuldev) 2>&1", _g.shellname, flags) + os.run("%s %s -S -o %s -xc %s > %s 2>&1", _g.shellname, flags, os.nuldev(), os.nuldev(), os.nuldev()) -- ok ok = true |
