Skip to content

Commit

Permalink
Use relative schema urls internally
Browse files Browse the repository at this point in the history
As discussed in person, given that compilers should (if they have a
choice) produce bit-for-bit identical output, and a codegen tool like
plank is used in builds, it makes sense for `--print_deps` to output
dependencies via their relative paths.

Even if all things were equal and , this is still a nice change because:

1. The print_deps output is more readable and fewer bytes since absolute
paths are mostly repetitive and noisy
2. The logic for `decodeRef` can be simplified

I verified that Pinterest still builds correctly with this plank and
that we are still able to load schemas located in a different directory
(I tested with `../../foo.json`).
  • Loading branch information
Brandon Kase committed Jun 15, 2017
1 parent 46d340f commit f667483
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions Sources/Core/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ func decodeRef(from source: URL, with ref: String) -> URL {
// Local URL
return URL(string:ref, relativeTo:source)!
} else {
var baseUrl = source.deletingLastPathComponent()
if baseUrl.path == "." {
baseUrl = URL(fileURLWithPath: (baseUrl.path))
}
let baseUrl = source.deletingLastPathComponent()
let lastPathComponentString = URL(string: ref)?.pathComponents.last
return URL(string:lastPathComponentString!, relativeTo:baseUrl)!
return baseUrl.appendingPathComponent(lastPathComponentString!)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/plank/Cli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func handleGenerateCommand(withArguments arguments: [String]) {
}
outputDirectory = URL(fileURLWithPath: outputDirectory.absoluteString, isDirectory: true)

let urls = args.map { URL(fileURLWithPath: $0).standardizedFileURL }
let urls = args.map { URL(string: $0)! }

if flags[.printDeps] != nil {
generateDeps(urls: Set(urls))
Expand Down

0 comments on commit f667483

Please sign in to comment.