From e9bbf53e9defcb33ebedc1dbda1207652b0d4bcc Mon Sep 17 00:00:00 2001 From: Xavier Lucas Date: Mon, 4 Apr 2016 19:17:17 +0200 Subject: [PATCH] Better code structure for packaging Signed-off-by: Xavier Lucas --- Rakefile | 13 ++----- scripts/package.rb | 89 +++++++++++++++++++++------------------------- 2 files changed, 43 insertions(+), 59 deletions(-) diff --git a/Rakefile b/Rakefile index 2e14ade..c24e768 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require 'rake/testtask' +require_relative 'scripts/package.rb' package = { :name => 'svfs', @@ -25,16 +26,8 @@ end # ----------------------------------------- desc 'Release a new version' task :release, [:version] => [:prepare_release] do |t, args| - system(%Q(scripts/package.rb \ - "#{package[:path]}" \ - "#{package[:name]}" \ - "#{package[:maintainer]}" \ - "#{package[:vendor]}" \ - "#{package[:url]}" \ - "#{package[:info]}" \ - "#{package[:licence]}" \ - "#{args.version}" - )) + mkdir_p package[:path] + release(package, args.version) end # ----------------------------------------- diff --git a/scripts/package.rb b/scripts/package.rb index f4204e9..c5203e1 100755 --- a/scripts/package.rb +++ b/scripts/package.rb @@ -1,14 +1,5 @@ #!/usr/bin/env ruby -pkg_path = ARGV[0] -pkg_name = ARGV[1] -pkg_main = ARGV[2] -pkg_vend = ARGV[3] -pkg_url = ARGV[4] -pkg_info = ARGV[5] -pkg_lic = ARGV[6] -pkg_vers = ARGV[7] - # Package dependencies DEPENDENCIES = { 'fuse' => '> 2.8', @@ -29,53 +20,53 @@ 'armel' => 5, } -pkg_deps = "" -# Make release directory -unless File.directory?("#{pkg_path}") - Dir.mkdir("#{pkg_path}") -end +def build(package, type, version, os, arch, deps) + go_arch = arch + pkg_deps = "" -# Build dependencies chain -DEPENDENCIES.each do |pkg, constraint| - pkg_deps << "-d '#{pkg} #{constraint}' " -end + deps.each do |pkg, constraint| + pkg_deps << "-d '#{pkg} #{constraint}' " + end -# Build go binary and package it -TARGETS.each do |target| - target.each do |os, pkgmap| - pkgmap.each do |pkg, archs| - archs.each do |arch| + if arch.start_with?('arm') + go_arch = 'arm' + go_extra = "GOARM=#{ARM_VERSIONS[arch]}" + end - go_arch = arch + go_build_target = "#{package[:path]}/go-#{package[:name]}-#{os}-#{arch}" + sh %{GOARCH=#{go_arch} GOOS=#{os} #{go_extra} go build -o #{go_build_target}} + sh %{chmod 755 #{go_build_target}} + sh %{fpm --force \\ + -s dir \\ + -t #{type} \\ + -a #{arch} \\ + -n #{package[:name]} \\ + -p #{package[:path]} \\ + #{pkg_deps} \\ + --maintainer "#{package[:maintainer]}" \\ + --description "#{package[:info]}" \\ + --license "#{package[:licence]}" \\ + --url "#{package[:url]}" \\ + --vendor "#{package[:vendor]}" \\ + --version "#{version}" \\ + #{go_build_target}=/usr/local/bin/#{package[:name]} \\ + scripts/mount.#{package[:name]}=/sbin/mount.#{package[:name]} \\ + scripts/hubic-application.rb=/usr/local/bin/hubic-application + } - if arch.start_with?('arm') - go_arch = 'arm' - go_extra = "GOARM=#{ARM_VERSIONS[arch]}" - end - - pkg_fullname = "#{pkg_path}/go-#{pkg_name}-#{os}-#{arch}" - system("GOARCH=#{go_arch} GOOS=#{os} #{go_extra} go build -o #{pkg_fullname}") - system("chmod 755 #{pkg_fullname}") - system(%{fpm --force \ - -s dir \ - -t #{pkg} \ - -a #{arch} \ - -n #{pkg_name} \ - -p #{pkg_path} \ - #{pkg_deps} \ - --maintainer "#{pkg_main}" \ - --description "#{pkg_info}" \ - --license "#{pkg_lic}" \ - --url "#{pkg_url}" \ - --vendor "#{pkg_vend}" \ - --version "#{pkg_vers}" \ - #{pkg_fullname}=/usr/local/bin/#{pkg_name} \ - scripts/mount.#{pkg_name}=/sbin/mount.#{pkg_name} \ - scripts/hubic-application.rb=/usr/local/bin/hubic-application - }) +end +def release(package, version) + TARGETS.each do |target| + target.each do |os, pkgmap| + pkgmap.each do |pkg, archs| + archs.each do |arch| + build(package, pkg, version, os, arch, DEPENDENCIES) + end end end end end + +