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

Support for source-based packages #1972

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
36 changes: 32 additions & 4 deletions lib/fpm/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ def to_s
# a summary or description of the package
attr_accessor :description

# the source code archive
attr_accessor :source_archive

# Shell code for building this package from source. (inserted into a
# source-package's spec file).
attr_accessor :build_procedure

# Shell code for installing this package to host OS (inserted into a
# source-package's spec file).
attr_accessor :install_procedure

# Arguments to pass to dh in a SDEB's debian/rules file.
attr_accessor :dh_args

# hash of scripts for maintainer/package scripts (postinstall, etc)
#
# The keys are :before_install, etc
Expand Down Expand Up @@ -201,10 +215,11 @@ def convert(klass)

# copy other bits
ivars = [
:@architecture, :@category, :@config_files, :@conflicts,
:@dependencies, :@description, :@epoch, :@iteration, :@license, :@maintainer,
:@name, :@provides, :@replaces, :@scripts, :@url, :@vendor, :@version,
:@directories, :@staging_path, :@attrs
:@architecture, :@build_procedure, :@category, :@config_files, :@conflicts,
:@dependencies, :@description, :@dh_args, :@epoch, :@install_procedure,
:@iteration, :@license, :@maintainer, :@name, :@provides, :@replaces,
:@scripts, :@url, :@vendor, :@version, :@directories, :@source_archive,
:@staging_path, :@attrs
]
ivars.each do |ivar|
#logger.debug("Copying ivar", :ivar => ivar, :value => instance_variable_get(ivar),
Expand Down Expand Up @@ -550,6 +565,19 @@ def provides=(value)
end
end

def ensure_source_package_capable
required = [:@source_archive, :@build_procedure, :@install_procedure]

required.each do |req|
unless instance_variable_get(req)
raise "#{self.class.name} does not yet support creating #{self.type} " \
"source-based packages. Missing required instance variable #{req}."
end
end

return true
end # def ensure_source_package_capable

# General public API
public(:type, :initialize, :convert, :input, :output, :to_s, :cleanup, :files,
:version, :script, :provides=)
Expand Down
14 changes: 14 additions & 0 deletions lib/fpm/package/cpan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ def input(package)
# Empty install_base to avoid local::lib being used.
"--install_base", "")
end

# used for creating source-based packages (such as SRPM)
self.build_procedure = "perl Build.PL\n./Build"
self.install_procedure = "./Build install"

elsif File.exist?("Makefile.PL")
if attributes[:cpan_perl_lib_path]
perl_lib_path = attributes[:cpan_perl_lib_path]
Expand All @@ -251,13 +256,19 @@ def input(package)
safesystem(*(make + ["test"])) if attributes[:cpan_test?]
safesystem(*(make + ["DESTDIR=#{staging_path}", "install"]))

# used for creating source-based packages (such as SRPM)
self.build_procedure = "perl Makefile.PL\nmake"
self.install_procedure = "make install"

else
raise FPM::InvalidPackageConfiguration,
"I don't know how to build #{name}. No Makefile.PL nor " \
"Build.PL found"
end

# dh recognizes perl code automatically
self.dh_args = ''

# Fix any files likely to cause conflicts that are duplicated
# across packages.
# https://github.com/jordansissel/fpm/issues/443
Expand Down Expand Up @@ -362,6 +373,9 @@ def download(metadata, cpan_version=nil)
#response.read_body { |c| fd.write(c) }
fd.write(response.body)
end

self.source_archive = build_path(tarball)

return build_path(tarball)
end # def download

Expand Down
7 changes: 7 additions & 0 deletions lib/fpm/package/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def download(gem_name, gem_version=nil)
raise "Unexpected number of gem files in #{download_dir}, #{gem_files.length} should be 1"
end

self.source_archive = gem_files.first

return gem_files.first
end # def download

Expand Down Expand Up @@ -217,6 +219,11 @@ def load_package_info(gem_path)
end
end # runtime_dependencies
end #no_auto_depends

# in case we are building a source-based package
self.build_procedure = ""
self.install_procedure = "gem install #{File.basename(gem_path)}"
self.dh_args = "--buildsystem=ruby --with ruby"
end # def load_package_info

def install_to_staging(gem_path)
Expand Down
Loading