From a2ef86a5a5c36b3e377f22025c3060eb1562934a Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 11 Jul 2016 22:49:43 -0700 Subject: [PATCH] Add basic debug support --- NEWS.md | 4 ++++ README.md | 5 ++++ lib/thermite/config.rb | 7 ++++++ lib/thermite/github_release_binary.rb | 6 ++++- lib/thermite/tasks.rb | 2 ++ lib/thermite/util.rb | 34 +++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/thermite/util.rb diff --git a/NEWS.md b/NEWS.md index 4343181..7706a17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/README.md b/README.md index 7316392..d148a88 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/lib/thermite/config.rb b/lib/thermite/config.rb index 168f4f8..de0e790 100644 --- a/lib/thermite/config.rb +++ b/lib/thermite/config.rb @@ -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. # diff --git a/lib/thermite/github_release_binary.rb b/lib/thermite/github_release_binary.rb index 9d3b40e..8a9e23a 100644 --- a/lib/thermite/github_release_binary.rb +++ b/lib/thermite/github_release_binary.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/thermite/tasks.rb b/lib/thermite/tasks.rb index 2c53045..2da431f 100644 --- a/lib/thermite/tasks.rb +++ b/lib/thermite/tasks.rb @@ -24,6 +24,7 @@ require 'thermite/config' require 'thermite/github_release_binary' require 'thermite/package' +require 'thermite/util' # # Helpers for Rust-based Ruby extensions. @@ -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. diff --git a/lib/thermite/util.rb b/lib/thermite/util.rb new file mode 100644 index 0000000..1e69c6e --- /dev/null +++ b/lib/thermite/util.rb @@ -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