chunker/Rakefile
author mahlon
Thu, 04 Jun 2009 17:28:02 +0000
branchruby-modules
changeset 3 233041485364
parent 2 e5c705047540
child 4 01a3332bfe0a
permissions -rw-r--r--
Require spec implicitly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     1
#!/usr/bin/env rake
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     2
#
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     3
# Chunker Rakefile
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     4
#
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     5
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     6
require 'rubygems'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     7
require 'pathname'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     8
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     9
require 'rake'
3
233041485364 Require spec implicitly.
mahlon
parents: 2
diff changeset
    10
require 'spec'
233041485364 Require spec implicitly.
mahlon
parents: 2
diff changeset
    11
require 'rake/testtask'
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    12
require 'rake/packagetask'
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    13
require 'rake/gempackagetask'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    14
require 'spec/rake/spectask'
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    15
require 'rubygems/installer'
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    16
require 'rubygems/uninstaller'
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    17
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    18
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    19
######################################################################
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    20
### P A T H S  A N D  F I L E S
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    21
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    22
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    23
BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    24
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    25
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    26
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    27
SPECDIR    = BASEDIR + 'spec'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    28
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ }
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    29
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    30
LIBDIR    = BASEDIR + 'lib'
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    31
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb').reject {|i| i =~ /\.svn/ }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    32
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    33
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    34
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    35
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    36
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    37
### H E L P E R S
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    38
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    39
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    40
### Given a +file+ path, find the first captured match of +pattern+,
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    41
### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.)
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    42
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    43
def find_pattern( file, pattern )
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    44
	ver = nil
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    45
	File.open( file ) do |f|
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    46
		ver = f.each do |line|
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    47
			break $1 if line =~ pattern
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    48
		end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    49
	end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    50
	return ver.is_a?( String ) ? ver : 'UNKNOWN'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    51
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    52
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    53
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    54
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    55
### P A C K A G E   C O N S T A N T S
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    56
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    57
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    58
PKG_NAME      = 'chunker'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    59
PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ )
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    60
PKG_REVISION  = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ )
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    61
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}.#{PKG_REVISION}"
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    62
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    63
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    64
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    65
### T A S K S
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    66
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    67
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    68
task :default => [ :test, :package ]
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    69
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    70
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    71
### Task: run rspec tests
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    72
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    73
desc "Run tests"
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    74
Spec::Rake::SpecTask.new('test') do |task|
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    75
	task.spec_files = SPEC_FILES
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    76
	task.spec_opts  = %w{ -c -fs }
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    77
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    78
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    79
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    80
### Task: generate ctags
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    81
### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    82
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    83
desc "Generate a ctags 'tags' file from Chunker source"
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    84
task :ctags do
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    85
	sh "ctags -R #{LIBDIR}"
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    86
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    87
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    88
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    89
### Task: Create gem from source
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    90
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    91
gem = Gem::Specification.new do |gem|
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    92
	pkg_build = PKG_REVISION || 0
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    93
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    94
	gem.summary           = "A convenience library for parsing __END__ tokens consistently."
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    95
	gem.name              = PKG_NAME
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    96
	gem.version           = "%s.%s" % [ PKG_VERSION, pkg_build ]
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    97
	gem.author            = 'Mahlon E. Smith'
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    98
	gem.email             = 'mahlon@martini.nu'
3
233041485364 Require spec implicitly.
mahlon
parents: 2
diff changeset
    99
	gem.homepage          = 'http://projects.martini.nu/ruby-modules/wiki/Chunker'
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   100
	gem.rubyforge_project = 'mahlon'
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   101
	gem.has_rdoc          = true
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   102
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   103
	gem.files = RELEASE_FILES.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   104
		collect {|f| f.relative_path_from(BASEDIR).to_s }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   105
	gem.test_files	= SPEC_FILES.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   106
		collect {|f| f.relative_path_from(BASEDIR).to_s }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   107
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   108
	gem.description = <<-EOF
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   109
	Ruby provides an automatic constant called DATA, which is an IO object
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   110
	that references all text in the current file under an __END__ token.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   111
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   112
	I find it convenient to use the __END__ area to store all sorts of
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   113
	stuff, rather than have to worry about distributing separate files.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   114
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   115
	The DATA constant is determined from whatever ruby believes $0 to be.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   116
	It doesn't work inside of other required libraries, so you'll see stuff
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   117
	like this all the time:
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   118
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   119
	END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   120
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   121
	It works, but it's more work than I want to do.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   122
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   123
	Chunker solves this by parsing __END__ tokens for you, and making it
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   124
	available in the form of a 'DATA_END' constant.  It installs this
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   125
	constant into the class that includes Chunker, so you can use it again
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   126
	and again, assuming you use a different file for each class.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   127
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   128
	It also automatically parses out other things that look like tokens, so
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   129
	you can easily have multiple, distinct documents all embedded into the
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   130
	__END__ block.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   131
	EOF
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   132
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   133
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   134
Rake::GemPackageTask.new( gem ) do |pkg|
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   135
	pkg.need_zip     = true
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   136
	pkg.need_tar     = true
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   137
	pkg.need_tar_bz2 = true
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   138
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   139
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   140
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   141
### Task: install
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   142
###
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   143
task :install_gem => [ :package ] do
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   144
	$stderr.puts
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   145
	installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" )
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   146
	installer.install
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   147
end
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   148
task :install => [ :install_gem ]
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   149
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   150
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   151
### Task: uninstall
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   152
###
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   153
task :uninstall_gem do
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   154
	uninstaller = Gem::Uninstaller.new( PKG_NAME )
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   155
	uninstaller.uninstall
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   156
end
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   157
task :uninstall => [ :uninstall_gem ]
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   158