Skip to content

Commit

Permalink
Use OUT_DIR for hermes_parser build script
Browse files Browse the repository at this point in the history
Summary:
Same as D53502298, we need to use the OUT_DIR for generated files in build.rs to make internal infra happy.

Original Author: [email protected]
Original Git: 61f1f52
Original Reviewed By: alunyov
Original Revision: D53545692

Reviewed By: avp

Differential Revision: D54092034

fbshipit-source-id: 339a60a5987650971a64b6f897865548e599f6b0
  • Loading branch information
neildhar authored and facebook-github-bot committed Feb 23, 2024
1 parent 5b9fe11 commit e1a177c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4,156 deletions.
19 changes: 19 additions & 0 deletions unsupported/hermes/crates/hermes_estree_codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ pub fn estree_hermes() -> String {
)
}

/// Returns estree_herems that can be included indirectly
pub fn estree_hermes_mod() -> String {
let src = include_str!("./ecmascript.json");
let grammar: Grammar = serde_json::from_str(src).unwrap();
let raw = grammar.codegen_hermes();
let in_mod = quote! {
pub mod generated {
#raw
}
};

let parsed = syn::parse_file(&in_mod.to_string()).unwrap();
format!(
"// {}generated\n{}",
'\u{0040}',
prettyplease::unparse(&parsed)
)
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Grammar {
Expand Down
1 change: 1 addition & 0 deletions unsupported/hermes/crates/hermes_estree_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ mod codegen;

pub use codegen::estree;
pub use codegen::estree_hermes;
pub use codegen::estree_hermes_mod;
pub use codegen::estree_mod;
11 changes: 8 additions & 3 deletions unsupported/hermes/crates/hermes_parser/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

use hermes_estree_codegen::estree_hermes;
use std::env;
use std::path::Path;

use hermes_estree_codegen::estree_hermes_mod;

// Example custom build script.
fn main() {
Expand All @@ -15,6 +18,8 @@ fn main() {
println!("cargo:rerun-if-changed=../hermes_estree_codegen/src/ecmascript.json");
println!("cargo:rerun-if-changed=../hermes_estree_codegen");

let src = estree_hermes();
std::fs::write("src/generated.rs", src).unwrap();
let src = estree_hermes_mod();
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("generated.rs");
std::fs::write(dest_path, src).unwrap();
}
Loading

0 comments on commit e1a177c

Please sign in to comment.