MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / ensure_module_in_uproject

Function ensure_module_in_uproject

crates/codegen/src/unrealcpp.rs:6925–6999  ·  view source on GitHub ↗
(uproject_dir: &Path, module_name: &str)

Source from the content-addressed store, hash-verified

6923}
6924
6925fn ensure_module_in_uproject(uproject_dir: &Path, module_name: &str) -> Result<(), String> {
6926 let uproject_file = std::fs::read_dir(uproject_dir)
6927 .map_err(|e| format!("Failed to read Unreal project directory '{}': {e}", uproject_dir.display()))?
6928 .filter_map(|entry| entry.ok())
6929 .find(|entry| {
6930 entry
6931 .path()
6932 .extension()
6933 .and_then(|ext| ext.to_str())
6934 .map(|ext| ext == "uproject")
6935 .unwrap_or(false)
6936 })
6937 .ok_or_else(|| {
6938 format!(
6939 "No .uproject file found in '{}'. Unreal code generation requires a project directory containing a .uproject file.",
6940 uproject_dir.display()
6941 )
6942 })?;
6943
6944 let uproject_path = uproject_file.path();
6945 let content = std::fs::read_to_string(&uproject_path)
6946 .map_err(|e| format!("Failed to read .uproject file '{}': {e}", uproject_path.display()))?;
6947
6948 let mut json: serde_json::Value = serde_json::from_str(&content)
6949 .map_err(|e| format!("Invalid JSON in .uproject file '{}': {e}", uproject_path.display()))?;
6950
6951 if !json.is_object() {
6952 return Err(format!(
6953 "Invalid .uproject file '{}': top-level JSON must be an object.",
6954 uproject_path.display()
6955 ));
6956 }
6957
6958 let json_obj = json
6959 .as_object_mut()
6960 .expect("validated object .uproject JSON should have an object map");
6961
6962 if !json_obj.contains_key("Modules") {
6963 json_obj.insert("Modules".to_string(), serde_json::Value::Array(vec![]));
6964 }
6965
6966 let modules = json_obj
6967 .get_mut("Modules")
6968 .and_then(|m| m.as_array_mut())
6969 .ok_or_else(|| {
6970 format!(
6971 "Invalid .uproject file '{}': 'Modules' must be an array.",
6972 uproject_path.display()
6973 )
6974 })?;
6975
6976 let module_exists = modules.iter().any(|module| {
6977 module
6978 .get("Name")
6979 .and_then(|name| name.as_str())
6980 .map(|name| name == module_name)
6981 .unwrap_or(false)
6982 });

Callers 1

generate_global_filesMethod · 0.85

Calls 15

from_strFunction · 0.85
unwrap_orMethod · 0.80
contains_keyMethod · 0.80
insertMethod · 0.65
iterMethod · 0.65
ErrFunction · 0.50
ArrayFunction · 0.50
OkFunction · 0.50
findMethod · 0.45
okMethod · 0.45
mapMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…