chunker/Rakefile
author Mahlon E. Smith <mahlon@martini.nu>
Sat, 22 Jan 2011 01:20:16 -0800
branchruby-modules
changeset 5 3d9956beee25
parent 4 01a3332bfe0a
child 6 62a5ac525ce8
permissions -rw-r--r--
Bug metadata has been initialized.
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
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     4
require 'rubygems'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     5
require 'pathname'
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     6
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
     7
require 'rake'
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
     8
require 'rspec'
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
     9
require 'rspec/core/rake_task'
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    10
require 'rake/packagetask'
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    11
require 'rake/gempackagetask'
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    12
require 'rubygems/installer'
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    13
require 'rubygems/uninstaller'
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    14
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    15
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    16
######################################################################
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    17
### 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
    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
BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    21
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    22
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    23
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    24
SPECDIR    = BASEDIR + 'spec'
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    25
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' )
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    26
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    27
LIBDIR    = BASEDIR + 'lib'
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    28
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb')
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    29
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    30
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    31
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    32
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    33
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    34
### H E L P E R S
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    35
######################################################################
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
### 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
    38
### 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
    39
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    40
def find_pattern( file, pattern )
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    41
	ver = nil
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    42
	File.open( file ) do |f|
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    43
		ver = f.each do |line|
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    44
			break $1 if line =~ pattern
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    45
		end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    46
	end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    47
	return ver.is_a?( String ) ? ver : 'UNKNOWN'
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
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
    50
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    51
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    52
### 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
    53
######################################################################
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
PKG_NAME      = 'chunker'
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    56
PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ )
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    57
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    58
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    59
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    60
######################################################################
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    61
### T A S K S
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
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    64
task :test    => 'test:spec'
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    65
task :default => :test
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    66
# task :default => [ :test, :package ]
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    67
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    68
namespace :test do
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    69
	desc 'Generate verbose and pretty output'
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    70
	RSpec::Core::RakeTask.new( :spec ) do |task|
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    71
		task.pattern = SPEC_FILES
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    72
		task.rspec_opts  = ['-b', '-fd', '-c']
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    73
	end
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    74
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    75
	desc 'Generate quiet non-colored plain-text output'
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    76
	RSpec::Core::RakeTask.new( :quiet ) do |task|
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    77
		task.pattern = SPEC_FILES
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    78
		task.rspec_opts  = ['-f', 'p']
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    79
	end
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    80
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    81
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    82
### Task: generate ctags
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    83
### 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
    84
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    85
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
    86
task :ctags do
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    87
	sh "ctags -R #{LIBDIR}"
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    88
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    89
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
### Task: Create gem from source
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    92
###
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
    93
gem = Gem::Specification.new do |gem|
2
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
4
01a3332bfe0a Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents: 3
diff changeset
    96
	gem.version           = PKG_VERSION
2
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.has_rdoc          = true
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   101
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   102
	gem.files = RELEASE_FILES.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   103
		collect {|f| f.relative_path_from(BASEDIR).to_s }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   104
	gem.test_files	= SPEC_FILES.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   105
		collect {|f| f.relative_path_from(BASEDIR).to_s }
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   106
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   107
	gem.description = <<-EOF
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   108
	Ruby provides an automatic constant called DATA, which is an IO object
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   109
	that references all text in the current file under an __END__ token.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   110
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   111
	I find it convenient to use the __END__ area to store all sorts of
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   112
	stuff, rather than have to worry about distributing separate files.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   113
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   114
	The DATA constant is determined from whatever ruby believes $0 to be.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   115
	It doesn't work inside of other required libraries, so you'll see stuff
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   116
	like this all the time:
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   117
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   118
	END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   119
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   120
	It works, but it's more work than I want to do.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   121
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   122
	Chunker solves this by parsing __END__ tokens for you, and making it
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   123
	available in the form of a 'DATA_END' constant.  It installs this
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   124
	constant into the class that includes Chunker, so you can use it again
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   125
	and again, assuming you use a different file for each class.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   126
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   127
	It also automatically parses out other things that look like tokens, so
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   128
	you can easily have multiple, distinct documents all embedded into the
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   129
	__END__ block.
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   130
	EOF
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   131
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   132
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   133
Rake::GemPackageTask.new( gem ) do |pkg|
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   134
	pkg.need_zip     = true
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   135
	pkg.need_tar     = true
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   136
	pkg.need_tar_bz2 = true
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   137
end
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   138
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
### Task: install
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   141
###
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   142
task :install_gem => [ :package ] do
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   143
	$stderr.puts
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   144
	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
   145
	installer.install
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   146
end
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   147
task :install => [ :install_gem ]
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   148
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   149
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   150
### Task: uninstall
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   151
###
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   152
task :uninstall_gem do
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   153
	uninstaller = Gem::Uninstaller.new( PKG_NAME )
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   154
	uninstaller.uninstall
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   155
end
2
e5c705047540 * Rename 'markers' to 'token'
mahlon
parents: 1
diff changeset
   156
task :uninstall => [ :uninstall_gem ]
1
9e127bf6e84f Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff changeset
   157