Class: Bundix
- Inherits:
-
Object
- Object
- Bundix
- Defined in:
- lib/bundix.rb,
lib/bundix/source.rb,
lib/bundix/version.rb
Defined Under Namespace
Classes: Source
Constant Summary collapse
- NIX_INSTANTIATE =
'nix-instantiate'- NIX_PREFETCH_URL =
'nix-prefetch-url'- NIX_PREFETCH_GIT =
'nix-prefetch-git'- NIX_BUILD =
'nix-build'- NIX_HASH =
'nix-hash'- NIX_SHELL =
'nix-shell'- FETCHURL_FORCE =
File.('../bundix/fetchurl-force.nix', __FILE__)
- FETCHURL_FORCE_CHECK =
lambda do |_, out| out =~ /success! failing outer nix build.../ end
- SHA256_32 =
%r(^[a-z0-9]{52}$)- SHA256_16 =
%r(^[a-f0-9]{64}$)- VERSION =
'2.3.0'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #convert ⇒ Object
- #convert_spec(spec, cache) ⇒ Object
- #find_cached_spec(spec, cache) ⇒ Object
-
#initialize(options) ⇒ Bundix
constructor
A new instance of Bundix.
- #parse_gemset ⇒ Object
- #parse_lockfile ⇒ Object
Constructor Details
#initialize(options) ⇒ Bundix
Returns a new instance of Bundix.
28 29 30 |
# File 'lib/bundix.rb', line 28 def initialize() = { quiet: false, tempfile: nil }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/bundix.rb', line 26 def end |
Class Method Details
.object2nix(obj, level = 2, out = '') ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/bundix.rb', line 86 def self.object2nix(obj, level = 2, out = '') case obj when Hash out << "{\n" obj.sort_by{|k, v| k.to_s.downcase }.each do |(k, v)| out << ' ' * level if k.to_s =~ /^[a-zA-Z_-]+[a-zA-Z0-9_-]*$/ out << k.to_s else object2nix(k, level + 2, out) end out << ' = ' object2nix(v, level + 2, out) out << (v.is_a?(Hash) ? "\n" : ";\n") end out << (' ' * (level - 2)) << (level == 2 ? '}' : '};') when Array out << '[' << obj.sort.map{|o| o.to_str.dump }.join(' ') << ']' when String out << obj.dump when Symbol out << obj.to_s.dump when true, false out << obj.to_s else fail obj.inspect end end |
.sh(*args, &block) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/bundix.rb', line 115 def self.sh(*args, &block) out, status = Open3.capture2e(*args) unless block_given? ? block.call(status, out) : status.success? puts "$ #{args.join(' ')}" if $VERBOSE puts out if $VERBOSE fail "command execution failed: #{status}" end out end |
Instance Method Details
#convert ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bundix.rb', line 32 def convert cache = parse_gemset lock = parse_lockfile # reverse so git comes last lock.specs.reverse_each.with_object({}) do |spec, gems| gem = find_cached_spec(spec, cache) || convert_spec(spec, cache) gems.merge!(gem) gems[spec.name]['dependencies'] = spec.dependencies.map(&:name) - ['bundler'] end end |
#convert_spec(spec, cache) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/bundix.rb', line 45 def convert_spec(spec, cache) {spec.name => {version: spec.version.to_s, source: Source.new(spec).convert}} rescue => ex warn "Skipping #{spec.name}: #{ex}" puts ex.backtrace {spec.name => {}} end |
#find_cached_spec(spec, cache) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bundix.rb', line 53 def find_cached_spec(spec, cache) name, cached = cache.find{|k, v| next unless k == spec.name next unless cached_source = v['source'] case spec_source = spec.source when Bundler::Source::Git next unless cached_source['type'] == 'git' next unless cached_rev = cached_source['rev'] next unless spec_rev = spec_source.['revision'] spec_rev == cached_rev when Bundler::Source::Rubygems next unless cached_source['type'] == 'gem' v['version'] == spec.version.to_s end } {name => cached} if cached end |
#parse_gemset ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/bundix.rb', line 74 def parse_gemset path = File.([:gemset]) return {} unless File.file?(path) json = Bundix.sh( NIX_INSTANTIATE, '--eval', '-E', "builtins.toJSON(import #{path})") JSON.parse(json.strip.gsub(/\\"/, '"')[1..-2]) end |
#parse_lockfile ⇒ Object
82 83 84 |
# File 'lib/bundix.rb', line 82 def parse_lockfile Bundler::LockfileParser.new(File.read([:lockfile])) end |