Skip to content

Commit cd632df

Browse files
feat: always log json parameters to debug folder (#433)
* chore: always log json parameters to debug folder * Update backends/pixi-build-ros/src/pixi_build_ros/config.py Co-authored-by: nichmor <[email protected]> * Fix some comments * Save to the correct work directory * Change directory back * Fix test --------- Co-authored-by: nichmor <[email protected]>
1 parent 8afc967 commit cd632df

File tree

21 files changed

+182
-199
lines changed

21 files changed

+182
-199
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backends/pixi-build-ros/src/pixi_build_ros/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import warnings
34
from pathlib import Path
45
from typing import Any
56

@@ -192,6 +193,18 @@ def _parse_debug_dir(cls, value: Any, info: pydantic.ValidationInfo) -> Path | N
192193
base_path = Path(info.context["manifest_root"])
193194
return _parse_str_as_abs_path(value, base_path)
194195

196+
@pydantic.model_validator(mode="after")
197+
def _warn_deprecated_debug_dir(self) -> "ROSBackendConfig":
198+
"""Warn when the deprecated debug_dir setting is used."""
199+
if self.debug_dir:
200+
warnings.warn(
201+
"`debug-dir` backend configuration is deprecated and ignored, it will be removed later. "
202+
"Debug data is now written to the build work directory.",
203+
UserWarning,
204+
stacklevel=2,
205+
)
206+
return self
207+
195208
@pydantic.field_validator("extra_package_mappings", mode="before")
196209
@classmethod
197210
def _parse_package_mappings(

backends/pixi-build-ros/src/pixi_build_ros/ros_generator.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ def generate_recipe(
160160
env=script_env,
161161
)
162162

163-
if backend_config.debug_dir:
164-
recipe = generated_recipe.recipe.to_yaml()
165-
package = generated_recipe.recipe.package
166-
debug_file_path = backend_config.debug_dir / f"{package.name.get_concrete()}-{package.version}-recipe.yaml"
167-
debug_file_path.parent.mkdir(parents=True, exist_ok=True)
168-
with open(debug_file_path, "w") as debug_file:
169-
debug_file.write(recipe)
170-
171163
# Test the build script before running to early out.
172164
# TODO: returned script.content list is not a list of strings, a container for that
173165
# so it cant be compared directly with the list yet
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const DEBUG_OUTPUT_DIR: &str = "debug";

crates/pixi-build-backend/src/intermediate_backend.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ use rattler_build::{
3434
use rattler_conda_types::{Platform, compression_level::CompressionLevel, package::ArchiveType};
3535

3636
use serde::Deserialize;
37+
use tracing::warn;
3738

3839
use crate::{
3940
TargetSelector,
41+
consts::DEBUG_OUTPUT_DIR,
4042
dependencies::{
4143
convert_binary_dependencies, convert_dependencies, convert_input_variant_configuration,
4244
},
@@ -129,6 +131,13 @@ impl<T: GenerateRecipe> IntermediateBackend<T> {
129131
.into_diagnostic()
130132
.context("failed to parse configuration")?;
131133

134+
if let Some(path) = config.debug_dir() {
135+
warn!(
136+
path = %path.display(),
137+
"`debug-dir` backend configuration is deprecated and ignored; debug data is now written to the build work directory."
138+
);
139+
}
140+
132141
let target_config = target_config
133142
.into_iter()
134143
.map(|(target, config)| {
@@ -160,12 +169,6 @@ where
160169
T: GenerateRecipe + Clone + Send + Sync + 'static,
161170
T::Config: Send + Sync + 'static,
162171
{
163-
fn debug_dir(configuration: Option<serde_json::Value>) -> Option<PathBuf> {
164-
configuration
165-
.and_then(|config| serde_json::from_value::<T::Config>(config).ok())
166-
.and_then(|config| config.debug_dir().map(|d| d.to_path_buf()))
167-
}
168-
169172
async fn initialize(
170173
&self,
171174
params: InitializeParams,
@@ -217,10 +220,6 @@ where
217220
T: GenerateRecipe + Clone + Send + Sync + 'static,
218221
T::Config: BackendConfig + Send + Sync + 'static,
219222
{
220-
fn debug_dir(&self) -> Option<&Path> {
221-
self.config.debug_dir()
222-
}
223-
224223
async fn conda_outputs(
225224
&self,
226225
params: CondaOutputsParams,
@@ -369,18 +368,18 @@ where
369368
);
370369

371370
// Save intermediate recipe and the used variant
372-
// in the work dir by hash of the variant
373-
// and entire variants.yaml at the root of work_dir
374-
let work_dir = &directories.work_dir;
371+
// in the debug dir by hash of the variant
372+
// and entire variants.yaml at the root of debug_dir
373+
let debug_dir = &directories.build_dir.join("debug");
375374

376-
let recipe_path = work_dir.join("recipe.yaml");
377-
let variants_path = work_dir.join("variants.yaml");
375+
let recipe_path = debug_dir.join("recipe.yaml");
376+
let variants_path = debug_dir.join("variants.yaml");
378377

379-
let package_work_dir = work_dir.join("recipe").join(&hash.hash);
380-
let package_recipe_path = package_work_dir.join("recipe.yaml");
381-
let package_variant_path = package_work_dir.join("variants.yaml");
378+
let package_debug_dir = debug_dir.join("recipe").join(&hash.hash);
379+
let package_recipe_path = package_debug_dir.join("recipe.yaml");
380+
let package_variant_path = package_debug_dir.join("variants.yaml");
382381

383-
tokio_fs::create_dir_all(&package_work_dir)
382+
tokio_fs::create_dir_all(&package_debug_dir)
384383
.await
385384
.into_diagnostic()?;
386385

@@ -398,7 +397,7 @@ where
398397
.await
399398
.into_diagnostic()?;
400399

401-
// write the entire variants.yaml at the root of work_dir
400+
// write the entire variants.yaml at the root of debug_dir
402401
if !variants_saved {
403402
let variants = serde_yaml::to_string(&variant_config)
404403
.into_diagnostic()
@@ -619,21 +618,18 @@ where
619618
);
620619

621620
// Save intermediate recipe and the used variant
622-
// in the work dir by hash of the variant
621+
// in the debug dir by hash of the variant
623622
let variant = discovered_output.used_vars;
624623

625624
// Save intermediate recipe and the used variant
626-
// in the work dir by hash of the variant
627-
// and entire variants.yaml at the root of work_dir
628-
let work_dir = &directories.work_dir;
625+
// in the debug dir by hash of the variant
626+
// and entire variants.yaml at the root of debug_dir
627+
let debug_dir = &directories.build_dir.join(DEBUG_OUTPUT_DIR);
629628

630-
let recipe_path = work_dir.join("recipe.yaml");
631-
let variants_path = work_dir.join("variants.yaml");
629+
let recipe_path = debug_dir.join("recipe.yaml");
630+
let variants_path = debug_dir.join("variants.yaml");
632631

633-
let package_dir = directories
634-
.work_dir
635-
.join("recipe")
636-
.join(&discovered_output.hash.hash);
632+
let package_dir = debug_dir.join("recipe").join(&discovered_output.hash.hash);
637633

638634
let package_recipe_path = package_dir.join("recipe.yaml");
639635
let package_variant_path = package_dir.join("variants.yaml");
@@ -656,7 +652,7 @@ where
656652
.await
657653
.into_diagnostic()?;
658654

659-
// write the entire variants.yaml at the root of work_dir
655+
// write the entire variants.yaml at the root of debug_dir
660656
let variants = serde_yaml::to_string(&variant_config)
661657
.into_diagnostic()
662658
.context("failed to serialize variant config to YAML")?;

crates/pixi-build-backend/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub mod traits;
1717
pub mod utils;
1818
pub mod variants;
1919

20+
pub mod consts;
21+
2022
pub use traits::{PackageSourceSpec, PackageSpec, ProjectModel, TargetSelector, Targets};
2123

2224
pub use cli::main_ext as cli_main;

crates/pixi-build-backend/src/protocol.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::path::{Path, PathBuf};
2-
31
use pixi_build_types::procedures::conda_build_v1::{CondaBuildV1Params, CondaBuildV1Result};
42
use pixi_build_types::procedures::conda_outputs::{CondaOutputsParams, CondaOutputsResult};
53
use pixi_build_types::procedures::{
@@ -11,10 +9,6 @@ use pixi_build_types::procedures::{
119
/// and endpoint that can handle the RPC calls.
1210
#[async_trait::async_trait]
1311
pub trait ProtocolInstantiator: Send + Sync + 'static {
14-
/// Get the debug directory
15-
/// If set, internal state will be logged as files in that directory
16-
fn debug_dir(configuration: Option<serde_json::Value>) -> Option<PathBuf>;
17-
1812
/// Called when negotiating capabilities with the client.
1913
/// This is determine how the rest of the initialization will proceed.
2014
async fn negotiate_capabilities(
@@ -34,10 +28,6 @@ pub trait ProtocolInstantiator: Send + Sync + 'static {
3428
/// server as an endpoint for the RPC calls.
3529
#[async_trait::async_trait]
3630
pub trait Protocol {
37-
/// Get the debug directory
38-
/// If set, internal state will be logged as files in that directory
39-
fn debug_dir(&self) -> Option<&Path>;
40-
4131
/// Called when the client requests outputs for a Conda package.
4232
async fn conda_outputs(
4333
&self,

0 commit comments

Comments
 (0)