summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-11-10 23:47:15 +0800
committerruki <[email protected]>2017-11-10 16:43:32 +0800
commit24bdac45ba26a318fd07b2bad0baa6d1bdc28fa9 (patch)
treeb0fa91fc30d3dd6804966f5b4950c5a6ea785877
parent5605084d64edb44917f7e69752335d1fdf979515 (diff)
improve ar.lua on windows cmd
-rw-r--r--xmake/core/project/project.lua63
-rw-r--r--xmake/core/project/rule.lua88
-rw-r--r--xmake/modules/core/tools/ar.lua15
3 files changed, 163 insertions, 3 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 488aa5c61..2dfa53d7a 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -35,6 +35,7 @@ local global = require("base/global")
local process = require("base/process")
local deprecated = require("base/deprecated")
local interpreter = require("base/interpreter")
+local rule = require("project/rule")
local target = require("project/target")
local config = require("project/config")
local option = require("project/option")
@@ -197,6 +198,9 @@ function project.interpreter()
-- set root scope
interp:rootscope_set("target")
+ -- define apis for rule
+ interp:api_define(rule.apis())
+
-- define apis for target
interp:api_define(target.apis())
@@ -353,6 +357,41 @@ function project._load_deps(target, targets, deps, orderdeps)
end
end
+-- load rules
+function project._load_rules()
+
+ -- get interpreter
+ local interp = project.interpreter()
+ assert(interp)
+
+ -- enter the project directory
+ local oldir, errors = os.cd(os.projectdir())
+ if not oldir then
+ return nil, errors
+ end
+
+ -- load rules
+ local results, errors = interp:load(project.file(), "rule", true, true)
+ if not results then
+ return nil, errors
+ end
+
+ -- leave the project directory
+ local ok, errors = os.cd(oldir)
+ if not ok then
+ return nil, errors
+ end
+
+ -- make rules
+ local rules = {}
+ for rulename, ruleinfo in pairs(results) do
+ rules[rulename] = rule.new(rulename, ruleinfo)
+ end
+
+ -- ok
+ return rules
+end
+
-- load targets
function project._load_targets()
@@ -564,11 +603,33 @@ function project.clear()
opt:clear()
end
- -- clear targets and options
+ -- clear rules, targets and options
+ project._RULES = nil
project._TARGETS = nil
project._OPTIONS = nil
end
+-- get the given rule
+function project.rule(name)
+ return project.rules()[name]
+end
+
+-- get the current configure for rules
+function project.rules()
+
+ -- load rules
+ if not project._RULES then
+ local rules, errors = project._load_RULES()
+ if not rules then
+ os.raise(errors)
+ end
+ project._RULES = rules
+ end
+
+ -- ok
+ return project._RULES
+end
+
-- get the given target
function project.target(name)
return project.targets()[name]
diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua
new file mode 100644
index 000000000..bd0a2af57
--- /dev/null
+++ b/xmake/core/project/rule.lua
@@ -0,0 +1,88 @@
+--!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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file rule.lua
+--
+
+-- define module
+local rule = rule or {}
+
+-- load modules
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+local table = require("base/table")
+
+-- get rule apis
+function rule.apis()
+
+ return
+ {
+ values =
+ {
+ -- rule.add_xxx
+ "rule.add_imports"
+ }
+ , script =
+ {
+ -- rule.on_xxx
+ "rule.on_build"
+ , "rule.on_clean"
+ , "rule.on_package"
+ , "rule.on_install"
+ , "rule.on_uninstall"
+ -- rule.before_xxx
+ , "rule.before_clean"
+ , "rule.before_package"
+ , "rule.before_install"
+ , "rule.before_uninstall"
+ -- rule.after_xxx
+ , "rule.after_clean"
+ , "rule.after_package"
+ , "rule.after_install"
+ , "rule.after_uninstall"
+ }
+ }
+end
+
+-- new a rule instance
+function rule.new(name, info)
+
+ -- init a rule instance
+ local instance = table.inherit(rule)
+ assert(instance)
+
+ -- save name and info
+ instance._NAME = name
+ instance._INFO = info
+
+ -- ok?
+ return instance
+end
+
+-- get the rule info
+function rule:get(name)
+ return self._INFO[name]
+end
+
+
+-- return module
+return rule
diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua
index 650ca7b27..dc2404d06 100644
--- a/xmake/modules/core/tools/ar.lua
+++ b/xmake/modules/core/tools/ar.lua
@@ -55,8 +55,19 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags)
-- check
assert(targetkind == "static")
- -- make it
- return self:program(), table.join(flags, targetfile, objectfiles)
+ -- make arguments list
+ local argv = table.join(flags, targetfile, objectfiles)
+
+ -- too long?
+ local args = os.args(argv)
+ if #args > 4096 and os.host() == "windows" then
+ local argfile = targetfile .. ".arg"
+ io.printf(argfile, args)
+ argv = {"@" .. argfile}
+ end
+
+ -- ok?
+ return self:program(), argv
end
-- link the library file