Exclude files (#42)

File exclusion from pattern exclusion list
This commit is contained in:
Tanner Rogalsky
2017-01-18 08:41:35 -05:00
committed by Antonin Décimo
parent e6f8f7386a
commit 339cbe7b42
4 changed files with 42 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ love-release can extract its informations from the environment: it guesses your
``` ```
Usage: love-release [-D] [-M] [-a <author>] [-b] [-d <desc>] Usage: love-release [-D] [-M] [-a <author>] [-b] [-d <desc>]
[-e <email>] [-l <love>] [-p <package>] [-t <title>] [-u <url>] [-e <email>] [-l <love>] [-p <package>] [-t <title>] [-u <url>]
[--uti <uti>] [-v <v>] [--version] [-h] [<release>] [<source>] [--uti <uti>] [-v <v>] [-X <exclude>] [--version] [-h] [<release>] [<source>]
[-W [32|64]] [-W [32|64]]
Makes LÖVE games releases easier ! Makes LÖVE games releases easier !
@@ -49,6 +49,8 @@ Options:
Project title. Project title.
-u <url>, --url <url> Project homepage url. -u <url>, --url <url> Project homepage url.
--uti <uti> Project Uniform Type Identifier. --uti <uti> Project Uniform Type Identifier.
-x <exclude_pattern>, --exclude <exclude_pattern>
Exclude file patterns.
-v <v> Project version. -v <v> Project version.
--version Show love-release version and exit. --version Show love-release version and exit.
-h, --help Show this help message and exit. -h, --help Show this help message and exit.
@@ -71,6 +73,7 @@ function love.conf(t)
description = nil, -- The project description (string) description = nil, -- The project description (string)
homepage = nil, -- The project homepage (string) homepage = nil, -- The project homepage (string)
identifier = nil, -- The project Uniform Type Identifier (string) identifier = nil, -- The project Uniform Type Identifier (string)
excludeFileList = {}, -- File patterns to exclude. (string list)
releaseDirectory = nil, -- Where to store the project releases (string) releaseDirectory = nil, -- Where to store the project releases (string)
} }
end end

View File

@@ -50,6 +50,8 @@ function Args:initialize()
parser:option("--uti", "Project Uniform Type Identifier.") parser:option("--uti", "Project Uniform Type Identifier.")
parser:option("-v", "Project version.") parser:option("-v", "Project version.")
:target("version") :target("version")
parser:option("-x --exclude", "Exclude file patterns."):count("*")
:target("excludeFileList")
parser:flag("--version", "Show love-release version and exit.") parser:flag("--version", "Show love-release version and exit.")
:target("love_release") :target("love_release")
@@ -89,6 +91,7 @@ function Args:__call(project)
if args.url then project:setHomepage(args.url) end if args.url then project:setHomepage(args.url) end
if args.uti then project:setIdentifier(args.uti) end if args.uti then project:setIdentifier(args.uti) end
if args.version then project:setVersion(args.version) end if args.version then project:setVersion(args.version) end
if args.excludeFileList then project:setExcludeFileList(args.excludeFileList) end
if project.projectDirectory == project.releaseDirectory then if project.projectDirectory == project.releaseDirectory then
project:setReleaseDirectory(project.releaseDirectory.."/releases") project:setReleaseDirectory(project.releaseDirectory.."/releases")

View File

@@ -29,6 +29,12 @@ function pipe.pipe(project)
end end
end end
local function setTable(key, value)
if type(value) == "table" then
project["set"..key](project, value)
end
end
local function setLoveVersion(v) local function setLoveVersion(v)
if type(v) == "string" and v ~= "" then if type(v) == "string" and v ~= "" then
local version = semver(v) local version = semver(v)
@@ -65,6 +71,7 @@ function pipe.pipe(project)
setString("Homepage", releases.homepage) setString("Homepage", releases.homepage)
setString("Identifier", releases.identifier) setString("Identifier", releases.identifier)
setString("ReleaseDirectory", releases.releaseDirectory) setString("ReleaseDirectory", releases.releaseDirectory)
setTable("ExcludeFileList", releases.excludeFileList)
end end
return project return project

View File

@@ -37,6 +37,9 @@ Project.homepage = nil
--- Uniform Type Identifier in reverse-DNS format. --- Uniform Type Identifier in reverse-DNS format.
Project.identifier = nil Project.identifier = nil
--- Sequential table of string patterns to exclude from the project.
Project.excludeFileList = {}
--- Project directory, where to find the game sources. --- Project directory, where to find the game sources.
Project.projectDirectory = nil Project.projectDirectory = nil
@@ -75,6 +78,18 @@ _buildFileTree = function(dir)
end end
end end
--- Recursive function to check if file should be excluded based
--- on a file name string pattern match.
-- @local
local function isExcluded(file, exclusionRule, ...)
if exclusionRule == nil then return false end
if file:find(exclusionRule) then
return true
else
return isExcluded(file, ...)
end
end
--- Constructs the file tree. --- Constructs the file tree.
-- @return File tree. The table represents the root directory. -- @return File tree. The table represents the root directory.
-- Sub-directories are represented as sub-tables, indexed by the directory name. -- Sub-directories are represented as sub-tables, indexed by the directory name.
@@ -125,23 +140,13 @@ function Project:excludeFiles()
"^"..utils.lua.escape_string_regex(self.projectDirectory).."/", "^"..utils.lua.escape_string_regex(self.projectDirectory).."/",
"") "")
if rm_dir > 0 then if rm_dir > 0 then
rm_dir = true
dir = "^"..dir dir = "^"..dir
else
rm_dir = false
end end
if rm_dir then local unpack = unpack or table.unpack
local rm = false for i=#self._fileList,1,-1 do
local file if isExcluded(self._fileList[i], dir, unpack(self.excludeFileList)) then
local n = #self._fileList table.remove(self._fileList, i)
for i = 1, n do
file = self._fileList[i]
if rm_dir then if file:find(dir) then rm = true end end
if rm then
self._fileList[i] = nil
rm = false
end
end end
end end
end end
@@ -183,6 +188,7 @@ function Project:__tostring()
' description = '..escape(self.description)..',\n'.. ' description = '..escape(self.description)..',\n'..
' homepage = '..escape(self.homepage)..',\n'.. ' homepage = '..escape(self.homepage)..',\n'..
' identifier = '..escape(self.identifier)..',\n'.. ' identifier = '..escape(self.identifier)..',\n'..
' excludeFileList = { '..escape(table.concat(self.excludeFileList, ', '))..'} ,\n'..
' compile = '..escape(self.compile)..',\n'.. ' compile = '..escape(self.compile)..',\n'..
' projectDirectory = '..escape(self.projectDirectory)..',\n'.. ' projectDirectory = '..escape(self.projectDirectory)..',\n'..
' releaseDirectory = '..escape(self.releaseDirectory)..',\n'.. ' releaseDirectory = '..escape(self.releaseDirectory)..',\n'..
@@ -261,6 +267,14 @@ function Project:setIdentifier(identifier)
return self return self
end end
--- Sets the excludeFileList.
-- @string excludeFileList the excludeFileList.
-- @treturn project self.
function Project:setExcludeFileList(excludeFileList)
self.excludeFileList = excludeFileList
return self
end
--- Sets the source directory. The path is normalized and absoluted. --- Sets the source directory. The path is normalized and absoluted.
-- @string directory the directory. -- @string directory the directory.
-- @treturn project self. -- @treturn project self.