Skip to content

Commit

Permalink
fix some more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Jul 6, 2017
1 parent 930a29e commit b5700bd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
17 changes: 11 additions & 6 deletions bin/bundix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion bundix.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion lib/bundix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 4 additions & 6 deletions lib/bundix/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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}")
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/bundix/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Bundix
VERSION = '2.3.0'
VERSION = '2.3.1'
end

0 comments on commit b5700bd

Please sign in to comment.