class Build::Files::Path
def self.shortest_path(path, root)
def self.shortest_path(path, root) path_components = Path.components(path) root_components = Path.components(root) # Find the common prefix: i = prefix_length(path_components, root_components) || 0 # The difference between the root path and the required path, taking into account the common prefix: up = root_components.size - i components = [".."] * up + path_components[i..-1] if components.empty? return "." else return File.join(components) end end