lib/cany/dpkg/creator.rb in cany-0.0.2 vs lib/cany/dpkg/creator.rb in cany-0.1.0

- old
+ new

@@ -46,10 +46,16 @@ end def run(*args) parse_opts *args + # let recipes influence package creating + @spec.system_recipe = DebHelperRecipe.new(spec) + @spec.recipes.each do |recipe| + recipe.create(self) + end + Dir.mkdir debian create_compact create_source_format create_source_control create_copyright @@ -62,48 +68,30 @@ File.open(debian('source', 'format'), 'w') { |f| f.write '3.0 (native)' } end def create_compact File.open debian('compat'), 'w' do |f| - f.write '8' + f.write '9' end end def create_source_control - require 'bundler' - lock_path = File.join(spec.base_dir, 'Gemfile.lock') - extra_libs = { - pg: ['libpq-dev', 'libpq5'], - ethon: ['libcurl3 | libcurl3-gnutls | libcurl3-nss', 'libcurl3 | libcurl3-gnutls | libcurl3-nss'] - } - src_deps = ['debhelper (>= 7.0.50~)', ruby_deb, ruby_deb + '-dev'] - bin_deps = ['${shlibs:Depends}', '${misc:Depends}', ruby_deb] - if File.exists? lock_path - lock = Bundler::LockfileParser.new File.read lock_path - lock.specs.each do |spec| - if extra_libs.has_key? spec.name.to_sym - src, bin = extra_libs[spec.name.to_sym] - src_deps << src - bin_deps << bin - end - end - end File.open debian('control'), 'w' do |f| # write source package fields: f.write("Source: #{spec.name}\n") f.write("Section: ruby\n") f.write("Priority: optional\n") f.write("Maintainer: #{spec.maintainer_name} <#{spec.maintainer_email}>\n") f.write("Standards-Version: 3.9.2\n") f.write("Homepage: #{spec.website}\n") - f.write("Build-Depends: #{src_deps.join(', ')}\n") + f.write("Build-Depends: #{resolve_dependencies(@spec.build_dependencies)}\n") # write binary package fields: f.write("\n") f.write("Package: #{spec.name}\n") f.write("Architecture: any\n") - f.write("Depends: #{bin_deps.join(', ')}\n") + f.write("Depends: #{resolve_dependencies(@spec.runtime_dependencies)}\n") f.write("Description: #{spec.description}\n") end end def create_copyright @@ -117,19 +105,27 @@ end end def create_rules File.open debian('rules'), 'w' do |f| - f.write("#!/usr/bin/make -f\n") - f.write("export PATH := debian/bin:${PATH}\n") - f.write("export GEM_PATH := debian/gems:${GEM_PATH}\n") - # call cany for every target: - f.write("%:\n") - f.write("\t#{ruby_exe} -cS cany >/dev/null || #{ruby_exe} -S gem install --no-ri --no-rdoc --install-dir debian/gems --bindir debian/bin $${CANY_GEM:-cany}\n") - f.write("\t#{ruby_exe} -S cany dpkg-builder $@\n") - f.write("\noverride_dh_prep:\n") + unless @spec.cany_version_constraint + gem_version = '' + else + gem_version = " --version \"#{@spec.cany_version_constraint}\"" + gem_version += ' --prerelease' if @spec.cany_version_constraint.match /[a-zA-Z]/ + end + f.write <<EOM.gsub /^ /, '' + #!/usr/bin/make -f + export PATH := debian/bin:${PATH} + export GEM_PATH := debian/gems:${GEM_PATH} + %: + \t#{ruby_exe} -cS cany >/dev/null || #{ruby_exe} -S gem install --no-ri --no-rdoc --install-dir debian/gems --bindir debian/bin $${CANY_GEM:-cany}#{gem_version} + \t#{ruby_exe} -S cany dpkg-builder $@\n + override_dh_prep: +EOM + f.chmod(0755) end end def create_changelog @@ -138,9 +134,23 @@ f.write "\n" f.write " * Build with cany\n" f.write "\n" f.write " -- #{spec.maintainer_name} <#{spec.maintainer_email}> #{Time.now.strftime "%a, %d %b %Y %H:%M:%S %z" }" end + end + + private + + # Converts the given array of dependencies objects into a dependency string used inside + # debians source control files + # @param dependencies[Array<Dependency>] + # @return [String] A dependency string + def resolve_dependencies(dependencies) + dependencies.inject([]) do |deps, dep| + deps + dep.determine(:ubuntu, :precise).map do |pkg, version| + !version.nil? ? "#{pkg} (#{version})" : pkg + end + end.join(', ') end end end end