MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / generate_bytecode_cache

Function generate_bytecode_cache

llrt_core/build.rs:93–219  ·  view source on GitHub ↗
(out_dir: &str)

Source from the content-addressed store, hash-verified

91}
92
93fn generate_bytecode_cache(out_dir: &str) -> StdResult<(), Box<dyn Error>> {
94 let resolver = (DummyResolver,);
95 let loader = (DummyLoader,);
96
97 let rt = Runtime::new()?;
98 rt.set_loader(resolver, loader);
99 let ctx = Context::full(&rt)?;
100
101 let bytecode_cache_path = Path::new(&out_dir).join("bytecode_cache.rs");
102 let mut bytecode_cache_file = BufWriter::new(File::create(bytecode_cache_path)?);
103
104 let mut ph_map = phf_codegen::Map::<String>::new();
105 let mut lrt_filenames = vec![];
106 let mut total_bytes: usize = 0;
107
108 fs::write("../VERSION", env!("CARGO_PKG_VERSION")).expect("Unable to write VERSION file");
109
110 #[cfg(feature = "lambda")]
111 let test_file = PathBuf::new().join("@llrt").join("test.js");
112
113 ctx.with(|ctx| {
114 for dir_ent in WalkDir::new(BUNDLE_JS_DIR).into_iter().flatten() {
115 let path = dir_ent.path();
116
117 let path = path.strip_prefix(BUNDLE_JS_DIR)?.to_owned();
118
119 let path_str = path.to_string_lossy().to_string();
120
121 if path_str.starts_with("__tests__") || path.extension().unwrap_or_default() != "js" {
122 continue;
123 }
124
125 #[cfg(feature = "lambda")]
126 {
127 if path == test_file {
128 continue;
129 }
130 }
131
132 #[cfg(feature = "no-sdk")]
133 {
134 if path_str.starts_with("@aws-sdk")
135 || path_str.starts_with("@smithy")
136 || path_str.starts_with("llrt-chunk-sdk")
137 {
138 continue;
139 }
140 }
141
142 let source = fs::read_to_string(dir_ent.path())
143 .unwrap_or_else(|_| panic!("Unable to load: {}", dir_ent.path().to_string_lossy()));
144
145 let module_name = if !path_str.starts_with("llrt-") {
146 path.with_extension("")
147 .to_string_lossy()
148 .replace('\\', "/")
149 .replace("@llrt/", "llrt:")
150 } else {

Callers 1

mainFunction · 0.85

Calls 11

fromFunction · 0.85
add_bytecode_headerFunction · 0.85
compress_bytecodeFunction · 0.85
joinMethod · 0.80
pushMethod · 0.80
writeMethod · 0.65
writeFunction · 0.50
to_stringMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected