From b5700bdaa3b5fcc574974fc253db6f4cc67027cb Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Thu, 6 Jul 2017 11:35:52 +0200 Subject: [PATCH] fix some more issues --- bin/bundix | 17 +++++++++++------ bundix.gemspec | 4 +++- default.nix | 2 +- lib/bundix.rb | 4 +++- lib/bundix/source.rb | 10 ++++------ lib/bundix/version.rb | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/bin/bundix b/bin/bundix index 28f4937..a4bb7ca 100755 --- a/bin/bundix +++ b/bin/bundix @@ -83,14 +83,15 @@ if options[:magic] end if options[:init] + shell_nix = File.read(File.expand_path('../template/shell.nix', __dir__)) + shell_nix.gsub!('PROJECT', File.basename(Dir.pwd)) + shell_nix.gsub!('RUBY', options[:ruby]) + shell_nix.gsub!('LOCKFILE', "./#{Pathname(options[:lockfile]).relative_path_from(Pathname('./'))}") + shell_nix.gsub!('GEMSET', "./#{Pathname(options[:gemset]).relative_path_from(Pathname('./'))}") if File.file?('shell.nix') - warn "won't override existing shell.nix" + warn "won't override existing shell.nix but here is what it'd look like:" + puts shell_nix else - shell_nix = File.read(File.expand_path('../template/shell.nix', __dir__)) - shell_nix.gsub!('PROJECT', File.basename(Dir.pwd)) - shell_nix.gsub!('RUBY', options[:ruby]) - shell_nix.gsub!('LOCKFILE', "./#{Pathname(options[:lockfile]).relative_path_from(Pathname('./'))}") - shell_nix.gsub!('GEMSET', "./#{Pathname(options[:gemset]).relative_path_from(Pathname('./'))}") File.write('shell.nix', shell_nix) end end @@ -99,6 +100,10 @@ if options[:lock] lock = !File.file?(options[:lockfile]) lock ||= File.mtime(options[:gemfile]) > File.mtime(options[:lockfile]) if lock + ENV.delete('BUNDLE_PATH') + ENV.delete('BUNDLE_GEMFILE') + ENV.delete('BUNDLE_FROZEN') + ENV.delete('BUNDLE_BIN_PATH') system('bundle', 'lock') fail 'bundle lock failed' unless $?.success? end diff --git a/bundix.gemspec b/bundix.gemspec index 00a507b..1efe828 100644 --- a/bundix.gemspec +++ b/bundix.gemspec @@ -8,7 +8,9 @@ Gem::Specification.new do |s| s.summary = 'Creates Nix packages from Gemfiles.' s.description = 'Creates Nix packages from Gemfiles.' s.authors = ["Michael 'manveru' Fellinger"] - s.files = Dir['bin/*'] + Dir['lib/**/*.{rb,nix}'] + s.files = Dir['bin/*'] + + Dir['lib/**/*.{rb,nix}'] + + Dir['template/**/*.{rb,nix}'] s.bindir = 'bin' s.executables = ['bundix'] s.add_runtime_dependency 'bundler', '~> 1.11' diff --git a/default.nix b/default.nix index 43b5145..62bc6d1 100644 --- a/default.nix +++ b/default.nix @@ -6,7 +6,7 @@ nix-prefetch-git ? pkgs.nix-prefetch-git, }: pkgs.stdenv.mkDerivation rec { - version = "2.3.0"; + version = "2.3.1"; name = "bundix"; src = ./.; phases = "installPhase"; diff --git a/lib/bundix.rb b/lib/bundix.rb index b5c6b36..67d01a9 100755 --- a/lib/bundix.rb +++ b/lib/bundix.rb @@ -38,7 +38,9 @@ def convert gem = find_cached_spec(spec, cache) || convert_spec(spec, cache) gems.merge!(gem) - gems[spec.name]['dependencies'] = spec.dependencies.map(&:name) - ['bundler'] + if spec.dependencies.any? + gems[spec.name]['dependencies'] = spec.dependencies.map(&:name) - ['bundler'] + end end end diff --git a/lib/bundix/source.rb b/lib/bundix/source.rb index 316c21b..55b85b0 100644 --- a/lib/bundix/source.rb +++ b/lib/bundix/source.rb @@ -25,7 +25,8 @@ def download(file, url) uri.user = nil uri.password = nil end - open(uri, 'r', 0600, open_options) do |net| + + open(uri.to_s, 'r', 0600, open_options) do |net| File.open(file, 'wb+') { |local| File.copy_stream(net, local) } @@ -37,10 +38,7 @@ def nix_prefetch_url(url) FileUtils.mkdir_p dir file = File.join(dir, url.gsub(/[^\w-]+/, '_')) - unless File.size?(file) - download(file, url) - end - + download(file, url) unless File.size?(file) return unless File.size?(file) sh('nix-prefetch-url', '--type', 'sha256', "file://#{file}") @@ -62,7 +60,7 @@ def fetch_local_hash(spec) spec.source.caches.each do |cache| path = File.join(cache, "#{spec.name}-#{spec.version}.gem") next unless File.file?(path) - hash = nix_prefetch_url("file://#{path}")[SHA256_32] + hash = nix_prefetch_url(path)[SHA256_32] return hash if hash end diff --git a/lib/bundix/version.rb b/lib/bundix/version.rb index be60a8c..9144679 100644 --- a/lib/bundix/version.rb +++ b/lib/bundix/version.rb @@ -1,3 +1,3 @@ class Bundix - VERSION = '2.3.0' + VERSION = '2.3.1' end