Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude files #42

Merged
merged 7 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>]
[-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]]

Makes LÖVE games releases easier !
Expand Down Expand Up @@ -49,6 +49,8 @@ Options:
Project title.
-u <url>, --url <url> Project homepage url.
--uti <uti> Project Uniform Type Identifier.
-x <exclude_pattern>, --exclude <exclude_pattern>
Exclude file patterns.
-v <v> Project version.
--version Show love-release version and exit.
-h, --help Show this help message and exit.
Expand All @@ -71,6 +73,7 @@ function love.conf(t)
description = nil, -- The project description (string)
homepage = nil, -- The project homepage (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)
}
end
Expand Down
3 changes: 3 additions & 0 deletions src/pipes/args.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function Args:initialize()
parser:option("--uti", "Project Uniform Type Identifier.")
parser:option("-v", "Project version.")
:target("version")
parser:option("-x --exclude", "Exclude file patterns."):count("*")
:target("excludeFileList")

parser:flag("--version", "Show love-release version and exit.")
:target("love_release")
Expand Down Expand Up @@ -89,6 +91,7 @@ function Args:__call(project)
if args.url then project:setHomepage(args.url) end
if args.uti then project:setIdentifier(args.uti) 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
project:setReleaseDirectory(project.releaseDirectory.."/releases")
Expand Down
7 changes: 7 additions & 0 deletions src/pipes/conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ function pipe.pipe(project)
end
end

local function setTable(key, value)
if type(value) == "table" then
project["set"..key](project, value)
end
end

local function setLoveVersion(v)
if type(v) == "string" and v ~= "" then
local version = semver(v)
Expand Down Expand Up @@ -65,6 +71,7 @@ function pipe.pipe(project)
setString("Homepage", releases.homepage)
setString("Identifier", releases.identifier)
setString("ReleaseDirectory", releases.releaseDirectory)
setTable("ExcludeFileList", releases.excludeFileList)
end

return project
Expand Down
42 changes: 28 additions & 14 deletions src/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Project.homepage = nil
--- Uniform Type Identifier in reverse-DNS format.
Project.identifier = nil

--- Sequential table of string patterns to exclude from the project.
Project.excludeFileList = {}

--- Project directory, where to find the game sources.
Project.projectDirectory = nil

Expand Down Expand Up @@ -75,6 +78,18 @@ _buildFileTree = function(dir)
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.
-- @return File tree. The table represents the root directory.
-- Sub-directories are represented as sub-tables, indexed by the directory name.
Expand Down Expand Up @@ -125,23 +140,13 @@ function Project:excludeFiles()
"^"..utils.lua.escape_string_regex(self.projectDirectory).."/",
"")
if rm_dir > 0 then
rm_dir = true
dir = "^"..dir
else
rm_dir = false
end

if rm_dir then
local rm = false
local file
local n = #self._fileList
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
local unpack = unpack or table.unpack
for i=#self._fileList,1,-1 do
if isExcluded(self._fileList[i], dir, unpack(self.excludeFileList)) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like an alias here to support multiple versions of Lua (see msg00532)

local unpack = unpack or table.unpack
-- or
table.unpack = table.unpack or unpack -- preferred ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the second one, you should never modify Lua's built-in modules since that is not expected from a module and can end up with problems in other modules later on

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I'm glad I'm following this project, it is already really mature. Keep it up!

table.remove(self._fileList, i)
end
end
end
Expand Down Expand Up @@ -183,6 +188,7 @@ function Project:__tostring()
' description = '..escape(self.description)..',\n'..
' homepage = '..escape(self.homepage)..',\n'..
' identifier = '..escape(self.identifier)..',\n'..
' excludeFileList = { '..escape(table.concat(self.excludeFileList, ', '))..'} ,\n'..
' compile = '..escape(self.compile)..',\n'..
' projectDirectory = '..escape(self.projectDirectory)..',\n'..
' releaseDirectory = '..escape(self.releaseDirectory)..',\n'..
Expand Down Expand Up @@ -261,6 +267,14 @@ function Project:setIdentifier(identifier)
return self
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.
-- @string directory the directory.
-- @treturn project self.
Expand Down