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