From 2654751b391163dd781e6a690a29fbbddd616198 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Thu, 2 Dec 2021 15:04:12 +0000 Subject: [PATCH] Custom code for joining paths no longer needed Since rust 1.57.0, path.push() works correctly on verbatim paths on Windows. See https://github.com/rust-lang/rust/pull/89270 Signed-off-by: Sean Young --- .github/workflows/test.yml | 14 +++-- src/file_resolver.rs | 107 +++---------------------------------- 2 files changed, 16 insertions(+), 105 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30d95e640..83363a90c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,12 @@ jobs: run: unzip c:\llvm.zip -d c:/ - name: Add LLVM to Path run: echo "c:\llvm13.0\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 + - name: Stable with rustfmt and clippy + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy # We run clippy on Linux in the lint job above, but this does not check #[cfg(windows)] items - name: Run cargo clippy run: cargo clippy --tests --bins -- -D warnings -D clippy::inconsistent-struct-constructor @@ -122,8 +128,8 @@ jobs: name: solang-mac-intel path: ./target/debug/solang - container: - name: Container + image: + name: Container Image runs-on: ubuntu-20.04 steps: - name: Checkout sources @@ -131,8 +137,8 @@ jobs: with: # Make sure "git describe --tags" works for solang --version fetch-depth: 0 - - run: | - docker build . -t ghcr.io/${GITHUB_REPOSITORY}:latest \ + - run: + docker build . -t ghcr.io/${GITHUB_REPOSITORY}:latest --label org.opencontainers.image.description="Solidity Compiler for Solana, Substrate, and ewasm version $(git describe --tags)" - name: Push to github container registry if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} diff --git a/src/file_resolver.rs b/src/file_resolver.rs index 24f96db5d..9bf9d819a 100644 --- a/src/file_resolver.rs +++ b/src/file_resolver.rs @@ -5,7 +5,7 @@ use std::ffi::OsString; use std::fs::File; use std::io; use std::io::{prelude::*, Error, ErrorKind}; -use std::path::{Component, Path, PathBuf}; +use std::path::{Path, PathBuf}; use std::sync::Arc; pub struct FileResolver { @@ -138,7 +138,7 @@ impl FileResolver { if let (Some(mapping), import_path) = import { if first_part == mapping { // match! - if let Ok(full_path) = join_fold(import_path, &relpath).canonicalize() { + if let Ok(full_path) = import_path.join(&relpath).canonicalize() { self.load_file(&full_path)?; let base = full_path .parent() @@ -165,7 +165,7 @@ impl FileResolver { { if self.import_paths.is_empty() { // we have no import paths, resolve by what's in the cache - let full_path = join_fold(base, &path); + let full_path = base.join(&path); let base = (&full_path.parent()) .expect("path should include filename") .to_path_buf(); @@ -178,9 +178,9 @@ impl FileResolver { } if let (None, import_path) = &self.import_paths[*import_no] { - let import_path = join_fold(import_path, base); + let import_path = import_path.join(base); - if let Ok(full_path) = join_fold(&import_path, &path).canonicalize() { + if let Ok(full_path) = import_path.join(&path).canonicalize() { self.load_file(&full_path)?; let base = full_path .parent() @@ -218,7 +218,7 @@ impl FileResolver { let import_no = (i + start_import_no) % self.import_paths.len(); if let (None, import_path) = &self.import_paths[import_no] { - if let Ok(full_path) = join_fold(import_path, &path).canonicalize() { + if let Ok(full_path) = import_path.join(&path).canonicalize() { let base = full_path .parent() .expect("path should include filename") @@ -275,98 +275,3 @@ impl FileResolver { (full_line, begin_line, begin_column, size) } } - -// see https://github.com/rust-lang/rust/pull/89270 -fn join_fold(left: &Path, right: &Path) -> PathBuf { - let mut buf = Vec::new(); - let mut has_prefix = false; - - for c in left.components() { - match c { - Component::Prefix(_) => { - has_prefix = true; - buf.push(c); - } - Component::Normal(_) | Component::RootDir => { - buf.push(c); - } - Component::CurDir => (), - Component::ParentDir => { - if let Some(Component::Normal(_)) = buf.last() { - buf.pop(); - } else { - buf.push(c); - } - } - } - } - - for c in right.components() { - match c { - Component::Prefix(_) => { - buf = vec![c]; - has_prefix = true; - } - Component::RootDir => { - if has_prefix { - buf.push(c); - } else { - buf = vec![c]; - } - } - Component::CurDir => (), - Component::ParentDir => match buf.last() { - Some(Component::RootDir) => (), - Some(Component::Prefix(_) | Component::ParentDir) | None => buf.push(c), - _ => { - let _ = buf.pop(); - } - }, - Component::Normal(_) => { - buf.push(c); - } - } - } - - buf.iter().collect() -} - -#[test] -#[cfg(not(windows))] -fn test_join() { - let x = join_fold(&PathBuf::from("/foo//"), &PathBuf::from("bar")); - - assert_eq!(x.to_string_lossy(), r"/foo/bar"); - - let x = join_fold(&PathBuf::from("/foo//"), &PathBuf::from("/../bar")); - - assert_eq!(x.to_string_lossy(), r"/bar"); -} - -#[test] -#[cfg(windows)] -fn test_win_join() { - let x = join_fold(&PathBuf::from("/foo//"), &PathBuf::from("bar")); - - assert_eq!(x.to_string_lossy(), r"\foo\bar"); - - let x = join_fold(&PathBuf::from("/foo//"), &PathBuf::from("/../bar")); - - assert_eq!(x.to_string_lossy(), r"\bar"); - - let x = join_fold(&PathBuf::from("C:/foo//"), &PathBuf::from("bar")); - - assert_eq!(x.to_string_lossy(), r"C:\foo\bar"); - - let x = join_fold(&PathBuf::from("C:"), &PathBuf::from("bar/../foo")); - - assert_eq!(x.to_string_lossy(), r"C:foo"); - - let x = join_fold(&PathBuf::from("C:"), &PathBuf::from("/bar/../foo")); - - assert_eq!(x.to_string_lossy(), r"C:\foo"); - - let x = join_fold(&PathBuf::from("C:"), &PathBuf::from("../foo")); - - assert_eq!(x.to_string_lossy(), r"C:..\foo"); -}