|
| 1 | +use std::collections::BTreeMap; |
| 2 | + |
1 | 3 | use sqlx::Acquire; |
2 | 4 |
|
3 | 5 | use harmonia_store_core::store_path::StoreDir; |
@@ -338,12 +340,14 @@ impl Connection { |
338 | 340 | CROSS JOIN LATERAL ( |
339 | 341 | SELECT o.path |
340 | 342 | FROM buildsteps s |
| 343 | + LEFT JOIN buildsteps sr |
| 344 | + ON s.build = sr.build AND s.resolvedToStep = sr.stepnr |
341 | 345 | JOIN buildstepoutputs o |
342 | | - ON s.build = o.build AND s.stepnr = o.stepnr |
| 346 | + ON s.build = o.build AND (s.stepnr = o.stepnr OR sr.stepnr = o.stepnr) |
343 | 347 | WHERE s.drvPath = r.drv_path |
344 | 348 | AND o.name = i.chain[r.step] |
345 | 349 | AND o.path IS NOT NULL |
346 | | - AND s.status = 0 |
| 350 | + AND (s.status = 0 OR (s.status = 13 AND sr.status = 0)) |
347 | 351 | ORDER BY s.build DESC |
348 | 352 | LIMIT 1 |
349 | 353 | ) sub |
@@ -648,6 +652,16 @@ impl Transaction<'_> { |
648 | 652 | Ok(()) |
649 | 653 | } |
650 | 654 |
|
| 655 | + #[tracing::instrument(skip(self), err)] |
| 656 | + pub async fn find_build_step_outputs( |
| 657 | + &mut self, |
| 658 | + drv_path: &str, |
| 659 | + ) -> sqlx::Result<BTreeMap<String, String>> { |
| 660 | + let items: Vec<(String, String)> = sqlx::query_as("SELECT o.name, o.path FROM buildstepoutputs o JOIN buildsteps s ON s.stepnr = o.stepnr WHERE s.drvpath = ? AND o.path IS NOT NULL").bind(drv_path).fetch_all(&mut *self.tx).await?; |
| 661 | + |
| 662 | + Ok(items.into_iter().collect()) |
| 663 | + } |
| 664 | + |
651 | 665 | #[tracing::instrument(skip(self, res), err)] |
652 | 666 | pub async fn update_build_step_in_finish( |
653 | 667 | &mut self, |
@@ -879,6 +893,79 @@ impl Transaction<'_> { |
879 | 893 | Ok(step_nr) |
880 | 894 | } |
881 | 895 |
|
| 896 | + /// Set resolvedToBuild/resolvedToStep on a dependency step after the |
| 897 | + /// resolved step has been created, linking the dependency to its resolution. |
| 898 | + #[tracing::instrument(skip(self), err)] |
| 899 | + pub async fn set_resolved_to( |
| 900 | + &mut self, |
| 901 | + origin_build_id: crate::models::BuildID, |
| 902 | + origin_step_nr: i32, |
| 903 | + resolved_step_nr: i32, |
| 904 | + ) -> sqlx::Result<()> { |
| 905 | + sqlx::query( |
| 906 | + r" |
| 907 | + UPDATE buildsteps |
| 908 | + SET resolvedToStep = $3 |
| 909 | + WHERE build = $1 AND stepnr = $2 |
| 910 | + ", |
| 911 | + ) |
| 912 | + .bind(origin_build_id) |
| 913 | + .bind(origin_step_nr) |
| 914 | + .bind(resolved_step_nr) |
| 915 | + .execute(&mut *self.tx) |
| 916 | + .await?; |
| 917 | + Ok(()) |
| 918 | + } |
| 919 | + |
| 920 | + #[tracing::instrument( |
| 921 | + skip(self, start_time, stop_time, build_id, drv_path, outputs,), |
| 922 | + err, |
| 923 | + ret |
| 924 | + )] |
| 925 | + pub async fn create_local_step( |
| 926 | + &mut self, |
| 927 | + start_time: i32, |
| 928 | + stop_time: i32, |
| 929 | + build_id: crate::models::BuildID, |
| 930 | + drv_path: &str, |
| 931 | + outputs: BTreeMap<String, String>, |
| 932 | + ) -> anyhow::Result<i32> { |
| 933 | + let step_nr = loop { |
| 934 | + if let Some(step_nr) = self |
| 935 | + .insert_build_step(InsertBuildStep { |
| 936 | + build_id, |
| 937 | + r#type: crate::models::BuildType::Substitution, |
| 938 | + drv_path, |
| 939 | + status: BuildStatus::Success, |
| 940 | + busy: false, |
| 941 | + start_time: Some(start_time), |
| 942 | + stop_time: Some(stop_time), |
| 943 | + platform: None, |
| 944 | + propagated_from: None, |
| 945 | + error_msg: None, |
| 946 | + machine: "", |
| 947 | + }) |
| 948 | + .await? |
| 949 | + { |
| 950 | + break step_nr; |
| 951 | + } |
| 952 | + }; |
| 953 | + |
| 954 | + let output_items: Vec<_> = outputs |
| 955 | + .into_iter() |
| 956 | + .map(|(name, path)| InsertBuildStepOutput::<String> { |
| 957 | + build_id, |
| 958 | + step_nr, |
| 959 | + name, |
| 960 | + path: Some(path), |
| 961 | + }) |
| 962 | + .collect(); |
| 963 | + |
| 964 | + self.insert_build_step_outputs(&output_items).await?; |
| 965 | + |
| 966 | + Ok(step_nr) |
| 967 | + } |
| 968 | + |
882 | 969 | #[tracing::instrument( |
883 | 970 | skip(self, start_time, stop_time, build_id, drv_path, output,), |
884 | 971 | err, |
|
0 commit comments