Skip to content

Commit

Permalink
Add basic debug support
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Jul 12, 2016
1 parent beb7d51 commit a2ef86a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

* Write debug output to file, if the `THERMITE_DEBUG_FILENAME` environment variable is set

### Changed

* Relaxed rake version requirement
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ repository contains an example of using Thermite with [ruru](https://github.com/
to provide a `String.blank?` speedup extension. While the example uses ruru, this gem should be
usable with any method of integrating Rust and Ruby that you choose.

### Troubleshooting

Debug statements can be written to a file specified by the `THERMITE_DEBUG_FILENAME` environment
variable.

## FAQ

### Why is it named Thermite?
Expand Down
7 changes: 7 additions & 0 deletions lib/thermite/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def initialize(options = {})
@options = options
end

#
# Location to emit debug output, if not `nil`. Defaults to `nil`.
#
def debug_filename
@debug_filename ||= ENV['THERMITE_DEBUG_FILENAME']
end

#
# The file extension of the compiled shared Rust library.
#
Expand Down
6 changes: 5 additions & 1 deletion lib/thermite/github_release_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def download_binary
def download_cargo_version_from_github_release
version = config.toml[:package][:version]
tag = options.fetch(:git_tag_format, 'v%s') % version
if (tgz = download_binary_from_github_release(github_download_uri(tag, version), version))
uri = github_download_uri(tag, version)
if (tgz = download_binary_from_github_release(uri, version))
debug "Unpacking GitHub release from Cargo version: #{File.basename(uri)}"
unpack_tarball(tgz)
true
end
Expand All @@ -73,6 +75,7 @@ def download_latest_binary_from_github_release
each_github_release(github_uri) do |version, download_uri|
tgz = download_binary_from_github_release(download_uri, version)
next unless tgz
debug "Unpacking GitHub release: #{File.basename(download_uri)}"
unpack_tarball(tgz)
installed_binary = true
break
Expand Down Expand Up @@ -123,6 +126,7 @@ def unpack_tarball(tgz)
tar.each do |entry|
path = entry.header.name
next if path.end_with?('/')
debug "Unpacking file: #{path}"
File.open(path, 'wb') do |f|
f.write(entry.read)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/thermite/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require 'thermite/config'
require 'thermite/github_release_binary'
require 'thermite/package'
require 'thermite/util'

#
# Helpers for Rust-based Ruby extensions.
Expand All @@ -41,6 +42,7 @@ class Tasks < Rake::TaskLib
include Thermite::Cargo
include Thermite::GithubReleaseBinary
include Thermite::Package
include Thermite::Util

#
# The configuration used for the Rake tasks.
Expand Down
34 changes: 34 additions & 0 deletions lib/thermite/util.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
#
# Copyright (c) 2016 Mark Lee and contributors
#
# 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.

module Thermite
#
# Utility methods
#
module Util
def debug(msg)
# Should probably replace with a Logger
if config.debug_filename
@debug ||= File.open(config.debug_filename, 'w')
@debug.write("#{msg}\n")
end
end
end
end

0 comments on commit a2ef86a

Please sign in to comment.