Skip to content

Commit 3144ff8

Browse files
authored
Merge pull request RustPython#2602 from RustPython/coolreader18/fix-windows-symlinks
Remove symlinks-to-hardlinks.ps1 hack
2 parents dcb1b45 + 9a83e15 commit 3144ff8

6 files changed

Lines changed: 47 additions & 57 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ jobs:
2929
- uses: actions/checkout@master
3030
- uses: actions-rs/toolchain@v1
3131
- name: Set up the Windows environment
32-
run: |
33-
choco install llvm
34-
powershell.exe scripts/symlinks-to-hardlinks.ps1
32+
run: choco install llvm
3533
if: runner.os == 'Windows'
3634
- name: Set up the Mac environment
3735
run: brew install autoconf automake libtool
@@ -62,9 +60,7 @@ jobs:
6260
with:
6361
python-version: 3.8
6462
- name: Set up the Windows environment
65-
run: |
66-
choco install llvm
67-
powershell.exe scripts/symlinks-to-hardlinks.ps1
63+
run: choco install llvm
6864
if: runner.os == 'Windows'
6965
- name: Set up the Mac environment
7066
run: brew install autoconf automake libtool

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ To build RustPython locally, do the following:
2828

2929
$ git clone https://github.com/RustPython/RustPython
3030
$ cd RustPython
31-
# if you're on windows:
32-
$ powershell scripts\symlinks-to-hardlinks.ps1
3331
# --release is needed (at least on windows) to prevent stack overflow
3432
$ cargo run --release demo.py
3533
Hello, RustPython!

derive/src/compile_bytecode.rs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,18 @@ impl CompilationSource {
115115
mode: compile::Mode,
116116
) -> Result<HashMap<String, FrozenModule>, Diagnostic> {
117117
let mut code_map = HashMap::new();
118-
let paths = fs::read_dir(&path).map_err(|err| {
119-
Diagnostic::spans_error(self.span, format!("Error listing dir {:?}: {}", path, err))
120-
})?;
118+
let paths = fs::read_dir(path)
119+
.or_else(|e| {
120+
if cfg!(windows) {
121+
if let Ok(real_path) = fs::read_to_string(path.canonicalize().unwrap()) {
122+
return fs::read_dir(real_path.trim());
123+
}
124+
}
125+
Err(e)
126+
})
127+
.map_err(|err| {
128+
Diagnostic::spans_error(self.span, format!("Error listing dir {:?}: {}", path, err))
129+
})?;
121130
for path in paths {
122131
let path = path.map_err(|err| {
123132
Diagnostic::spans_error(self.span, format!("Failed to list file: {}", err))
@@ -133,12 +142,6 @@ impl CompilationSource {
133142
mode,
134143
)?);
135144
} else if file_name.ends_with(".py") {
136-
let source = fs::read_to_string(&path).map_err(|err| {
137-
Diagnostic::spans_error(
138-
self.span,
139-
format!("Error reading file {:?}: {}", path, err),
140-
)
141-
})?;
142145
let stem = path.file_stem().unwrap().to_str().unwrap();
143146
let is_init = stem == "__init__";
144147
let module_name = if is_init {
@@ -148,15 +151,39 @@ impl CompilationSource {
148151
} else {
149152
format!("{}.{}", parent, stem)
150153
};
154+
155+
let compile_path = |src_path: &Path| {
156+
let source = fs::read_to_string(src_path).map_err(|err| {
157+
Diagnostic::spans_error(
158+
self.span,
159+
format!("Error reading file {:?}: {}", path, err),
160+
)
161+
})?;
162+
self.compile_string(&source, mode, module_name.clone(), || {
163+
path.strip_prefix(&*CARGO_MANIFEST_DIR)
164+
.ok()
165+
.unwrap_or(&path)
166+
.display()
167+
})
168+
};
169+
let code = compile_path(&path).or_else(|e| {
170+
if cfg!(windows) {
171+
if let Ok(real_path) = fs::read_to_string(path.canonicalize().unwrap()) {
172+
let joined = path.parent().unwrap().join(real_path.trim());
173+
if joined.exists() {
174+
return compile_path(&joined);
175+
} else {
176+
return Err(e);
177+
}
178+
}
179+
}
180+
Err(e)
181+
})?;
182+
151183
code_map.insert(
152-
module_name.clone(),
184+
module_name,
153185
FrozenModule {
154-
code: self.compile_string(&source, mode, module_name, || {
155-
path.strip_prefix(&*CARGO_MANIFEST_DIR)
156-
.ok()
157-
.unwrap_or(&path)
158-
.display()
159-
})?,
186+
code,
160187
package: is_init,
161188
},
162189
);

scripts/symlinks-to-hardlinks.ps1

Lines changed: 0 additions & 31 deletions
This file was deleted.

vm/src/frozen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub fn get_module_inits() -> impl Iterator<Item = (String, bytecode::FrozenModul
3838
// Python modules that the vm calls into, but are not actually part of the stdlib. They could
3939
// in theory be implemented in Rust, but are easiest to do in Python for one reason or another.
4040
// Includes _importlib_bootstrap and _importlib_bootstrap_external
41-
// For Windows: did you forget to run `powershell scripts\symlinks-to-hardlinks.ps1`?
4241
ext_modules!(iter, dir = "Lib/python_builtins/");
4342

4443
#[cfg(not(feature = "freeze-stdlib"))]

vm/src/stdlib/os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,7 @@ pub(crate) use posix::raw_set_inheritable;
27642764
#[pymodule]
27652765
mod nt {
27662766
use super::*;
2767+
#[cfg(target_env = "msvc")]
27672768
use crate::builtins::list::PyListRef;
27682769
#[cfg(target_env = "msvc")]
27692770
use winapi::vc::vcruntime::intptr_t;
@@ -3120,7 +3121,7 @@ mod nt {
31203121
}
31213122
#[cfg(windows)]
31223123
use nt as platform;
3123-
#[cfg(windows)]
3124+
#[cfg(all(windows, target_env = "msvc"))]
31243125
pub use nt::{_set_thread_local_invalid_parameter_handler, silent_iph_handler};
31253126

31263127
#[cfg(not(any(unix, windows)))]

0 commit comments

Comments
 (0)