MCPcopy Create free account
hub / github.com/encounter/objdiff / run_create_scratch

Function run_create_scratch

objdiff-core/src/jobs/create_scratch.rs:41–105  ·  view source on GitHub ↗
(
    status: &JobContext,
    cancel: Receiver<()>,
    config: CreateScratchConfig,
)

Source from the content-addressed store, hash-verified

39const API_HOST: &str = "https://decomp.me";
40
41fn run_create_scratch(
42 status: &JobContext,
43 cancel: Receiver<()>,
44 config: CreateScratchConfig,
45) -> Result<Box<CreateScratchResult>> {
46 let project_dir =
47 config.build_config.project_dir.as_ref().ok_or_else(|| anyhow!("Missing project dir"))?;
48
49 let mut context = None;
50 if let Some(context_path) = &config.context_path {
51 if config.build_context {
52 update_status(status, "Building context".to_string(), 0, 2, &cancel)?;
53 match run_make(&config.build_config, context_path.as_ref()) {
54 BuildStatus { success: true, .. } => {}
55 BuildStatus { success: false, stdout, stderr, .. } => {
56 bail!("Failed to build context:\n{stdout}\n{stderr}")
57 }
58 }
59 }
60 let context_path = project_dir.join(context_path.with_platform_encoding());
61 context = Some(
62 fs::read_to_string(&context_path)
63 .map_err(|e| anyhow!("Failed to read {}: {}", context_path, e))?,
64 );
65 }
66
67 update_status(status, "Creating scratch".to_string(), 1, 2, &cancel)?;
68 let diff_flags = [format!("--disassemble={}", config.function_name)];
69 let diff_flags = serde_json::to_string(&diff_flags)?;
70 let file = reqwest::blocking::multipart::Part::file(&config.target_obj)
71 .with_context(|| format!("Failed to open {}", config.target_obj))?;
72 let mut form = reqwest::blocking::multipart::Form::new()
73 .text("compiler", config.compiler.clone())
74 .text("platform", config.platform.clone())
75 .text("compiler_flags", config.compiler_flags.clone())
76 .text("diff_label", config.function_name.clone())
77 .text("diff_flags", diff_flags)
78 .text("context", context.unwrap_or_default())
79 .text("source_code", "// Move related code from Context tab to here")
80 .text(
81 "name",
82 config
83 .demangler
84 .demangle(&config.function_name)
85 .unwrap_or_else(|| config.function_name.clone()),
86 );
87 if let Some(preset) = config.preset_id {
88 form = form.text("preset", preset.to_string());
89 }
90 form = form.part("target_obj", file);
91 let client = reqwest::blocking::Client::new();
92 let response = client
93 .post(format!("{API_HOST}/api/scratch"))
94 .multipart(form)
95 .send()
96 .map_err(|e| anyhow!("Failed to send request: {}", e))?;
97 if !response.status().is_success() {
98 return Err(anyhow!("Failed to create scratch: {}", response.text()?));

Callers 1

start_create_scratchFunction · 0.85

Calls 2

update_statusFunction · 0.85
demangleMethod · 0.80

Tested by

no test coverage detected