Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f47caa6

Browse files
committed
Add AbsPath::absolutize
1 parent 939ebb4 commit f47caa6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

crates/paths/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ impl AbsPath {
140140
self.0.parent().map(AbsPath::assert)
141141
}
142142

143+
/// Equivalent of [`Path::join`] for `AbsPath` with an additional normalize step afterwards.
144+
pub fn absolutize(&self, path: impl AsRef<Path>) -> AbsPathBuf {
145+
self.join(path).normalize()
146+
}
147+
143148
/// Equivalent of [`Path::join`] for `AbsPath`.
144149
pub fn join(&self, path: impl AsRef<Path>) -> AbsPathBuf {
145150
self.as_ref().join(path).try_into().unwrap()

crates/project-model/src/project_json.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,23 @@ impl ProjectJson {
9898
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
9999
/// configuration.
100100
pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
101-
let absolutize =
102-
|p| AbsPathBuf::try_from(p).unwrap_or_else(|path| base.join(&path)).normalize();
101+
let absolutize_on_base = |p| base.absolutize(p);
103102
ProjectJson {
104-
sysroot: data.sysroot.map(absolutize),
105-
sysroot_src: data.sysroot_src.map(absolutize),
103+
sysroot: data.sysroot.map(absolutize_on_base),
104+
sysroot_src: data.sysroot_src.map(absolutize_on_base),
106105
project_root: base.to_path_buf(),
107106
crates: data
108107
.crates
109108
.into_iter()
110109
.map(|crate_data| {
111-
let root_module = absolutize(crate_data.root_module);
110+
let root_module = absolutize_on_base(crate_data.root_module);
112111
let is_workspace_member = crate_data
113112
.is_workspace_member
114113
.unwrap_or_else(|| root_module.starts_with(base));
115114
let (include, exclude) = match crate_data.source {
116115
Some(src) => {
117116
let absolutize = |dirs: Vec<PathBuf>| {
118-
dirs.into_iter().map(absolutize).collect::<Vec<_>>()
117+
dirs.into_iter().map(absolutize_on_base).collect::<Vec<_>>()
119118
};
120119
(absolutize(src.include_dirs), absolutize(src.exclude_dirs))
121120
}
@@ -142,7 +141,9 @@ impl ProjectJson {
142141
cfg: crate_data.cfg,
143142
target: crate_data.target,
144143
env: crate_data.env,
145-
proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(absolutize),
144+
proc_macro_dylib_path: crate_data
145+
.proc_macro_dylib_path
146+
.map(absolutize_on_base),
146147
is_workspace_member,
147148
include,
148149
exclude,

0 commit comments

Comments
 (0)