Skip to content

Commit

Permalink
Merge remote-tracking branch 'alekstorm/pathfile_search_path'
Browse files Browse the repository at this point in the history
  • Loading branch information
cespare committed Sep 20, 2012
2 parents 20ebc0c + 8436336 commit b47c626
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/pathological/base.rb
Expand Up @@ -89,20 +89,23 @@ def self.find_pathfile(directory = nil)
#
# @param [String] copy_outside_paths the directory to stage dependencies in
# @param [String] dependency_directory the subdir within destination to put dependencies in
# @param [String] pathfile_search_path the directory at which to begin the search for the Pathfile by
# walking up the directory tree
#
# TODO(ev): Break this function up into a set of more functional primitives
def self.copy_outside_paths!(destination, dependency_directory = "pathological_dependencies")
def self.copy_outside_paths!(destination, options = {})
options = {:dependency_directory => "pathological_dependencies"}.merge(options)
saved_exclude_root = @@exclude_root
begin
self.excluderoot_mode
pathfile = self.find_pathfile
pathfile = self.find_pathfile(options[:pathfile_search_path])
# Nothing to do if there's no Pathfile
return unless pathfile && File.file?(pathfile)

foreign_paths = self.find_load_paths(pathfile).uniq
return if foreign_paths.empty?

path_root = File.join(destination, dependency_directory)
path_root = File.join(destination, options[:dependency_directory])
FileUtils.mkdir_p path_root

# Copy in each path and save the relative paths to write to the rewritten Pathfile. We copy each unique
Expand All @@ -116,7 +119,7 @@ def self.copy_outside_paths!(destination, dependency_directory = "pathological_d
FileUtils.mkdir_p File.split(symlinked_name)[0]
debug "About to move #{foreign_path} to #{symlinked_name}..."
copy_directory(foreign_path, symlinked_name)
File.join(dependency_directory, path_short_name)
File.join(options[:dependency_directory], path_short_name)
end
# Overwrite the Pathfile with the new relative paths.
File.open(File.join(destination, "Pathfile"), "w") do |file|
Expand Down
20 changes: 19 additions & 1 deletion test/unit/pathological/base_test.rb
Expand Up @@ -245,7 +245,7 @@ def load_and_run!
end

should "return immediately if there is no Pathfile" do
mock(Pathological).find_pathfile { nil }
mock(Pathological).find_pathfile(nil) { nil }
Pathological.copy_outside_paths! @destination
refute File.directory?(File.join(@destination, "pathological_dependencies"))
end
Expand All @@ -271,6 +271,24 @@ def load_and_run!
end
assert_equal destination_paths, File.read(File.join(@destination, "Pathfile")).split("\n")
end

should "copy source dirs as links and rewrite Pathfile in a different directory" do
other = "/tmp/other"
FileUtils.mkdir_p other
File.open(File.join(other, "Pathfile"), "w") { |f| f.puts @source_paths.join("\n") }

final_path = File.join(@destination, "pathological_dependencies")
@source_paths.each do |source_path|
mock(Pathological).copy_directory(source_path, final_path + source_path.gsub("/src", "")).once
end
Pathological.copy_outside_paths! @destination, :pathfile_search_path => other

assert File.directory?(final_path)
destination_paths = @source_paths.map do |source_path|
"pathological_dependencies#{source_path.gsub("/src", "")}"
end
assert_equal destination_paths, File.read(File.join(@destination, "Pathfile")).split("\n")
end
end
end
end
Expand Down

0 comments on commit b47c626

Please sign in to comment.