deterministic ordered file processing

This commit is contained in:
Steve Donovan 2014-04-23 10:20:55 +02:00
parent 511dfe7df0
commit 251dc88f93
2 changed files with 29 additions and 21 deletions

View File

@ -447,13 +447,22 @@ local function reorder_module_file ()
end end
end end
-- process files, optionally in order that respects master module files
local function process_all_files(files)
local sortfn = reorder_module_file()
local files = tools.expand_file_list(files,'*.*')
if sortfn then files:sort(sortfn) end
for f in files:iter() do
process_file(f, file_list)
end
if #file_list == 0 then quit "no source files found" end
end
if type(args.file) == 'table' then if type(args.file) == 'table' then
-- this can only be set from config file so we can assume it's already read -- this can only be set from config file so we can assume config is already read
args.file.sortfn = reorder_module_file() process_all_files(args.file)
process_file_list(args.file,'*.*',process_file, file_list)
if #file_list == 0 then quit "no source files specified" end
elseif path.isdir(args.file) then elseif path.isdir(args.file) then
local files = List(dir.getallfiles(args.file,'*.*'))
-- use any configuration file we find, if not already specified -- use any configuration file we find, if not already specified
if not config_dir then if not config_dir then
local config_files = files:filter(function(f) local config_files = files:filter(function(f)
@ -466,16 +475,9 @@ elseif path.isdir(args.file) then
end end
end end
end end
-- process files, optionally in order that respects master module files
local sortfn = reorder_module_file() process_all_files({args.file})
if sortfn then files:sort(sortfn) end
for f in files:iter() do
process_file(f, file_list)
end
if #file_list == 0 then
quit(quote(args.file).." contained no source files")
end
elseif path.isfile(args.file) then elseif path.isfile(args.file) then
-- a single file may be accompanied by a config.ld in the same dir -- a single file may be accompanied by a config.ld in the same dir
if not config_dir then if not config_dir then

View File

@ -462,7 +462,13 @@ function M.abspath (f)
return res return res
end end
function M.process_file_list (list, mask, operation, ...) function M.getallfiles(root,mask)
local res = List(dir.getallfiles(root,mask))
res:sort()
return res
end
function M.expand_file_list (list, mask)
local exclude_list = list.exclude and M.files_from_list(list.exclude, mask) local exclude_list = list.exclude and M.files_from_list(list.exclude, mask)
local files = List() local files = List()
local function process (f) local function process (f)
@ -473,7 +479,7 @@ function M.process_file_list (list, mask, operation, ...)
end end
for _,f in ipairs(list) do for _,f in ipairs(list) do
if path.isdir(f) then if path.isdir(f) then
local dfiles = List(dir.getallfiles(f,mask)) local dfiles = M.getallfiles(f,mask)
for f in dfiles:iter() do for f in dfiles:iter() do
process(f) process(f)
end end
@ -483,11 +489,11 @@ function M.process_file_list (list, mask, operation, ...)
quit("file or directory does not exist: "..M.quote(f)) quit("file or directory does not exist: "..M.quote(f))
end end
end end
return files
end
if list.sortfn then function M.process_file_list (list, mask, operation, ...)
files:sort(list.sortfn) local files = M.expand_file_list(list,mask)
end
for f in files:iter() do for f in files:iter() do
operation(f,...) operation(f,...)
end end