mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-26 21:34:55 +00:00
Fix docs.rs build for rustpython-parser
docs.rs failed to build the documentation of the recently released rustpython-parser 0.2.0 because the build.rs script couldn't write the parser.rs file because docs.rs builds the documentation in a sandbox with a read-only filesystem. This commit fixes this by writing the parser.rs file to the cargo output directory instead, as recommended by the docs.rs documentation.[1] Fixes #4436. [1]: https://docs.rs/about/builds#read-only-directories
This commit is contained in:
parent
884a7bdb15
commit
4f1e7c6291
2 changed files with 18 additions and 13 deletions
|
@ -1,22 +1,22 @@
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, BufWriter, Write};
|
use std::io::{BufRead, BufReader, BufWriter, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use tiny_keccak::{Hasher, Sha3};
|
use tiny_keccak::{Hasher, Sha3};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
const SOURCE: &str = "python.lalrpop";
|
const SOURCE: &str = "python.lalrpop";
|
||||||
const TARGET: &str = "python.rs";
|
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed={SOURCE}");
|
println!("cargo:rerun-if-changed={SOURCE}");
|
||||||
|
|
||||||
try_lalrpop(SOURCE, TARGET)?;
|
try_lalrpop(SOURCE, &out_dir.join("python.rs"))?;
|
||||||
gen_phf();
|
gen_phf(&out_dir);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn requires_lalrpop(source: &str, target: &str) -> Option<String> {
|
fn requires_lalrpop(source: &str, target: &Path) -> Option<String> {
|
||||||
let Ok(target) = File::open(target) else {
|
let Ok(target) = File::open(target) else {
|
||||||
return Some("python.rs doesn't exist. regenerate.".to_owned());
|
return Some("python.rs doesn't exist. regenerate.".to_owned());
|
||||||
};
|
};
|
||||||
|
@ -68,13 +68,19 @@ fn requires_lalrpop(source: &str, target: &str) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_lalrpop(source: &str, target: &str) -> anyhow::Result<()> {
|
fn try_lalrpop(source: &str, target: &Path) -> anyhow::Result<()> {
|
||||||
let Some(_message) = requires_lalrpop(source, target) else {
|
let Some(_message) = requires_lalrpop(source, target) else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "lalrpop")]
|
#[cfg(feature = "lalrpop")]
|
||||||
lalrpop::process_root().unwrap_or_else(|e| {
|
// We are not using lalrpop::process_root() or Configuration::process_current_dir()
|
||||||
|
// because of https://github.com/lalrpop/lalrpop/issues/699.
|
||||||
|
lalrpop::Configuration::new()
|
||||||
|
.use_cargo_dir_conventions()
|
||||||
|
.set_in_dir(Path::new("."))
|
||||||
|
.process()
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
println!("cargo:warning={_message}");
|
println!("cargo:warning={_message}");
|
||||||
panic!("running lalrpop failed. {e:?}");
|
panic!("running lalrpop failed. {e:?}");
|
||||||
});
|
});
|
||||||
|
@ -98,8 +104,7 @@ fn sha_equal(expected_sha3_str: &str, actual_sha3: &[u8; 32]) -> bool {
|
||||||
*actual_sha3 == expected_sha3
|
*actual_sha3 == expected_sha3
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_phf() {
|
fn gen_phf(out_dir: &Path) {
|
||||||
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
|
||||||
let mut kwds = phf_codegen::Map::new();
|
let mut kwds = phf_codegen::Map::new();
|
||||||
let kwds = kwds
|
let kwds = kwds
|
||||||
// Alphabetical keywords:
|
// Alphabetical keywords:
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
include!("../python.rs");
|
include!(concat!(env!("OUT_DIR"), "/python.rs"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue