fc-queue-server: match output names by path instead of index
Now creates a path-to-name lookup `HashMap` from the outputs JSON and matches each output path to its correct name. Both the `build_outputs` table insert and GC root registration loops now use the same lookup to ensure we're consistent. Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Id9f4ce0be6131a7c1a8ce6775ab249db6a6a6964
This commit is contained in:
parent
ec28069b69
commit
609ac53c3f
1 changed files with 32 additions and 17 deletions
|
|
@ -588,23 +588,35 @@ async fn run_build(
|
|||
};
|
||||
|
||||
if build_result.success {
|
||||
// Parse output names from build's outputs JSON
|
||||
let output_names: Vec<String> = build
|
||||
// Build a reverse lookup map: path -> output_name
|
||||
// The outputs JSON is a HashMap<String, String> where keys are output names
|
||||
// and values are store paths. We need to match paths to names correctly.
|
||||
let path_to_name: std::collections::HashMap<String, String> = build
|
||||
.outputs
|
||||
.as_ref()
|
||||
.and_then(|v| v.as_object())
|
||||
.map(|obj| obj.keys().cloned().collect())
|
||||
.map(|obj| {
|
||||
obj
|
||||
.iter()
|
||||
.filter_map(|(name, path)| {
|
||||
path.as_str().map(|p| (p.to_string(), name.clone()))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
// Store build outputs in normalized table
|
||||
for (i, output_path) in build_result.output_paths.iter().enumerate() {
|
||||
let output_name = output_names.get(i).cloned().unwrap_or_else(|| {
|
||||
if i == 0 {
|
||||
"out".to_string()
|
||||
} else {
|
||||
format!("out{i}")
|
||||
}
|
||||
});
|
||||
let output_name = path_to_name
|
||||
.get(output_path)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
if i == 0 {
|
||||
"out".to_string()
|
||||
} else {
|
||||
format!("out{i}")
|
||||
}
|
||||
});
|
||||
|
||||
if let Err(e) = repo::build_outputs::create(
|
||||
pool,
|
||||
|
|
@ -624,13 +636,16 @@ async fn run_build(
|
|||
|
||||
// Register GC roots and create build products for each output
|
||||
for (i, output_path) in build_result.output_paths.iter().enumerate() {
|
||||
let output_name = output_names.get(i).cloned().unwrap_or_else(|| {
|
||||
if i == 0 {
|
||||
build.job_name.clone()
|
||||
} else {
|
||||
format!("{}-{i}", build.job_name)
|
||||
}
|
||||
});
|
||||
let output_name = path_to_name
|
||||
.get(output_path)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
if i == 0 {
|
||||
build.job_name.clone()
|
||||
} else {
|
||||
format!("{}-{i}", build.job_name)
|
||||
}
|
||||
});
|
||||
|
||||
// Register GC root
|
||||
let mut gc_root_path = None;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue