Skip to content

Commit

Permalink
Reverted recent fix attempts and finally fixed Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
awelc committed Feb 29, 2024
1 parent 968636e commit f62479b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use crate::{
expansion, hlir, interface_generator, naming, parser,
parser::{comments::*, *},
shared::{
canonicalize, CompilationEnv, Flags, IndexedPackagePath, IndexedVfsPackagePath,
find_filenames, CompilationEnv, Flags, IndexedPackagePath, IndexedVfsPackagePath,
NamedAddressMap, NamedAddressMaps, NumericalAddress, PackageConfig, PackagePaths,
},
to_bytecode,
typing::{self, visitor::TypingVisitorObj},
unit_test,
};
use move_command_line_common::files::{
extension_equals, find_filenames, MOVE_COMPILED_EXTENSION, MOVE_EXTENSION, SOURCE_MAP_EXTENSION,
MOVE_COMPILED_EXTENSION, MOVE_EXTENSION, SOURCE_MAP_EXTENSION,
};
use move_core_types::language_storage::ModuleId as CompiledModuleId;
use move_symbol_pool::Symbol;
Expand Down Expand Up @@ -280,12 +280,17 @@ impl<'a> Compiler<'a> {
)> {
/// Path relativization after parsing is needed as paths are initially canonicalized when
/// converted to virtual file system paths and would show up as absolute in the test output
/// which wouldn't be machine-agnostic.
fn relativize_path(path: Symbol) -> Symbol {
/// which wouldn't be machine-agnostic. We need to relativize using `vfs_root` beacuse it
/// was also used during canonicalization and might have altered path prefix in a
/// non-standard way (e.g., this can happen on Windows).
fn relativize_path(vsf_root: &VfsPath, path: Symbol) -> Symbol {
let Some(current_dir) = std::env::current_dir().ok() else {
return path;
};
let Some(new_path) = diff_paths(path.to_string(), current_dir) else {
let Ok(current_dir_vfs) = vsf_root.join(&current_dir.to_string_lossy()) else {
return path;
};
let Some(new_path) = diff_paths(path.to_string(), current_dir_vfs.as_str()) else {
return path;
};
Symbol::from(new_path.to_string_lossy().to_string())
Expand Down Expand Up @@ -345,7 +350,7 @@ impl<'a> Compiler<'a> {

source_text
.iter_mut()
.for_each(|(_, (path, _))| *path = relativize_path(*path));
.for_each(|(_, (path, _))| *path = relativize_path(&vfs_root, *path));

let res: Result<_, Diagnostics> =
SteppedCompiler::new_at_parser(compilation_env, pre_compiled_lib, pprog)
Expand Down Expand Up @@ -758,18 +763,17 @@ pub fn generate_interface_files(
} in other_file_locations
{
v.extend(
find_filenames(&[path.as_str()], |path| {
extension_equals(path, MOVE_COMPILED_EXTENSION)
find_filenames(&[path], |path| {
path.extension()
.map(|e| e.as_str() == MOVE_COMPILED_EXTENSION)
.unwrap_or(false)
})?
.into_iter()
.map(|p| {
Ok(IndexedVfsPackagePath {
package,
path: path.root().join(p)?,
named_address_map,
})
})
.collect::<Result<Vec<_>, anyhow::Error>>()?,
.map(|path| IndexedVfsPackagePath {
package,
path,
named_address_map,
}),
);
}
v
Expand Down Expand Up @@ -824,7 +828,7 @@ pub fn generate_interface_files(
.to_string_lossy()
.to_string(),
);
let vfs_path = deps_out_vfs.join(canonicalize(file_path.as_str().to_owned()))?;
let vfs_path = deps_out_vfs.join(file_path)?;
vfs_path.parent().create_dir_all()?;
vfs_path
.create_file()?
Expand Down
23 changes: 9 additions & 14 deletions external-crates/move/crates/move-compiler/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub(crate) mod verification_attribute_filter;
use crate::{
diagnostics::FilesSourceText,
parser::{self, ast::PackageDefinition, syntax::parse_file_string},
shared::{CompilationEnv, IndexedVfsPackagePath, NamedAddressMaps},
shared::{find_move_filenames, CompilationEnv, IndexedVfsPackagePath, NamedAddressMaps},
};
use anyhow::anyhow;
use comments::*;
use move_command_line_common::files::{find_move_filenames, FileHash};
use move_command_line_common::files::FileHash;
use move_symbol_pool::Symbol;
use std::collections::{BTreeSet, HashMap};
use vfs::VfsPath;
Expand All @@ -41,18 +41,13 @@ pub(crate) fn parse_program(
named_address_map: named_address_mapping,
} in paths_with_mapping
{
res.extend(
find_move_filenames(&[path.as_str()], true)?
.into_iter()
.map(|s| {
Ok(IndexedVfsPackagePath {
package,
path: path.root().join(s)?,
named_address_map: named_address_mapping,
})
})
.collect::<Result<Vec<_>, anyhow::Error>>()?,
);
res.extend(find_move_filenames(&[path], true)?.into_iter().map(|s| {
IndexedVfsPackagePath {
package,
path: s,
named_address_map: named_address_mapping,
}
}));
}
// sort the filenames so errors about redefinitions, or other inter-file conflicts, are
// deterministic
Expand Down
16 changes: 8 additions & 8 deletions external-crates/move/crates/move-compiler/src/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,16 +882,16 @@ pub struct IndexedVfsPackagePath {
pub named_address_map: NamedAddressMapIndex,
}

// we need to canonicalized paths for virtual file systems as some of them (e.g., implementation
// of the physical one) cannot handle relative paths
pub fn canonicalize(p: String) -> String {
match std::fs::canonicalize(&p) {
Ok(s) => s.to_string_lossy().to_string(),
Err(_) => p,
pub fn vfs_path_from_str(path: String, vfs_path: &VfsPath) -> Result<VfsPath, VfsError> {
// we need to canonicalized paths for virtual file systems as some of them (e.g., implementation
// of the physical one) cannot handle relative paths
fn canonicalize(p: String) -> String {
match dunce::canonicalize(&p) {
Ok(s) => s.to_string_lossy().to_string(),
Err(_) => p,
}
}
}

pub fn vfs_path_from_str(path: String, vfs_path: &VfsPath) -> Result<VfsPath, VfsError> {
vfs_path.join(canonicalize(path))
}

Expand Down

0 comments on commit f62479b

Please sign in to comment.