diff options
author | Nadrieril | 2020-03-01 19:37:24 +0000 |
---|---|---|
committer | Nadrieril | 2020-03-05 15:58:54 +0000 |
commit | 5a9a5859eec0cf7deebf7fa07fe99f8dc8722ec8 (patch) | |
tree | 838f55765c65d5dd8c701670cd78b1908467e383 | |
parent | df4495f30708180591b630bb720cfe81ff4118ce (diff) |
Implement remote `as Location` resolution
Diffstat (limited to '')
24 files changed, 52 insertions, 12 deletions
diff --git a/dhall/build.rs b/dhall/build.rs index 29219ff..5faa6b2 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -253,13 +253,17 @@ fn generate_tests() -> std::io::Result<()> { || path == "alternativeHashMismatch" || path == "hashFromCache" || path == "unit/AlternativeHashMismatch" - // TODO: remote imports + // TODO: This test is wrong || path == "asLocation" + // TODO: remote imports + || path == "unit/SimpleRemote" + || path == "unit/asLocation/RemoteChain1" + || path == "unit/asLocation/RemoteChain2" + || path == "unit/asLocation/RemoteChain3" + // TODO: import headers || path == "customHeaders" || path == "headerForwarding" || path == "noHeaderForwarding" - || path == "unit/SimpleRemote" - || path == "unit/asLocation/Remote" }), input_type: FileType::Text, output_type: Some(FileType::Text), @@ -273,9 +277,10 @@ fn generate_tests() -> std::io::Result<()> { false // TODO: import hash || path == "hashMismatch" - // TODO: remote imports - || path == "customHeadersUsingBoundVariable" + // TODO: remote imports CORS/sanity check || path == "referentiallyInsane" + // TODO: import headers + || path == "customHeadersUsingBoundVariable" }), input_type: FileType::Text, output_type: Some(FileType::UI), diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index f419858..8a8c9b6 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::borrow::Cow; use std::env; use std::path::PathBuf; @@ -127,11 +128,21 @@ fn resolve_one_import( .into_owned(); ("Local", Some(path)) } + ImportLocation::Remote(url) => { + let path = + url.path.canonicalize().file_path.iter().join("/"); + let mut url_str = + format!("{}://{}/{}", url.scheme, url.authority, path); + if let Some(q) = &url.query { + url_str.push('?'); + url_str.push_str(q.as_ref()); + } + ("Remote", Some(url_str)) + } ImportLocation::Env(name) => { ("Environment", Some(name.clone())) } ImportLocation::Missing => ("Missing", None), - _ => unimplemented!("{:?}", import), }; let asloc_ty = make_aslocation_uniontype(); diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 8891d41..53f2c8f 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -406,7 +406,7 @@ impl<SubExpr: Display> Display for Import<SubExpr> { f.write_str(&path)?; } Remote(url) => { - write!(f, "{}://{}/", url.scheme, url.authority,)?; + write!(f, "{}://{}/", url.scheme, url.authority)?; let path: String = url.path.file_path.iter().join("/"); f.write_str(&path)?; if let Some(q) = &url.query { diff --git a/dhall/tests/import/success/unit/asLocation/Chain1A.dhall b/dhall/tests/import/success/unit/asLocation/Chain1A.dhall index 7b20bc3..cf633fe 100644 --- a/dhall/tests/import/success/unit/asLocation/Chain1A.dhall +++ b/dhall/tests/import/success/unit/asLocation/Chain1A.dhall @@ -1 +1 @@ -./RelativeA.dhall +./Relative1A.dhall diff --git a/dhall/tests/import/success/unit/asLocation/RelativeA.dhall b/dhall/tests/import/success/unit/asLocation/Relative1A.dhall index b514f79..b514f79 100644 --- a/dhall/tests/import/success/unit/asLocation/RelativeA.dhall +++ b/dhall/tests/import/success/unit/asLocation/Relative1A.dhall diff --git a/dhall/tests/import/success/unit/asLocation/RelativeB.dhall b/dhall/tests/import/success/unit/asLocation/Relative1B.dhall index b3bd255..6aee0b5 100644 --- a/dhall/tests/import/success/unit/asLocation/RelativeB.dhall +++ b/dhall/tests/import/success/unit/asLocation/Relative1B.dhall @@ -1,2 +1,2 @@ -< Environment : Text | Remote : Text | Local : Text | Missing >.Local +< Environment : Text | Local : Text | Missing | Remote : Text >.Local "./dhall/tests/import/success/unit/asLocation/some/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/Relative2A.dhall b/dhall/tests/import/success/unit/asLocation/Relative2A.dhall new file mode 100644 index 0000000..ec59586 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/Relative2A.dhall @@ -0,0 +1 @@ +../some/import.dhall as Location diff --git a/dhall/tests/import/success/unit/asLocation/Relative2B.dhall b/dhall/tests/import/success/unit/asLocation/Relative2B.dhall new file mode 100644 index 0000000..9842f7c --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/Relative2B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Local + "./dhall/tests/import/success/unit/some/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteA.dhall b/dhall/tests/import/success/unit/asLocation/RemoteA.dhall index e0be314..54ea028 100644 --- a/dhall/tests/import/success/unit/asLocation/RemoteA.dhall +++ b/dhall/tests/import/success/unit/asLocation/RemoteA.dhall @@ -1 +1 @@ -https://prelude.dhall-lang.org/package.dhall as Location +https://example.com/foo/import.dhall as Location diff --git a/dhall/tests/import/success/unit/asLocation/RemoteB.dhall b/dhall/tests/import/success/unit/asLocation/RemoteB.dhall index 8ab6366..e22cfac 100644 --- a/dhall/tests/import/success/unit/asLocation/RemoteB.dhall +++ b/dhall/tests/import/success/unit/asLocation/RemoteB.dhall @@ -1,2 +1,2 @@ -< Environment : Text | Remote : Text | Local : Text | Missing >.Remote - "https://prelude.dhall-lang.org/package.dhall" +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://example.com/foo/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall new file mode 100644 index 0000000..3e6378e --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1A.dhall @@ -0,0 +1 @@ +https://example.com/foo/./bar/import.dhall as Location diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall new file mode 100644 index 0000000..0064a13 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize1B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://example.com/foo/bar/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall new file mode 100644 index 0000000..d3fd11e --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2A.dhall @@ -0,0 +1 @@ +https://example.com/foo/bar/../baz/import.dhall as Location diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall new file mode 100644 index 0000000..d85236b --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize2B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://example.com/foo/baz/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall new file mode 100644 index 0000000..2074fbf --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3A.dhall @@ -0,0 +1 @@ +https://example.com/foo/bar/../../baz/import.dhall as Location diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall new file mode 100644 index 0000000..45a2857 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize3B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://example.com/baz/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall new file mode 100644 index 0000000..9358f44 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4A.dhall @@ -0,0 +1 @@ +https://example.com/../bar/import.dhall as Location diff --git a/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall new file mode 100644 index 0000000..b5ccbcd --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteCanonicalize4B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://example.com/../bar/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall new file mode 100644 index 0000000..7d081ab --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteChain1A.dhall @@ -0,0 +1 @@ +https://raw.githubusercontent.com/dhall-lang/dhall-lang/0b983b92aa2222dc3e292c20550ee37dea3f41df/tests/import/data/simpleLocation.dhall diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall new file mode 100644 index 0000000..8ac2c6b --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteChain1B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://raw.githubusercontent.com/dhall-lang/dhall-lang/0b983b92aa2222dc3e292c20550ee37dea3f41df/tests/import/data/simple.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall new file mode 100644 index 0000000..9929517 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteChain2A.dhall @@ -0,0 +1 @@ +https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/asLocation/Canonicalize3A.dhall diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall new file mode 100644 index 0000000..685dc04 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteChain2B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/bar/import.dhall" diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall new file mode 100644 index 0000000..851108c --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteChain3A.dhall @@ -0,0 +1 @@ +https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/asLocation/Canonicalize5A.dhall diff --git a/dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall b/dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall new file mode 100644 index 0000000..685dc04 --- /dev/null +++ b/dhall/tests/import/success/unit/asLocation/RemoteChain3B.dhall @@ -0,0 +1,2 @@ +< Environment : Text | Local : Text | Missing | Remote : Text >.Remote + "https://raw.githubusercontent.com/Nadrieril/dhall-rust/f7d8c64a9799f139ad65427c2518376adb9e2e2f/dhall/tests/import/success/unit/bar/import.dhall" |