crate 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ #
2
+ # Crate recipe for openssl
3
+ #
4
+ Crate::Dependency.new("openssl", "0.9.8i") do |t|
5
+ t.depends_on( "zlib" )
6
+ t.upstream_source = "http://www.openssl.org/source/openssl-0.9.8i.tar.gz"
7
+ t.upstream_sha1 = "b2e029cfb68bf32eae997d60317a40945db5a65f"
8
+
9
+ t.build_commands = [
10
+ "./config --prefix=#{File.join( '/', 'usr' )} zlib no-threads no-shared",
11
+ "make"
12
+ ]
13
+
14
+ t.install_commands = [
15
+ "make install_sw INSTALL_PREFIX=#{t.install_dir}" ,
16
+ "make clean"
17
+ ]
18
+
19
+ end
20
+
@@ -0,0 +1,33 @@
1
+ * Make sure selected .a files in the current build directory are appended to
2
+ the build path.
3
+ * run ranlib on all .a files so they actually link correctly
4
+
5
+ --- ext/extmk.rb
6
+ +++ ext/extmk.rb
7
+ @@ -500,6 +500,7 @@ void Init_ext _((void))\n{\n#$extinit}
8
+ end
9
+
10
+ $extobjs = "ext/#{extinit.o} #{$extobjs}"
11
+ + $extobjs = "#{$extobjs} libz.a libcrypto.a libssl.a"
12
+ if RUBY_PLATFORM =~ /m68k-human|beos/
13
+ $extflags.delete("-L/usr/local/lib")
14
+ end
15
+ @@ -513,9 +514,17 @@ void Init_ext _((void))\n{\n#$extinit}
16
+ ].map {|n, v|
17
+ "#{n}=#{v}" if v and !(v = v.strip).empty?
18
+ }.compact
19
+ - puts conf
20
+ $stdout.flush
21
+ $mflags.concat(conf)
22
+ + unless enable_config("shared", $enable_shared )
23
+ + $extobjs.split.each do |eo|
24
+ + if eo =~/^ext/ and eo =~ /\.a$/ then
25
+ + local_f = eo[4..-1]
26
+ + puts "ranlib #{local_f}"
27
+ + %x[ ranlib #{local_f} ]
28
+ + end
29
+ + end
30
+ + end
31
+ else
32
+ FileUtils.rm_f(extinit.to_a)
33
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # Crate recipe for ruby version 1.2.3
3
+ #
4
+ Crate::Ruby.new( "ruby", "1.8.6-p287") do |t|
5
+ t.depends_on( "openssl" )
6
+ t.depends_on( "zlib" )
7
+
8
+ t.integrates( "amalgalite" )
9
+ t.integrates( "arrayfields" )
10
+ t.integrates( "configuration" )
11
+
12
+ t.upstream_source = "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p287.tar.gz"
13
+ t.upstream_md5 = "f6cd51001534ced5375339707a757556"
14
+
15
+ ENV["CPPFLAGS"]= "-I#{File.join( t.install_dir, 'usr', 'include')}"
16
+ ENV["LDFLAGS"] = "-L#{File.join( t.install_dir, 'usr', 'lib' )}"
17
+
18
+ def t.build
19
+ # put the .a files from the fakeroot/usr/lib directory into the package
20
+ # directory so the compilation can use them
21
+ %w[ libz.a libcrypto.a libssl.a ].each do |f|
22
+ FileUtils.cp File.join( install_dir, "usr", "lib", f ), pkg_dir
23
+ end
24
+ sh "./configure --disable-shared --prefix=#{File.join( '/', 'usr' )}"
25
+ sh "make"
26
+ end
27
+
28
+ t.install_commands << "make install DESTDIR=#{t.install_dir}"
29
+
30
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ # Crate recipe for rubygems version 1.3.1
3
+ #
4
+ Crate::Dependency.new( "rubygems", "1.3.1") do |t|
5
+ t.upstream_source = "http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz"
6
+ t.upstream_sha1 = "a21ae466146bffb28ece05cddbdced0b908ca74f"
7
+
8
+ # TODO: figure out proper integration of rubygems, or just wait until 1.9
9
+ #namespace t.name do
10
+ # desc "Integrate with ruby"
11
+ # task :integration => [ "ruby:patch", "#{t.name}:patch" ] do
12
+ # t.logger.info "Integrating #{t.name} into ruby's tree"
13
+ # Dir.chdir( File.join( t.pkg_dir, "lib" ) ) do |d|
14
+ # FileUtils.cp_r ".", Crate.ruby.lib_dir
15
+ # end
16
+ # end
17
+ #end
18
+ end
19
+
@@ -0,0 +1,16 @@
1
+ #
2
+ # Crate recipe for zlib version 1.2.3
3
+ #
4
+ Crate::Dependency.new( "zlib", "1.2.3") do |t|
5
+ t.upstream_source = "http://www.zlib.net/zlib-1.2.3.tar.gz"
6
+ t.upstream_md5 = "debc62758716a169df9f62e6ab2bc634"
7
+
8
+ t.build_commands << "./configure --prefix=#{File.join( '/', 'usr' )}"
9
+
10
+ t.install_commands = [
11
+ "make install prefix=#{File.join( t.install_dir, 'usr' )}",
12
+ "make distclean"
13
+ ]
14
+
15
+ end
16
+
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'crate/version'
3
+ require 'tasks/config'
4
+
5
+ Crate::GEM_SPEC = Gem::Specification.new do |spec|
6
+ proj = Configuration.for('project')
7
+ spec.name = proj.name
8
+ spec.version = Crate::VERSION
9
+
10
+ spec.author = proj.author
11
+ spec.email = proj.email
12
+ spec.homepage = proj.homepage
13
+ spec.summary = proj.summary
14
+ spec.description = proj.description
15
+ spec.platform = Gem::Platform::RUBY
16
+
17
+
18
+ pkg = Configuration.for('packaging')
19
+ spec.files = pkg.files.all
20
+ spec.executables = pkg.files.bin.collect { |b| File.basename(b) }
21
+
22
+ # add dependencies here
23
+ spec.add_dependency("rake", ">= 0.8.1")
24
+ spec.add_dependency("configuration", "~> 0.0.5")
25
+ spec.add_dependency("progressbar")
26
+ spec.add_dependency("archive-tar-minitar")
27
+ spec.add_dependency("amalgalite", "~> 0.5.0")
28
+
29
+
30
+
31
+ if rdoc = Configuration.for_if_exist?('rdoc') then
32
+ spec.has_rdoc = true
33
+ spec.extra_rdoc_files = pkg.files.rdoc
34
+ spec.rdoc_options = rdoc.options + [ "--main" , rdoc.main_page ]
35
+ else
36
+ spec.has_rdoc = false
37
+ end
38
+
39
+ if test = Configuration.for_if_exist?('testing') then
40
+ spec.test_files = test.files
41
+ end
42
+
43
+ if rf = Configuration.for_if_exist?('rubyforge') then
44
+ spec.rubyforge_project = rf.project
45
+ end
46
+
47
+ end
@@ -0,0 +1,85 @@
1
+ #--
2
+ # Copyright (c) 2008 Jeremy Hinegardner
3
+ # All rights reserved. See LICENSE and/or COPYING for details.
4
+ #++
5
+
6
+ require 'rubygems'
7
+ require 'logging'
8
+ require 'date'
9
+
10
+ # Configure Crate to log to STDOUT at the 'info' level
11
+ Logging::Logger['Crate'].level = :info
12
+ Logging::Logger['Crate'].add_appenders( Logging::Appender.stdout )
13
+ Logging::Appender.stdout.layout = Logging::Layouts::Pattern.new(
14
+ :pattern => "[%d] %5l: %m\n", # [date] LEVEL: message
15
+ :date_pattern => "%H:%M:%S" # date == HH::MM::SS
16
+ )
17
+
18
+ module Crate
19
+
20
+ # The root directory of the project is considered to be the parent directory
21
+ # of the 'lib' directory.
22
+ #
23
+ # returns:: [String] The full expanded path of the parent directory of 'lib'
24
+ # going up the path from the current file. Trailing
25
+ # File::SEPARATOR is guaranteed.
26
+ #
27
+ def self.root_dir
28
+ unless @root_dir
29
+ path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR)
30
+ lib_index = path_parts.rindex("lib")
31
+ @root_dir = path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR
32
+ end
33
+ return @root_dir
34
+ end
35
+
36
+ # returns:: [String] The full expanded path of the +config+ directory
37
+ # below _root_dir_. All parameters passed in are joined onto the
38
+ # result. Trailing File::SEPARATOR is guaranteed if _args_ are
39
+ # *not* present.
40
+ #
41
+ def self.config_path(*args)
42
+ self.sub_path("config", *args)
43
+ end
44
+
45
+ # returns:: [String] The full expanded path of the +data+ directory below
46
+ # _root_dir_. All parameters passed in are joined onto the
47
+ # result. Trailing File::SEPARATOR is guaranteed if
48
+ # _*args_ are *not* present.
49
+ #
50
+ def self.data_path(*args)
51
+ self.sub_path("data", *args)
52
+ end
53
+
54
+ # returns:: [String] The full expanded path of the +lib+ directory below
55
+ # _root_dir_. All parameters passed in are joined onto the
56
+ # result. Trailing File::SEPARATOR is guaranteed if
57
+ # _*args_ are *not* present.
58
+ #
59
+ def self.lib_path(*args)
60
+ self.sub_path("lib", *args)
61
+ end
62
+
63
+ def self.sub_path(sub,*args)
64
+ sp = ::File.join(root_dir, sub) + File::SEPARATOR
65
+ sp = ::File.join(sp, *args) if args
66
+ end
67
+
68
+ def self.project
69
+ @project
70
+ end
71
+
72
+ def self.project=( p )
73
+ @project = p
74
+ end
75
+
76
+ def self.ruby
77
+ @ruby
78
+ end
79
+ def self.ruby=( r )
80
+ @ruby = r
81
+ end
82
+
83
+ end
84
+ %w[ version packing_list utils dependency gem_integration ruby project ].each { |r| require "crate/#{r}" }
85
+
@@ -0,0 +1,306 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/clean'
4
+ require 'crate/utils'
5
+ require 'crate/digest'
6
+
7
+ module Crate
8
+ # Create a build task that will download, checksum and build and install an
9
+ # upstream source
10
+ #
11
+ # This task will create the following targets:
12
+ #
13
+ class Dependency < ::Rake::TaskLib
14
+ include ::Crate::Utils
15
+ # Name of the task, this is also the Rake namespace underwhich all other
16
+ # tasks will follow
17
+ attr_accessor :name
18
+
19
+ # Version of the upstream version
20
+ attr_accessor :version
21
+
22
+ # Upstream location
23
+ attr_accessor :upstream_source
24
+
25
+ # array of shell commands for building
26
+ attr_accessor :build_commands
27
+
28
+ # array of shell commands for installing
29
+ attr_accessor :install_commands
30
+
31
+ #
32
+ # Create a Crate Dependency with the given name and version
33
+ #
34
+ def initialize( name = nil, version = nil )
35
+ @name = name
36
+ @version = version
37
+ @install_commands = []
38
+ @build_commands = []
39
+ yield self if block_given?
40
+ @upstream_source = URI.parse( @upstream_source )
41
+ define unless name.nil? or version.nil?
42
+ end
43
+
44
+ #
45
+ # The build directory for this particular task
46
+ #
47
+ def build_dir
48
+ @build_dir ||= File.join(Crate.project.build_dir, name )
49
+ end
50
+
51
+ #
52
+ # The recipe directory for this particular task
53
+ #
54
+ def recipe_dir
55
+ @recipe_dir ||= File.join( Crate.project.recipe_dir, name )
56
+ end
57
+
58
+ #
59
+ # The fake root directory to install into
60
+ #
61
+ def install_dir
62
+ Crate.project.install_dir
63
+ end
64
+
65
+ #
66
+ # handle to the top level logger
67
+ #
68
+ def logger
69
+ Crate.project.logger
70
+ end
71
+
72
+ #
73
+ # The directory this task unpacks into
74
+ #
75
+ def pkg_dir
76
+ @pkg_dir ||= File.join( self.build_dir, "#{name + ( version ? "-#{version}" : "" ) }" )
77
+ end
78
+
79
+ #
80
+ # override the directory that the local source unpacks into if it is not
81
+ # +name-version+
82
+ #
83
+ def pkg_dir=( pd )
84
+ @pkg_dir = File.join( self.build_dir, pd )
85
+ end
86
+
87
+ #
88
+ # The local on disk copy of the upstream source
89
+ #
90
+ def local_source
91
+ @local_source ||= File.join( build_dir, File.basename( upstream_source.path ) )
92
+ end
93
+
94
+ #
95
+ # record the upstream sha1 checksum
96
+ #
97
+ def upstream_sha1=( checksum )
98
+ @digest = Crate::Digest.sha1( checksum )
99
+ end
100
+ def upstream_sha1
101
+ if @digest then
102
+ return @digest.hex
103
+ else
104
+ return nil
105
+ end
106
+ end
107
+
108
+ #
109
+ # record the upstream md5 checksum
110
+ #
111
+ def upstream_md5=( checksum )
112
+ @digest = Crate::Digest.md5( checksum )
113
+ end
114
+ def usptream_md5
115
+ if @digest then
116
+ return @digest.hex
117
+ else
118
+ return nil
119
+ end
120
+ end
121
+
122
+ #
123
+ # Define all the tasks in the namespace of the +name+ of this task.
124
+ #
125
+ # The dependency chain is:
126
+ #
127
+ # :install => :build => :patch => :unpack => :verify => :download
128
+ #
129
+ #
130
+ def define
131
+ logger.debug "Defining tasks for #{name} #{version}"
132
+
133
+ namespace "#{name}" do
134
+ define_download
135
+ define_verify
136
+ define_unpack
137
+ define_patch
138
+ define_build
139
+ define_install
140
+
141
+ task :done => "#{name}:install"
142
+ task :default => "#{name}:done"
143
+ end
144
+
145
+ desc "Build and Install #{name} #{version}"
146
+ task name => "#{name}:default"
147
+ end
148
+
149
+ def define_download
150
+ file local_source do |t|
151
+ logger.info "Downloading #{upstream_source} to #{t.name}"
152
+ download( upstream_source, t.name )
153
+ end
154
+
155
+ desc "Download #{File.basename( local_source )}"
156
+ task :download => local_source
157
+ end
158
+
159
+ def define_verify
160
+ desc "Verify source against its checksum"
161
+ task :verify => "#{name}:download" do
162
+ if @digenst then
163
+ if @digest.valid?( local_source ) then
164
+ logger.info "#{local_source} validates against #{@digest.hex}"
165
+ else
166
+ raise "#{local_source} does not have checksum #{@digest.hex}"
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ def define_unpack
173
+ #-- unpack
174
+ desc "Unpack #{name} into #{build_dir}"
175
+ task :unpack => "#{name}:verify" do
176
+ logger.info "Unpacking"
177
+ unpack( local_source, build_dir )
178
+ FileUtils.rm_f dotfile( 'patch' )
179
+ end
180
+ ::CLEAN << pkg_dir
181
+ end
182
+
183
+ def define_patch
184
+ desc "Apply patches to #{name}"
185
+ task :patch => dotfile( 'patch' ) do
186
+ logger.info "#{name} #{version} is patched"
187
+ end
188
+ file dotfile( 'patch' ) => "#{name}:unpack" do
189
+ logger.info "Patching #{name} #{version}"
190
+ patch_files.each do |pfile|
191
+ logger.info "applying patch #{File.basename( pfile ) }"
192
+ apply_patch( pfile, pkg_dir )
193
+ end
194
+ dotfile!( 'patch' )
195
+ end
196
+
197
+ ::CLEAN << dotfile( 'patch' )
198
+ end
199
+
200
+ def define_build
201
+ desc "Build #{name} #{version}"
202
+ task :build => dotfile( 'build' ) do
203
+ logger.info "#{name} #{version} built"
204
+ end
205
+
206
+ file dotfile( 'build' ) => "#{name}:patch" do
207
+ logger.info "Bulding #{name} #{version}"
208
+ Dir.chdir( pkg_dir ) do
209
+ build
210
+ end
211
+ dotfile!( 'build' )
212
+ end
213
+ ::CLEAN << dotfile( 'build' )
214
+ end
215
+
216
+ def define_install
217
+ desc "Install #{name} into #{Crate.project.install_dir}"
218
+ task :install => dotfile('install') do
219
+ logger.info "#{name} #{version} is installed"
220
+ end
221
+
222
+ file dotfile( 'install' ) => "#{name}:build" do
223
+ logger.info "Installing #{name} #{version}"
224
+ Dir.chdir( pkg_dir ) do
225
+ install
226
+ end
227
+ dotfile!( 'install' )
228
+ end
229
+ ::CLEAN << dotfile( 'install' )
230
+
231
+ end
232
+
233
+
234
+ #
235
+ # Execute all the build commands
236
+ #
237
+ def build
238
+ cd_and_sh( pkg_dir, build_commands )
239
+ end
240
+
241
+ #
242
+ # Execute all the install commands
243
+ #
244
+ def install
245
+ cd_and_sh( pkg_dir, install_commands )
246
+ end
247
+
248
+ #
249
+ # Change to a directory and execute a sequence of commands
250
+ #
251
+ def cd_and_sh( dir, cmds )
252
+ Dir.chdir( dir ) do
253
+ cmds.each do |cmd|
254
+ sh cmd
255
+ end
256
+ end
257
+ end
258
+
259
+ #
260
+ # Execute a shell command, sending the command name to the logger at info
261
+ # level and all the output to the logger at the debug level
262
+ #
263
+ def sh( cmd )
264
+ logger.info( cmd )
265
+
266
+ io = IO.popen( "#{cmd} 2>&1" )
267
+ io.each_line do |l|
268
+ logger.debug( l.strip )
269
+ end
270
+ end
271
+
272
+ #
273
+ # return the full path to a named dotfile
274
+ #
275
+ def dotfile( name )
276
+ File.join( build_dir, ".#{name}" )
277
+ end
278
+
279
+ #
280
+ # make the given dotfile
281
+ #
282
+ def dotfile!( name )
283
+ File.open( dotfile( name ), "w" ) do |f|
284
+ h = { 'name' => self.name, 'version' => self.version, "#{name}_timestsamp" => Time.now }
285
+ f.puts h.to_yaml
286
+ end
287
+ end
288
+
289
+ #
290
+ # allow this task to say it depends on something else. This is a build
291
+ # dependency
292
+ #
293
+ def depends_on( other_dependency )
294
+ namespace name do
295
+ task :build => "#{other_dependency}:done"
296
+ end
297
+ end
298
+
299
+ #
300
+ # patch the upacked source with files that are in the recipe directory
301
+ #
302
+ def patch_files
303
+ Dir[File.join( recipe_dir, "*.patch" )].sort
304
+ end
305
+ end
306
+ end