summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-19 20:14:09 +0800
committerruki <[email protected]>2017-06-19 20:14:09 +0800
commite2d960162cd7c78eaa86ae3fc474a112ec4ddfbe (patch)
tree6fe8f2d89b879f7cc55da4641c827f16e71b3d2e
parent8a7b62bca9d65dfe01a8f63016da48aa650c3a89 (diff)
use find_toolname in tool.lua
-rw-r--r--xmake/core/platform/platform.lua10
-rw-r--r--xmake/core/tool/tool.lua152
-rw-r--r--xmake/platforms/checker.lua23
-rw-r--r--xmake/tools/clangxx.lua (renamed from xmake/tools/clang++.lua)0
-rw-r--r--xmake/tools/gxx.lua (renamed from xmake/tools/g++.lua)0
-rw-r--r--xmake/tools/ml64.lua32
6 files changed, 78 insertions, 139 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 76ff5ff93..26852b60e 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -241,13 +241,13 @@ end
--
function platform.tool(toolkind)
- -- attempt to get it from config first
- local toolpath = config.get(toolkind)
- if toolpath ~= nil then
- return toolpath
+ -- attempt to get program from config first
+ local program = config.get(toolkind)
+ if program then
+ return program
else
- -- check the tool path
+ -- check it first
local check = platform.get("check")
if check then
check("config", toolkind)
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index 6db2e4439..ca81ec0da 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -26,111 +26,20 @@
local tool = tool or {}
-- load modules
-local os = require("base/os")
-local path = require("base/path")
-local utils = require("base/utils")
-local table = require("base/table")
-local string = require("base/string")
-local filter = require("base/filter")
-local config = require("project/config")
-local global = require("project/global")
-local sandbox = require("sandbox/sandbox")
-local platform = require("platform/platform")
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+local table = require("base/table")
+local string = require("base/string")
+local sandbox = require("sandbox/sandbox")
+local platform = require("platform/platform")
+local import = require("sandbox/modules/import")
--- the directories of tools
-function tool._directories(name)
-
- -- the directories
- return { path.join(config.directory(), "tools")
- , path.join(global.directory(), "tools")
- , path.join(xmake._PROGRAM_DIR, "tools")
- }
-end
-
--- match the tool name
-function tool._match(name, toolname)
-
- -- match full? ok
- if name == toolname then return 100 end
-
- -- match the last word? ok
- if name:find(toolname .. "$") then return 80 end
-
- -- contains it? ok
- if name:find(toolname, 1, true) then return 30 end
-
- -- not matched
- return 0
-end
-
--- find tool from the given root directory and name
-function tool._find(root, name)
-
- -- attempt to get it directly first
- local filepath = string.format("%s/%s.lua", root, name)
- if os.isfile(filepath) then
- return filepath
- end
-
- -- make the lower name
- name = name:lower()
-
- -- remove arguments: -xxx or --xxx
- name = (name:gsub("%s%-+%w+", " "))
-
- -- get the last name by ' ': xxx xxx toolname
- local names = name:split("%s")
- if #names > 0 then
- name = names[#names]
- end
-
- -- get the last valid name: xxx-xxx-toolname-5
- local partnames = {}
- for partname in name:gmatch("([%a%+]+)") do
- table.insert(partnames, partname)
- end
- if #partnames > 0 then
- name = partnames[#partnames]
- end
-
- -- remove suffix: ".xxx"
- name = (name:gsub("%.%w+", ""))
-
- -- get all tool files
- local file_ok = nil
- local score_maxn = 0
- local files = os.match(string.format("%s/*.lua", root))
- for _, file in ipairs(files) do
-
- -- the tool name
- local toolname = path.basename(file)
-
- -- found it?
- if toolname and toolname ~= "tool" then
-
- -- match score
- local score = tool._match(name, toolname:lower())
-
- -- ok?
- if score >= 100 then return file end
-
- -- select the file with the max score
- if score > score_maxn then
- file_ok = file
- score_maxn = score
- end
- end
- end
-
- -- ok?
- return file_ok
-end
-
--- load the given tool from the given shell name
-function tool._load(shellname, kind)
+-- load the given tool
+function tool._load(kind, name, program)
-- calculate the cache key
- local key = shellname .. (kind or "")
+ local key = (kind or "") .. program
-- get it directly from cache dirst
tool._TOOLS = tool._TOOLS or {}
@@ -138,22 +47,10 @@ function tool._load(shellname, kind)
return tool._TOOLS[key]
end
- -- find the tool script path
- local toolpath = nil
- local toolname = path.filename(shellname)
- for _, dir in ipairs(tool._directories()) do
-
- -- find this directory
- toolpath = tool._find(dir, toolname)
- if toolpath then
- break
- end
-
- end
-
-- not exists?
- if not toolpath or not os.isfile(toolpath) then
- return nil, string.format("%s not found!", shellname)
+ local toolpath = path.join(os.programdir(), "tools", name .. ".lua")
+ if not os.isfile(toolpath) then
+ return nil, string.format("%s not found!", name)
end
-- load script
@@ -174,7 +71,7 @@ function tool._load(shellname, kind)
-- init the tool module
if module.init then
- module.init(shellname, kind)
+ module.init(program, kind)
end
-- save tool to the cache
@@ -233,14 +130,23 @@ end
--
function tool.load(kind)
- -- get the shell name
- local shellname = platform.tool(kind)
- if not shellname then
+ -- get the tool program
+ local program = platform.tool(kind)
+ if not program then
return nil, string.format("cannot get tool for %s", kind)
end
-
+
+ -- import find_toolname()
+ local find_toolname = import("lib.detect.find_toolname")
+
+ -- get the tool name from the program
+ local name = find_toolname(program)
+ if not name then
+ return nil, string.format("cannot find tool name for %s", program)
+ end
+
-- load it
- return tool._load(shellname, kind)
+ return tool._load(kind, name, program)
end
-- check the tool and return the absolute path if exists
diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua
index 458b5f0d5..6d761c1e0 100644
--- a/xmake/platforms/checker.lua
+++ b/xmake/platforms/checker.lua
@@ -32,9 +32,9 @@ import("lib.detect.find_toolname")
-- find the given tool
function _toolchain_check(config, toolkind, toolinfo)
- -- get the tool path
- local toolpath = config.get(toolkind)
- if not toolpath then
+ -- get the program
+ local program = config.get(toolkind)
+ if not program then
-- get name and attempt to get `$(env XX)`
local name = vformat(toolinfo.name)
@@ -46,27 +46,28 @@ function _toolchain_check(config, toolkind, toolinfo)
local cross = config.get("cross") or toolinfo.cross or ""
-- attempt to check it
- if not toolpath then
- toolpath = find_tool(name, {program = cross .. name, pathes = config.get("toolchains"), check = toolinfo.check})
+ local program = nil
+ if not program then
+ program = find_tool(name, {program = cross .. name, pathes = config.get("toolchains"), check = toolinfo.check})
end
-- check ok?
- if toolpath then
- config.set(toolkind, toolpath)
+ if program then
+ config.set(toolkind, program)
end
-- trace
if option.get("verbose") then
- if toolpath then
- cprint("checking for %s (%s) ... ${green}%s", toolinfo.description, toolkind, path.filename(toolpath))
+ if program then
+ cprint("checking for %s (%s) ... ${green}%s", toolinfo.description, toolkind, path.filename(program))
else
cprint("checking for %s (%s: ${red}%s${clear}) ... ${red}no", toolinfo.description, toolkind, name)
end
end
end
- -- get tool path
- return toolpath
+ -- ok?
+ return program
end
-- check all for the given config kind
diff --git a/xmake/tools/clang++.lua b/xmake/tools/clangxx.lua
index b9545995d..b9545995d 100644
--- a/xmake/tools/clang++.lua
+++ b/xmake/tools/clangxx.lua
diff --git a/xmake/tools/g++.lua b/xmake/tools/gxx.lua
index f37bdb05a..f37bdb05a 100644
--- a/xmake/tools/g++.lua
+++ b/xmake/tools/gxx.lua
diff --git a/xmake/tools/ml64.lua b/xmake/tools/ml64.lua
new file mode 100644
index 000000000..be4bb0dc8
--- /dev/null
+++ b/xmake/tools/ml64.lua
@@ -0,0 +1,32 @@
+--!The Make-like 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file ml64.lua
+--
+
+-- inherit ml
+inherit("ml")
+
+-- init it
+function init(shellname, kind)
+ _super.init(shellname or "ml64", kind)
+end
+