JD2022-TU1/main/extern/gear4/buildfolder/generation/harvester.lua

92 lines
3.4 KiB
Lua

-- The class responsible for collecting the file associated with a library
-- It basically collect all files under a directory within a set of extensions
-- and remove all files that have suffix of a different platform.
-- Note: only known suffixes are removed. unknown suffixes are kept.
require "operators"
require "functools"
require "itertools"
-- all valid platform suffixes defined.
-- they must appear at the end of the filename only to be valid
local PLATFORM_NAMES = {
win32 = { "win32", "ms", "ms_pc", "vc", "sse" },
win64 = { "win64", "ms", "ms_pc", "vc", "sse" },
mac = { "mac", "apple", "clang", "sse" },
ios = { "ios", "apple", "clang" },
ps3_ppu = { "ps3", "ps3_ppu", "snc" },
ps3_spu = { "ps3", "ps3_spu", "gcc" },
vita = { "vita", "snc" },
orbis = { "orbis", "sse", "clang" },
xenon = { "ms", "xenon", "vc" },
durango = { "ms", "durango", "vc", "sse" },
cafe = { "cafe", "gc2", "gc", "ghs" },
linux = { "linux", "gcc" },
android = { "android", "gcc" },
}
local ALL_PLATFORM_NAMES = collect(unique(concat_from_iterable(PLATFORM_NAMES)))
FileHarvester = {
-- all valid extensions.
extensions = { ".h", ".cpp", ".inl", ".asm", ".c", ".mm", ".cgs" }
}
function FileHarvester:New(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
-- Validation to check if a file is platform specific.
function FileHarvester:HasPlatformIn(file, platforms)
local basename = path.getbasename(file)
function isplatform(platform)
return basename:match("_" .. platform .. "$") ~= nil
end
return any(map(isplatform, platforms))
end
-- Validation to check if a file is a bulk.
function FileHarvester:IsBulk(file)
return file:match("^.+_bulk_.+.cpp$") ~= nil
end
-- Validation to check if a file is a satellite blob.
function FileHarvester:IsSatelliteBlob(file)
return file:match("^.+" .. self.satelliteName .. "%.cpp$") ~= nil or file:match("^.+" .. self.satelliteName .. "_" .. self.platform .. "%.cpp$") ~= nil
end
-- Return all sources files (based on the extensions list) under the specified directory.
function FileHarvester:GetSrcFiles(directory, extensions)
function match_by_ext(ext)
local pattern = joinpath(directory, "**" .. ext)
return matchfiles(pattern)
end
return concat_from_iterable(map(match_by_ext, extensions))
end
-- Check if a file is not specific to another platform.
function FileHarvester:IsIncluded(file)
return not self:HasPlatformIn(file, self.excluded_platforms) and not self:IsBulk(file) and (self.IsInBlobMode or not self:IsSatelliteBlob(file))
end
-- return the list of valid files under the directory.
function FileHarvester:Harvest(directory)
self.included_platforms = PLATFORM_NAMES[self.platform]
assert(self.included_platforms)
self.excluded_platforms = collect(difference(ALL_PLATFORM_NAMES, self.included_platforms))
-- check if platform is ios
if any(map(function(platform) return platform and platform == "ios" end, self.included_platforms)) then
-- if platform is ios and ".plist" extension is not already included, add it in the extensions list
if not any(map(function(extension) return extension and extension == ".plist" end, self.extensions)) then
table.insert(self.extensions, ".plist")
end
end
local files = self:GetSrcFiles(directory, self.extensions)
return filter(partial(self.IsIncluded, self), files)
end