Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae070b7

Browse files
committed
Usestd::path::absolute in bootstrap
1 parent7ac6c2f commitae070b7

File tree

2 files changed

+2
-111
lines changed

2 files changed

+2
-111
lines changed

‎src/bootstrap/src/core/config/config.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::env;
1010
use std::fmt::{self,Display};
1111
use std::fs;
1212
use std::io::IsTerminal;
13-
use std::path::{Path,PathBuf};
13+
use std::path::{absolute,Path,PathBuf};
1414
use std::process::Command;
1515
use std::str::FromStr;
1616
use std::sync::OnceLock;
@@ -1437,7 +1437,7 @@ impl Config {
14371437
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
14381438
if !config.out.is_absolute(){
14391439
// `canonicalize` requires the path to already exist. Use our vendored copy of `absolute` instead.
1440-
config.out =crate::utils::helpers::absolute(&config.out);
1440+
config.out =absolute(&config.out).expect("can't make empty path absolute");
14411441
}
14421442

14431443
config.initial_rustc =ifletSome(rustc) = rustc{

‎src/bootstrap/src/utils/helpers.rs‎

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -331,115 +331,6 @@ fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {
331331
})
332332
}
333333

334-
/// Copied from `std::path::absolute` until it stabilizes.
335-
///
336-
/// FIXME: this shouldn't exist.
337-
pub(crate)fnabsolute(path:&Path) ->PathBuf{
338-
if path.as_os_str().is_empty(){
339-
panic!("can't make empty path absolute");
340-
}
341-
#[cfg(unix)]
342-
{
343-
t!(absolute_unix(path), format!("could not make path absolute: {}", path.display()))
344-
}
345-
#[cfg(windows)]
346-
{
347-
t!(absolute_windows(path), format!("could not make path absolute: {}", path.display()))
348-
}
349-
#[cfg(not(any(unix, windows)))]
350-
{
351-
println!("WARNING: bootstrap is not supported on non-unix platforms");
352-
t!(std::fs::canonicalize(t!(std::env::current_dir()))).join(path)
353-
}
354-
}
355-
356-
#[cfg(unix)]
357-
/// Make a POSIX path absolute without changing its semantics.
358-
fnabsolute_unix(path:&Path) -> io::Result<PathBuf>{
359-
// This is mostly a wrapper around collecting `Path::components`, with
360-
// exceptions made where this conflicts with the POSIX specification.
361-
// See 4.13 Pathname Resolution, IEEE Std 1003.1-2017
362-
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
363-
364-
use std::os::unix::prelude::OsStrExt;
365-
letmut components = path.components();
366-
let path_os = path.as_os_str().as_bytes();
367-
368-
letmut normalized =if path.is_absolute(){
369-
// "If a pathname begins with two successive <slash> characters, the
370-
// first component following the leading <slash> characters may be
371-
// interpreted in an implementation-defined manner, although more than
372-
// two leading <slash> characters shall be treated as a single <slash>
373-
// character."
374-
if path_os.starts_with(b"//") && !path_os.starts_with(b"///"){
375-
components.next();
376-
PathBuf::from("//")
377-
}else{
378-
PathBuf::new()
379-
}
380-
}else{
381-
env::current_dir()?
382-
};
383-
normalized.extend(components);
384-
385-
// "Interfaces using pathname resolution may specify additional constraints
386-
// when a pathname that does not name an existing directory contains at
387-
// least one non- <slash> character and contains one or more trailing
388-
// <slash> characters".
389-
// A trailing <slash> is also meaningful if "a symbolic link is
390-
// encountered during pathname resolution".
391-
392-
if path_os.ends_with(b"/"){
393-
normalized.push("");
394-
}
395-
396-
Ok(normalized)
397-
}
398-
399-
#[cfg(windows)]
400-
fnabsolute_windows(path:&std::path::Path) -> std::io::Result<std::path::PathBuf>{
401-
use std::ffi::OsString;
402-
use std::io::Error;
403-
use std::os::windows::ffi::{OsStrExt,OsStringExt};
404-
use std::ptr::null_mut;
405-
#[link(name ="kernel32")]
406-
extern"system"{
407-
fnGetFullPathNameW(
408-
lpFileName:*constu16,
409-
nBufferLength:u32,
410-
lpBuffer:*mutu16,
411-
lpFilePart:*mut*constu16,
412-
) ->u32;
413-
}
414-
415-
unsafe{
416-
// encode the path as UTF-16
417-
let path:Vec<u16> = path.as_os_str().encode_wide().chain([0]).collect();
418-
letmut buffer =Vec::new();
419-
// Loop until either success or failure.
420-
loop{
421-
// Try to get the absolute path
422-
let len =GetFullPathNameW(
423-
path.as_ptr(),
424-
buffer.len().try_into().unwrap(),
425-
buffer.as_mut_ptr(),
426-
null_mut(),
427-
);
428-
match lenasusize{
429-
// Failure
430-
0 =>returnErr(Error::last_os_error()),
431-
// Buffer is too small, resize.
432-
lenif len > buffer.len() => buffer.resize(len,0),
433-
// Success!
434-
len =>{
435-
buffer.truncate(len);
436-
returnOk(OsString::from_wide(&buffer).into());
437-
}
438-
}
439-
}
440-
}
441-
}
442-
443334
/// Adapted from <https://github.com/llvm/llvm-project/blob/782e91224601e461c019e0a4573bbccc6094fbcd/llvm/cmake/modules/HandleLLVMOptions.cmake#L1058-L1079>
444335
///
445336
/// When `clang-cl` is used with instrumentation, we need to add clang's runtime library resource

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp