Skip to content

Commit

Permalink
Fix stock lilypond includes, include search path (close #44, #43)
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Jan 3, 2017
1 parent 6803044 commit 8b5c02f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
20 changes: 18 additions & 2 deletions lib/lyp/lilypond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parse_lilypond_arg(arg, argv, argv_clean, options)
when '-A', '--auto-install-deps'
options[:resolve] = true
when '-c', '--cropped'
argv_clean += ['-dbackend=eps', '-daux-files=#f']
argv_clean.concat ['-dbackend=eps', '-daux-files=#f']
when '-E', '--env'
unless ENV['LILYPOND_VERSION']
STDERR.puts "$LILYPOND_VERSION not set"
Expand All @@ -33,6 +33,11 @@ def parse_lilypond_arg(arg, argv, argv_clean, options)
options[:use_version] = ENV['LILYPOND_VERSION']
when '-F', '--force-version'
options[:force_version] = true
when '-I', '--include'
path = argv.shift
options[:include_paths] ||= []
options[:include_paths] << path
argv_clean << "--include=#{path}"
when '-n', '--install'
options[:install] = true
when '-O', '--open'
Expand All @@ -46,7 +51,7 @@ def parse_lilypond_arg(arg, argv, argv_clean, options)
when '-R', '--raw'
options[:raw] = true
when '-S', '--snippet'
argv_clean += ['-dbackend=eps', '-daux-files=#f', '--png', '-dresolution=600']
argv_clean.concat ['-dbackend=eps', '-daux-files=#f', '--png', '-dresolution=600']
options[:snippet_paper_preamble] = true
when '-u', '--use'
options[:use_version] = argv.shift
Expand Down Expand Up @@ -98,6 +103,9 @@ def get_file_expected_version(file_path)
end

def compile(argv, opts = {})
opts[:include_paths] ||= []
opts[:include_paths] << current_lilypond_include_path

unless argv.last == '-'
fn = Lyp.wrap(argv.pop, opts)
argv << fn
Expand Down Expand Up @@ -159,11 +167,19 @@ def current_lilypond
settings[:current]
end

def current_lilypond_base_path
File.expand_path("#{File.dirname(current_lilypond)}/..")
end

def current_lilypond_bin_path
lilypond = current_lilypond
lilypond && File.dirname(lilypond)
end

def current_lilypond_include_path
File.join(current_lilypond_base_path, "share/lilypond/current/ly")
end

def current_lilypond_version
path = current_lilypond
version = File.basename(File.expand_path("#{File.dirname(path)}/../.."))
Expand Down
16 changes: 12 additions & 4 deletions lib/lyp/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,21 @@ def process_include_command(ref, dir, leaf, opts, location)
return if $1 == 'null'
ref = $2
end
qualified_path = File.expand_path(ref, dir)

unless File.file?(qualified_path)
error("Invalid include file specified in %s", location)
full_path = find_include_file(ref, dir, location)
queue_file_for_processing(full_path, leaf)
end

def find_include_file(ref, dir, location)
search_paths = [dir]
search_paths += @opts[:include_paths] if @opts[:include_paths]

search_paths.each do |path|
full_path = File.expand_path(ref, path)
return full_path if File.file?(full_path)
end

queue_file_for_processing(qualified_path, leaf)
error("Missing include file specified in %s", location)
end

def process_require_command(ref, dir, leaf, opts, location)
Expand Down
9 changes: 4 additions & 5 deletions lib/lyp/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ def test_rugged_gem!
end

def find_rugged_gem
found = Gem::Specification.find_all_by_name('rugged').find do |s|
RUGGED_REQ =~ s.version
end

dep = Gem::Dependency.new("rugged", RUGGED_REQ)
found = !dep.matching_specs.empty?

require_rugged_gem if found
found
end

def require_rugged_gem
gem 'rugged', RUGGED_REQ.to_s
req_ext 'rugged'
Expand Down
1 change: 1 addition & 0 deletions spec/include_files/mydeutsch.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\include "deutsch.ly"
18 changes: 18 additions & 0 deletions spec/lilypond_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,23 @@
end
end
end

it "correctly passes include paths to resolver" do
with_lilyponds(:tmp, copy_from: :empty) do
with_packages(:tmp, copy_from: :empty) do
Lyp::Lilypond.install('2.19.37', silent: true)

# fn = "#{$spec_dir}/user_files/include_stock.ly"
# expect {Lyp::Lilypond.compile([fn])}.to_not raise_error

fn = "#{$spec_dir}/user_files/include_path.ly"
include_path = "#{$spec_dir}/include_files"

opts, argv = Lyp::Lilypond.preprocess_argv(["--include", include_path, fn])

expect {Lyp::Lilypond.compile(argv, opts)}.to_not raise_error
end
end
end
end

2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Bundler.setup(:default, :spec)

$spec_dir = File.dirname(__FILE__)
require File.join(File.expand_path($spec_dir), '../lib/lyp')
require 'fileutils'
Expand Down
2 changes: 2 additions & 0 deletions spec/user_files/include_path.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\include "mydeutsch.ly"

2 changes: 2 additions & 0 deletions spec/user_files/include_stock.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\include "deutsch.ly"

0 comments on commit 8b5c02f

Please sign in to comment.