Class: Cany::Dpkg::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/cany/dpkg/creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Creator

Returns a new instance of Creator.



7
8
9
10
# File 'lib/cany/dpkg/creator.rb', line 7

def initialize(spec)
  @spec = spec
  @options = {}
end

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



6
7
8
# File 'lib/cany/dpkg/creator.rb', line 6

def spec
  @spec
end

Instance Method Details

#create_changelogObject



131
132
133
134
135
136
137
138
139
# File 'lib/cany/dpkg/creator.rb', line 131

def create_changelog
  File.open debian('changelog'), 'w' do |f|
    f.write "#{spec.name} (#{spec.version}-1) unstable; urgency=low\n"
    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

#create_compactObject



71
72
73
74
75
# File 'lib/cany/dpkg/creator.rb', line 71

def create_compact
  File.open debian('compat'), 'w' do |f|
    f.write '8'
  end
end


97
98
99
100
101
102
103
104
105
106
# File 'lib/cany/dpkg/creator.rb', line 97

def create_copyright
  File.open debian('copyright'), 'w' do |f|
    f.write("Format: http://dep.debian.net/deps/dep5\n")
    f.write("Upstream-Name: #{spec.name}\n\n")

    f.write("Files: *\n")
    f.write("Copyright: #{Time.now.year} #{spec.maintainer_name}\n")
    f.write("Licence: #{spec.licence}\n  [LICENCE TEXT]\n")
  end
end

#create_rulesObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/cany/dpkg/creator.rb', line 108

def create_rules
  File.open debian('rules'), 'w' do |f|
    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

#create_source_controlObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cany/dpkg/creator.rb', line 77

def create_source_control
  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: #{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: #{resolve_dependencies(@spec.runtime_dependencies)}\n")
    f.write("Description: #{spec.description}\n")
  end
end

#create_source_formatObject



66
67
68
69
# File 'lib/cany/dpkg/creator.rb', line 66

def create_source_format
  Dir.mkdir debian 'source'
  File.open(debian('source', 'format'), 'w') { |f| f.write '3.0 (native)' }
end

#debian(*args) ⇒ Object



12
13
14
# File 'lib/cany/dpkg/creator.rb', line 12

def debian(*args)
  File.join spec.base_dir, 'debian', *args
end

#parse_opts(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cany/dpkg/creator.rb', line 24

def parse_opts(*args)
  @options = {}

  OptionParser.new do|opts|
    opts.on('--ruby-exe RUBY_EXE', 'Choose the ruby interpreter name (default is ruby)') do |exe|
      @options[:ruby_exe] = exe
    end

    opts.on('--ruby-deb RUBY_DEB', 'Choose the ruby package name (default is ruby)') do |deb|
      @options[:ruby_deb] = deb
    end

    opts.on('-r', '--ruby RUBY_EXE_DEB', 'Set ruby interpreter and package name') do |name|
      @options[:ruby_exe] = name
      @options[:ruby_deb] = name
    end

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end.parse *args
end

#ruby_debObject



20
21
22
# File 'lib/cany/dpkg/creator.rb', line 20

def ruby_deb
  @options[:ruby_deb] || 'ruby'
end

#ruby_exeObject



16
17
18
# File 'lib/cany/dpkg/creator.rb', line 16

def ruby_exe
  @options[:ruby_exe] || 'ruby'
end

#run(*args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cany/dpkg/creator.rb', line 48

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
  create_rules
  create_changelog
end