Skip to content

Commit

Permalink
Move exclude functionality into the convert process, and make give it…
Browse files Browse the repository at this point in the history
… a sensible default of excluding nothing
  • Loading branch information
cpennington committed Mar 27, 2012
1 parent 2b22b2e commit 0f2da16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
21 changes: 11 additions & 10 deletions lib/fpm/command.rb
Expand Up @@ -95,9 +95,11 @@ class FPM::Command < Clamp::Command
option ["-e", "--edit"], :flag,
"Edit the package spec before building.", :default => false
option ["-x", "--exclude"], "EXCLUDE_PATTERN",
"Exclude paths matching pattern (shell wildcard globs valid here)" do |val|
@exclude_pattern ||= []
@exclude_pattern << val
"Exclude paths matching pattern (shell wildcard globs valid here). " \
"Patterns are evaluated relative to the root of the working directory, " \
"or the directory specified by -C" do |val|
@excludes ||= []
@excludes << val
end # -x / --exclude
option "--description", "DESCRIPTION", "Add a description for this package.",
:default => "no description"
Expand Down Expand Up @@ -173,6 +175,7 @@ def initialize(*args)
@provides = []
@dependencies = []
@config_files = []
@excludes = []
end # def initialize

# Execute this command. See Clamp::Command#execute and Clamp's documentation
Expand Down Expand Up @@ -273,10 +276,11 @@ def execute
set.call(input, :version)
set.call(input, :architecture)

input.conflicts += conflicts
input.dependencies += dependencies
input.provides += provides
input.replaces += replaces
input.conflicts += @conflicts
input.dependencies += @dependencies
input.provides += @provides
input.replaces += @replaces
input.excludes += @excludes

setscript = proc do |scriptname|
path = self.send(scriptname)
Expand All @@ -296,9 +300,6 @@ def execute
setscript.call(:before_remove)
setscript.call(:after_remove)

# Remove excluded paths
input.exclude(@exclude_pattern)

# Convert to the output type
output = input.convert(output_class)

Expand Down
13 changes: 10 additions & 3 deletions lib/fpm/package.rb
Expand Up @@ -82,6 +82,9 @@ def to_s
# (Not all packages support this)
attr_accessor :replaces

# Array of glob patterns to exclude from this package
attr_accessor :excludes

# a summary or description of the package
attr_accessor :description

Expand Down Expand Up @@ -155,6 +158,7 @@ def initialize
@dependencies = []
@scripts = {}
@config_files = []
@excludes = []

staging_path
build_path
Expand All @@ -170,6 +174,9 @@ def type
# Convert this package to a new package type
def convert(klass)
@logger.info("Converting #{self.type} to #{klass.type}")

exclude

pkg = klass.new
pkg.cleanup_staging # purge any directories that may have been created by klass.new

Expand Down Expand Up @@ -311,7 +318,7 @@ def edit_file(path)
end
end # def edit_file

def exclude(paths)
def exclude()
# This method removes excluded files from the staging_path. Subclasses can
# remove the files during the input phase rather than deleting them here
if @attributes.include?(:prefix)
Expand All @@ -320,7 +327,7 @@ def exclude(paths)
installdir = staging_path
end

paths.each do |path|
@excludes.each do |path|
path = File.join(installdir, path)
::Dir.glob(path) do |rmpath|
@logger.debug("Removing", :path => rmpath)
Expand Down Expand Up @@ -399,7 +406,7 @@ def type
end # class << self

# General public API
public(:type, :initialize, :convert, :input, :output, :to_s, :cleanup, :files, :exclude)
public(:type, :initialize, :convert, :input, :output, :to_s, :cleanup, :files)

# Package internal public api
public(:cleanup_staging, :cleanup_build, :staging_path, :converted_from,
Expand Down

0 comments on commit 0f2da16

Please sign in to comment.