diff options
| author | ruki <[email protected]> | 2018-04-10 22:35:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-04-10 09:34:29 +0800 |
| commit | 6d200ffbb19986456088cdcd0d24912409f93fe5 (patch) | |
| tree | 2860a1b72f7aa715f639f172ba9f1c45059e871a | |
| parent | 483f101b3fe1502ce4daca8d47058dba4cd27dee (diff) | |
check flags for swift
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/rule.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/swiftc/has_flags.lua | 111 |
2 files changed, 124 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/import/core/project/rule.lua b/xmake/core/sandbox/modules/import/core/project/rule.lua index 0f7766a87..3451c9691 100644 --- a/xmake/core/sandbox/modules/import/core/project/rule.lua +++ b/xmake/core/sandbox/modules/import/core/project/rule.lua @@ -45,6 +45,19 @@ end -- build source files function sandbox_core_project_rule.build(rulename, target, sourcefiles) + -- TODO + -- + -- sperate task and packages + -- private project._define_apis + -- rule.deps + -- on_build + -- on_build_file + -- on_build_files + -- after_build + -- on_install + -- + -- rule -> mode: debug, release + -- get rule local rule = project.rule(rulename) if not rule then diff --git a/xmake/modules/detect/tools/swiftc/has_flags.lua b/xmake/modules/detect/tools/swiftc/has_flags.lua new file mode 100644 index 000000000..a85637d2a --- /dev/null +++ b/xmake/modules/detect/tools/swiftc/has_flags.lua @@ -0,0 +1,111 @@ +--!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 has_flags.lua +-- + +-- imports +import("lib.detect.cache") + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "detect.tools.swiftc.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- load cache + local cacheinfo = cache.load(key) + + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"--help"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + cacheinfo[flagskey] = allflags + cache.save(key, cacheinfo) + end + + -- ok? + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "swiftc_has_flags.swift") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "") + end + + -- check it + local objectfile = os.tmpfile() .. ".o" + local ok, errors = _try_running(opt.program, table.join(flags, "-o", objectfile, sourcefile)) + + -- remove files + os.tryrm(objectfile) + + -- ok? + return ok, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + |
