summaryrefslogtreecommitdiff
path: root/xmake/modules/core/project/depend.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-05-08 22:46:38 +0800
committerruki <[email protected]>2018-05-08 10:39:52 +0800
commitc61545b0275b64c8b0294ce69e635e30475a2239 (patch)
tree0eba3c71f7065c5546f059e755f1ac869d4ac4fd /xmake/modules/core/project/depend.lua
parent5a1eebb5b49e7476ceb773d9b846c0c61c9f99c8 (diff)
improve build dependence
Diffstat (limited to 'xmake/modules/core/project/depend.lua')
-rw-r--r--xmake/modules/core/project/depend.lua94
1 files changed, 94 insertions, 0 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
new file mode 100644
index 000000000..cbb3d1bd8
--- /dev/null
+++ b/xmake/modules/core/project/depend.lua
@@ -0,0 +1,94 @@
+--!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 depend.lua
+--
+
+-- load dependent info from the given file (.d)
+function load(dependfile)
+ return os.isfile(dependfile) and io.load(dependfile) or nil
+end
+
+-- save dependent info to file
+function save(dependinfo, dependfile)
+ io.save(dependfile, dependinfo)
+end
+
+-- the dependent info is changed?
+--
+-- if not depend.is_changed(dependinfo, {filemtime = os.mtime(objectfile), values = {...}}) then
+-- return
+-- end
+--
+function is_changed(dependinfo, opt)
+
+ -- check the dependent files are changed?
+ local lastmtime = nil
+ _g.file_results = _g.file_results or {}
+ for _, file in ipairs(dependinfo.files) do
+
+ -- optimization: this file has been not checked?
+ local status = _g.file_results[file]
+ if status == nil then
+
+ -- optimization: only uses the mtime of first object file
+ lastmtime = lastmtime or opt.lastmtime or 0
+
+ -- source and header files have been changed?
+ if os.mtime(file) > lastmtime then
+
+ -- mark this file as changed
+ _g.file_results[file] = true
+ return true
+ end
+
+ -- mark this file as not changed
+ _g.file_results[file] = false
+
+ -- has been checked and changed?
+ elseif status then
+ return true
+ end
+ end
+
+ -- check the dependent values are changed?
+ local depvalues = dependinfo.values or {}
+ local optvalues = opt.values or {}
+ if #depvalues ~= #optvalues then
+ return true
+ end
+ for idx, depvalue in ipairs(depvalues) do
+ local optvalue = optvalues[idx]
+ local deptype = type(depvalue)
+ local opttype = type(optvalue)
+ if deptype ~= opttype then
+ return true
+ elseif deptype == "string" and depvalue ~= optvalue then
+ return true
+ elseif deptype == "table" then
+ for subidx, subvalue in ipairs(depvalue) do
+ if subvalue ~= optvalue[subidx] then
+ return true
+ end
+ end
+ end
+ end
+end