diff --git a/HISTORY b/HISTORY new file mode 100644 index 0000000..7a95134 --- /dev/null +++ b/HISTORY @@ -0,0 +1,4 @@ += Changelog +== Version 0.0.1 + +* Initial public release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4fb9a29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2008 Jeremy Hinegardner + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..9f0704e --- /dev/null +++ b/README @@ -0,0 +1,21 @@ +== hightimes + +* Homepage +* rubyforge project +* email + +== DESCRIPTION + +== FEATURES + +== SYNOPSIS + +== CREDITS + +== LICENSE + +Copyright (c) Jeremy Hinegardner + +All rights reserved. + +See LICENSE and/or COPYING for details. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..291c4d1 --- /dev/null +++ b/Rakefile @@ -0,0 +1,60 @@ +#-- +# Copyright (c) 2008 Jeremy Hinegardner +# All rights reserved. See LICENSE and/or COPYING for details. +#++ + +#------------------------------------------------------------------------------- +# make sure our project's top level directory and the lib directory are added to +# the ruby search path. +#------------------------------------------------------------------------------- +$: << File.expand_path(File.join(File.dirname(__FILE__),"lib")) +$: << File.expand_path(File.dirname(__FILE__)) + + +#------------------------------------------------------------------------------- +# load the global project configuration and add in the top level clean and +# clobber tasks so that other tasks can utilize those constants if necessary +# This loads up the defaults for the whole project configuration +#------------------------------------------------------------------------------- +require 'rubygems' +require 'tasks/config.rb' +require 'rake/clean' + +#------------------------------------------------------------------------------- +# Main configuration for the project, these overwrite the items that are in +# tasks/config.rb +#------------------------------------------------------------------------------- +require 'hightimes' +Configuration.for("project") { + name "hightimes" + version Hightimes::VERSION + author "Jeremy Hinegardner" + email "jeremy@hinegardner.org" + homepage "http://hightimes.rubyforge.org/" +} + +#------------------------------------------------------------------------------- +# load up all the project tasks and setup the default task to be the +# test:default task. +#------------------------------------------------------------------------------- +Configuration.for("packaging").files.tasks.each do |tasklib| + import tasklib +end +task :default => 'test:default' + +#------------------------------------------------------------------------------- +# Finalize the loading of all pending imports and update the top level clobber +# task to depend on all possible sub-level tasks that have a name like +# ':clobber' in other namespaces. This allows us to say: +# +# rake clobber +# +# and it will get everything. +#------------------------------------------------------------------------------- +Rake.application.load_imports +Rake.application.tasks.each do |t| + if t.name =~ /:clobber/ then + task :clobber => [t.name] + end +end + diff --git a/ext/a.out b/ext/a.out new file mode 100755 index 0000000..64f5b86 Binary files /dev/null and b/ext/a.out differ diff --git a/ext/clock.c b/ext/clock.c new file mode 100644 index 0000000..0d79da1 --- /dev/null +++ b/ext/clock.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +int main( int argc, char** argv ) +{ + + AbsoluteTime start; + AbsoluteTime end; + Duration duration; + Nanoseconds elapsedNano; + uint64_t *nano; + + int count = atoi(argv[1]); + int i; + float secs; + + start = UpTime(); + + for( i = 0 ; i < count ; i++) { (void) getpid(); } + + end = UpTime(); + + elapsedNano = AbsoluteDeltaToNanoseconds( end, start ); + + nano = (uint64_t *)&elapsedNano; + + secs = (double)((*nano) * (1e-9)); + + printf("elapsed time : %lld\n", *nano); + + exit( 0 ); +} + diff --git a/ext/hires.c b/ext/hires.c new file mode 100644 index 0000000..e69de29 diff --git a/ext/hires.h b/ext/hires.h new file mode 100644 index 0000000..9dc3759 --- /dev/null +++ b/ext/hires.h @@ -0,0 +1,17 @@ +/* + * + */ +struct hires_unit +{ + char* name; + float factor; +}; +typedef struct hires_unit hires_unit_t; + +struct hires_time +{ + hires_value_t value; + hires_unit_t units; +}; + +typedef struct hires_time hires_time_t; diff --git a/ext/hires_osx.c b/ext/hires_osx.c new file mode 100644 index 0000000..53f6a08 --- /dev/null +++ b/ext/hires_osx.c @@ -0,0 +1,18 @@ +#include + +#ifndef __HIRES_OSX__ +#define __HIRES_OSX__ + +#include +extern hires_units = { "nanosecond", 1e-9 } + +hires_time_t hires_uptime() +{ + AbsoluteTime now_raw = UpTime(); + hires_time_t now; + + now.value = AbsoluteToNanoseconds( now_raw ); + now.units = hirest_units; + + return now; +} diff --git a/ext/mkrf_conf.rb b/ext/mkrf_conf.rb new file mode 100644 index 0000000..e69de29 diff --git a/ext/ul.c b/ext/ul.c new file mode 100644 index 0000000..0d72566 --- /dev/null +++ b/ext/ul.c @@ -0,0 +1,6 @@ +#include + +int main(void) +{ + printf("size of unsigned long : %d\n", sizeof( unsigned long ) ); +} diff --git a/gemspec.rb b/gemspec.rb new file mode 100644 index 0000000..77e3931 --- /dev/null +++ b/gemspec.rb @@ -0,0 +1,44 @@ +require 'rubygems' +require 'hightimes/version' +require 'tasks/config' + +Hightimes::GEM_SPEC = Gem::Specification.new do |spec| + proj = Configuration.for('project') + spec.name = proj.name + spec.version = Hightimes::VERSION + + spec.author = proj.author + spec.email = proj.email + spec.homepage = proj.homepage + spec.summary = proj.summary + spec.description = proj.description + spec.platform = Gem::Platform::RUBY + + + pkg = Configuration.for('packaging') + spec.files = pkg.files.all + spec.executables = pkg.files.bin.collect { |b| File.basename(b) } + + # add dependencies here + # spec.add_dependency("rake", ">= 0.8.1") + spec.add_dependency("configuration", ">= 0.0.5") + + + + if rdoc = Configuration.for_if_exist?('rdoc') then + spec.has_rdoc = true + spec.extra_rdoc_files = pkg.files.rdoc + spec.rdoc_options = rdoc.options + [ "--main" , rdoc.main_page ] + else + spec.has_rdoc = false + end + + if test = Configuration.for_if_exist?('testing') then + spec.test_files = test.files + end + + if rf = Configuration.for_if_exist?('rubyforge') then + spec.rubyforge_project = rf.project + end + +end diff --git a/lib/hightimes.rb b/lib/hightimes.rb new file mode 100644 index 0000000..e21dfc6 --- /dev/null +++ b/lib/hightimes.rb @@ -0,0 +1,57 @@ +#-- +# Copyright (c) 2008 Jeremy Hinegardner +# All rights reserved. See LICENSE and/or COPYING for details. +#++ + +module Hightimes + + # The root directory of the project is considered to be the parent directory + # of the 'lib' directory. + # + # returns:: [String] The full expanded path of the parent directory of 'lib' + # going up the path from the current file. Trailing + # File::SEPARATOR is guaranteed. + # + def self.root_dir + unless @root_dir + path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR) + lib_index = path_parts.rindex("lib") + @root_dir = path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR + end + return @root_dir + end + + # returns:: [String] The full expanded path of the +config+ directory + # below _root_dir_. All parameters passed in are joined onto the + # result. Trailing File::SEPARATOR is guaranteed if _args_ are + # *not* present. + # + def self.config_path(*args) + self.sub_path("config", *args) + end + + # returns:: [String] The full expanded path of the +data+ directory below + # _root_dir_. All parameters passed in are joined onto the + # result. Trailing File::SEPARATOR is guaranteed if + # _*args_ are *not* present. + # + def self.data_path(*args) + self.sub_path("data", *args) + end + + # returns:: [String] The full expanded path of the +lib+ directory below + # _root_dir_. All parameters passed in are joined onto the + # result. Trailing File::SEPARATOR is guaranteed if + # _*args_ are *not* present. + # + def self.lib_path(*args) + self.sub_path("lib", *args) + end + + def self.sub_path(sub,*args) + sp = ::File.join(root_dir, sub) + File::SEPARATOR + sp = ::File.join(sp, *args) if args + end + +end +require 'hightimes/version' diff --git a/lib/hightimes/version.rb b/lib/hightimes/version.rb new file mode 100644 index 0000000..84d0218 --- /dev/null +++ b/lib/hightimes/version.rb @@ -0,0 +1,26 @@ +#-- +# Copyright (c) 2008 Jeremy Hinegardner +# All rights reserved. See LICENSE and/or COPYING for details +#++ + +module Hightimes + module Version + MAJOR = 0 + MINOR = 0 + BUILD = 1 + + def to_a + [MAJOR, MINOR, BUILD] + end + + def to_s + to_a.join(".") + end + + module_function :to_a + module_function :to_s + + STRING = Version.to_s + end + VERSION = Version.to_s +end diff --git a/spec/hightimes_spec.rb b/spec/hightimes_spec.rb new file mode 100644 index 0000000..6932037 --- /dev/null +++ b/spec/hightimes_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path(File.join(File.dirname(__FILE__),"spec_helper.rb")) + +describe Hightimes do + before(:each) do + # some setup + end + + after(:each) do + # some cleanup + end + + it "should have some tests" do + violated("I just want to be tested... is that so wrong?") + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b7f9e42 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,5 @@ +require 'rubygems' +require 'spec' + +$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) +require 'hightimes' diff --git a/tasks/announce.rake b/tasks/announce.rake new file mode 100644 index 0000000..5a7d6fe --- /dev/null +++ b/tasks/announce.rake @@ -0,0 +1,38 @@ +require 'tasks/config' +#------------------------------------------------------------------------------- +# announcement methods +#------------------------------------------------------------------------------- + +proj_config = Configuration.for('project') +namespace :announce do + desc "create email for ruby-talk" + task :email do + info = Utils.announcement + + File.open("email.txt", "w") do |mail| + mail.puts "From: #{proj_config.author} <#{proj_config.email}>" + mail.puts "To: ruby-talk@ruby-lang.org" + mail.puts "Date: #{Time.now.rfc2822}" + mail.puts "Subject: [ANN] #{info[:subject]}" + mail.puts + mail.puts info[:title] + mail.puts + mail.puts info[:urls] + mail.puts + mail.puts info[:description] + mail.puts + mail.puts "{{ Release notes for Version #{Hightimes::VERSION} }}" + mail.puts + mail.puts info[:release_notes] + mail.puts + mail.puts info[:urls] + end + puts "Created the following as email.txt:" + puts "-" * 72 + puts File.read("email.txt") + puts "-" * 72 + end + + CLOBBER << "email.txt" +end + diff --git a/tasks/config.rb b/tasks/config.rb new file mode 100644 index 0000000..e70fd5a --- /dev/null +++ b/tasks/config.rb @@ -0,0 +1,98 @@ +require 'configuration' + +require 'rake' +require 'tasks/utils' + +#----------------------------------------------------------------------- +# General project configuration +#----------------------------------------------------------------------- +Configuration.for('project') { + name "FIXME: NAME" + version "FIXME: 0.0.0" + author "FIXME: The Author" + email "FIXME: author@example.com" + homepage "FIXME: http://project.example.com" + description Utils.section_of("README", "description") + summary description.split(".").first + history "HISTORY" + license FileList["LICENSE", "COPYING"] + readme "README" +} + +#----------------------------------------------------------------------- +# Packaging +#----------------------------------------------------------------------- +Configuration.for('packaging') { + # files in the project + proj_conf = Configuration.for('project') + files { + bin FileList["bin/*"] + lib FileList["lib/**/*.rb"] + test FileList["spec/**/*.rb", "test/**/*.rb"] + data FileList["data/**/*"] + tasks FileList["tasks/**/*.r{ake,b}"] + rdoc FileList[proj_conf.readme, proj_conf.history, + proj_conf.license] + lib + all bin + lib + test + data + rdoc + tasks + } + + # ways to package the results + formats { + tgz true + zip true + gem Configuration::Table.has_key?('gem') + } +} + +#----------------------------------------------------------------------- +# Gem packaging +#----------------------------------------------------------------------- +Configuration.for("gem") { + spec "gemspec.rb" + Configuration.for('packaging').files.all << spec +} + +#----------------------------------------------------------------------- +# Testing +# - change mode to 'testunit' to use unit testing +#----------------------------------------------------------------------- +Configuration.for('test') { + mode "spec" + files Configuration.for("packaging").files.test + options %w[ --format specdoc --color ] + ruby_opts %w[ ] +} + +#----------------------------------------------------------------------- +# Rcov +#----------------------------------------------------------------------- +Configuration.for('rcov') { + output_dir "coverage" + libs %w[ lib ] + rcov_opts %w[ --html ] + ruby_opts %w[ ] + test_files Configuration.for('packaging').files.test +} + +#----------------------------------------------------------------------- +# Rdoc +#----------------------------------------------------------------------- +Configuration.for('rdoc') { + files Configuration.for('packaging').files.rdoc + main_page files.first + title Configuration.for('project').name + options %w[ --line-numbers --inline-source ] + output_dir "doc" +} + +#----------------------------------------------------------------------- +# Rubyforge +#----------------------------------------------------------------------- +Configuration.for('rubyforge') { + project "FIXME: rubyforge project" + user "FIXME: username" + host "rubyforge.org" + rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}" +} + + diff --git a/tasks/distribution.rake b/tasks/distribution.rake new file mode 100644 index 0000000..005c69d --- /dev/null +++ b/tasks/distribution.rake @@ -0,0 +1,38 @@ +require 'tasks/config' + +#------------------------------------------------------------------------------- +# Distribution and Packaging +#------------------------------------------------------------------------------- +if pkg_config = Configuration.for_if_exist?("packaging") then + + require 'gemspec' + require 'rake/gempackagetask' + require 'rake/contrib/sshpublisher' + + namespace :dist do + + Rake::GemPackageTask.new(Hightimes::GEM_SPEC) do |pkg| + pkg.need_tar = pkg_config.formats.tgz + pkg.need_zip = pkg_config.formats.zip + end + + desc "Install as a gem" + task :install => [:clobber, :package] do + sh "sudo gem install pkg/#{Hightimes::GEM_SPEC.full_name}.gem" + end + + desc "Uninstall gem" + task :uninstall do + sh "sudo gem uninstall -x #{Hightimes::GEM_SPEC.name}" + end + + desc "dump gemspec" + task :gemspec do + puts Hightimes::GEM_SPEC.to_ruby + end + + desc "reinstall gem" + task :reinstall => [:uninstall, :repackage, :install] + + end +end diff --git a/tasks/documentation.rake b/tasks/documentation.rake new file mode 100644 index 0000000..9e66e6b --- /dev/null +++ b/tasks/documentation.rake @@ -0,0 +1,31 @@ +require 'tasks/config' + +#----------------------------------------------------------------------- +# Documentation +#----------------------------------------------------------------------- + +if rdoc_config = Configuration.for_if_exist?('rdoc') then + + namespace :doc do + + require 'rake/rdoctask' + + # generating documentation locally + Rake::RDocTask.new do |rdoc| + rdoc.rdoc_dir = rdoc_config.output_dir + rdoc.options = rdoc_config.options + rdoc.rdoc_files = rdoc_config.files + rdoc.title = rdoc_config.title + rdoc.main = rdoc_config.main_page + end + + if rubyforge_config = Configuration.for_if_exist?('rubyforge') then + desc "Deploy the RDoc documentation to #{rubyforge_config.rdoc_location}" + task :deploy => :rerdoc do + sh "rsync -zav --delete #{rdoc_config.output_dir}/ #{rubyforge_config.rdoc_location}" + end + end + + end +end + diff --git a/tasks/extension.rake b/tasks/extension.rake new file mode 100644 index 0000000..c877d58 --- /dev/null +++ b/tasks/extension.rake @@ -0,0 +1,15 @@ +namespace :extension do + desc "Build the extension(s)" + task :build do + Hightimes::GEM_SPEC.extensions.each do |extension| + path = Pathname.new(extension) + parts = path.split + conf = parts.last + Dir.chdir(path.dirname) do |d| + ruby conf.to_s + sh "rake default" + end + end + end +end + diff --git a/tasks/rspec.rake b/tasks/rspec.rake new file mode 100644 index 0000000..c14f5bf --- /dev/null +++ b/tasks/rspec.rake @@ -0,0 +1,29 @@ + +require 'tasks/config' + +#-------------------------------------------------------------------------------- +# configuration for running rspec. This shows up as the test:default task +#-------------------------------------------------------------------------------- +if spec_config = Configuration.for_if_exist?("test") then + if spec_config.mode == "spec" then + namespace :test do + + task :default => :spec + + require 'spec/rake/spectask' + Spec::Rake::SpecTask.new do |r| + r.ruby_opts = spec_config.ruby_opts + r.libs = [ Hightimes.lib_path, + Hightimes.root_dir ] + r.spec_files = spec_config.files + r.spec_opts = spec_config.options + + if rcov_config = Configuration.for_if_exist?('rcov') then + r.rcov = true + r.rcov_dir = rcov_config.output_dir + r.rcov_opts = rcov_config.rcov_opts + end + end + end + end +end diff --git a/tasks/rubyforge.rake b/tasks/rubyforge.rake new file mode 100644 index 0000000..55eae71 --- /dev/null +++ b/tasks/rubyforge.rake @@ -0,0 +1,48 @@ +require 'tasks/config' + +#----------------------------------------------------------------------- +# Rubyforge additions to the task library +#----------------------------------------------------------------------- +if rf_conf = Configuration.for_if_exist?("rubyforge") then + + abort("rubyforge gem not installed 'gem install rubyforge'") unless Utils.try_require('rubyforge') + + proj_conf = Configuration.for('project') + + namespace :dist do + desc "Release files to rubyforge" + task :rubyforge => [:clean, :package] do + + rubyforge = RubyForge.new + + # make sure this release doesn't already exist + releases = rubyforge.autoconfig['release_ids'] + if releases.has_key?(Hightimes::GEM_SPEC.name) and releases[Hightimes::GEM_SPEC.name][Hightimes::VERSION] then + abort("Release #{Hightimes::VERSION} already exists! Unable to release.") + end + + config = rubyforge.userconfig + config["release_notes"] = proj_conf.description + config["release_changes"] = Utils.release_notes_from(proj_conf.history)[Hightimes::VERSION] + config["Prefomatted"] = true + + puts "Uploading to rubyforge..." + files = FileList[File.join("pkg","#{Hightimes::GEM_SPEC.name}-#{Hightimes::VERSION}*.*")].to_a + rubyforge.login + rubyforge.add_release(Hightimes::GEM_SPEC.rubyforge_project, Hightimes::GEM_SPEC.name, Hightimes::VERSION, *files) + puts "done." + end + end + + namespace :announce do + desc "Post news of #{proj_conf.name} to #{rf_conf.project} on rubyforge" + task :rubyforge do + info = Utils.announcement + rubyforge = RubyForge.new + rubyforge.login + rubyforge.post_news(rf_conf.project, info[:subject], "#{info[:title]}\n\n#{info[:urls]}\n\n#{info[:release_notes]}") + puts "Posted to rubyforge" + end + + end +end diff --git a/tasks/utils.rb b/tasks/utils.rb new file mode 100644 index 0000000..c2f97a7 --- /dev/null +++ b/tasks/utils.rb @@ -0,0 +1,80 @@ +require 'hightimes/version' + +#------------------------------------------------------------------------------- +# Additions to the Configuration class that are useful +#------------------------------------------------------------------------------- +class Configuration + class << self + def exist?( name ) + Configuration::Table.has_key?( name ) + end + + def for_if_exist?( name ) + if self.exist?( name ) then + self.for( name ) + end + end + end +end + +#------------------------------------------------------------------------------- +# some useful utilitiy methods for the tasks +#------------------------------------------------------------------------------- +module Utils + class << self + + # Try to load the given _library_ using the built-in require, but do not + # raise a LoadError if unsuccessful. Returns +true+ if the _library_ was + # successfully loaded; returns +false+ otherwise. + # + def try_require( lib ) + require lib + true + rescue LoadError + false + end + + # partition an rdoc file into sections, and return the text of the section + # given. + def section_of(file, section_name) + File.read(file).split(/^(?==)/).each do |section| + lines = section.split("\n") + return lines[1..-1].join("\n").strip if lines.first =~ /#{section_name}/i + end + nil + end + + # Get an array of all the changes in the application for a particular + # release. This is done by looking in the history file and grabbing the + # information for the most recent release. The history file is assumed to + # be in RDoc format and version release are 2nd tier sections separated by + # '== Version X.Y.Z' + # + # returns:: A hash of notes keyed by version number + # + def release_notes_from(history_file) + releases = {} + File.read(history_file).split(/^(?==)/).each do |section| + lines = section.split("\n") + md = %r{Version ((\w+\.)+\w+)}.match(lines.first) + next unless md + releases[md[1]] = lines[1..-1].join("\n").strip + end + return releases + end + + # return a hash of useful information for the latest release + # urls, subject, title, description and latest release notes + # + def announcement + cfg = Configuration.for("project") + { + :subject => "#{cfg.name} #{Hightimes::VERSION} Released", + :title => "#{cfg.name} version #{Hightimes::VERSION} has been released.", + :urls => "#{cfg.homepage}", + :description => "#{cfg.description.rstrip}", + :release_notes => Utils.release_notes_from(cfg.history)[Hightimes::VERSION].rstrip + } + end + end +end # << self