Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub(crate) const RULE_FIX_AVAILABLE_NOTE: &str =
pub(crate) const RULES_NATIVE_API_VERSION: i64 = 1;
/// File name of the custom-rule result cache under the project cache directory.
pub(crate) const CUSTOM_RULES_CACHE_FILE: &str = "custom-rules.json";
/// Bulk cache subdirectory of a selected run's whole-project pass, kept apart from its slice's.
pub(crate) const WHOLE_PROJECT_CACHE_DIRECTORY: &str = "whole-project";
/// Suffix of a custom host scratch directory abandoned by a cancelled run.
pub(crate) const CUSTOM_HOST_ABANDONED_SUFFIX: &str = ".abandoned";
/// Marker file whose presence tells split custom hosts the run was cancelled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::bindings::_helpers::rules::custom_rule_evidence::custom_rule_implemen
use crate::bindings::_helpers::rules::custom_rule_evidence::custom_rule_import_closure;
use crate::bindings::_helpers::rules::fact_encoder::{Encoded, reproducible};
use crate::bindings::_helpers::rules::fact_replay::{FactReplay, is_tree_fact};
use crate::bindings::_helpers::rules::rule_run::rules_bulk_cache_path;
use crate::bindings::_helpers::rules::rule_run::bulk_cache_file;

const PROJECT_SUBJECT: &str = "project";
const MODEL_SUBJECT: &str = "model";
Expand All @@ -49,6 +49,8 @@ pub(crate) struct CustomRun<'a, 'py> {
pub(crate) verify_determinism: bool,
pub(crate) implementation_fingerprints: HashMap<String, String>,
pub(crate) cancel: HostCancel,
/// The bulk cache subdirectory of the result cache, the bulk cache itself when `None`.
pub(crate) cache_directory: Option<&'a str>,
}

/// Reuse results whose recorded fact reads are unchanged and evaluate only the rest.
Expand Down Expand Up @@ -88,8 +90,9 @@ pub(crate) fn evaluate_custom_rules_cached<'py>(
rows.push((code.clone(), identity, subject_value(rule)?));
}
let cache_path: Option<PathBuf> = if enabled {
Some(rules_bulk_cache_path(
run.project_dir.extract()?,
Some(bulk_cache_file(
&run.project_dir.extract::<PathBuf>()?,
run.cache_directory,
CUSTOM_RULES_CACHE_FILE,
))
} else {
Expand Down
34 changes: 25 additions & 9 deletions crates/sqlbuild-python/src/bindings/_helpers/rules/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use sqlbuild_rules::models::{
Declaration, DeclarationMember, EvaluateRequest, Fault, Model, ModelRow, ModelRowsContext,
RowsEvaluation, RowsRequest, RulesConfig,
};
use sqlbuild_rules::rule_cache::main::rules_bulk_cache_path::rules_bulk_cache_path;

use crate::bindings::_helpers::boundary::keyword_request::Request;
use crate::bindings::_helpers::boundary::panics::{compiler_guard, value_error};
Expand All @@ -42,6 +41,7 @@ use crate::bindings::_helpers::rules::config_json::asdict_json;
use crate::bindings::_helpers::rules::early_builtin_rules::EarlyBuiltinRules;
use crate::bindings::_helpers::rules::fact_replay::{project_attribute, project_models};
use crate::bindings::_helpers::rules::findings::{FindingClasses, finding_fault};
use crate::bindings::_helpers::rules::rule_run::bulk_cache_file;
use crate::bindings::_helpers::rules::selection::rules_error;
use crate::bindings::_helpers::rules::sql_test_objects::{scenario_fact, sql_test_fact};
use crate::bindings::_helpers::scopes::scope_reports::metadata_projection_value;
Expand Down Expand Up @@ -157,9 +157,9 @@ pub(crate) fn selectionless_rules_request(
custom_payloads: &Bound<'_, PyAny>,
) -> PyResult<NativeRulesRequest> {
let py: Python<'_> = config.py();
let header: PyResult<Value> = dialect
.into_bound_py_any(py)
.and_then(|dialect| request_header(config, project_dir, &dialect, (None, custom_payloads)));
let header: PyResult<Value> = dialect.into_bound_py_any(py).and_then(|dialect| {
request_header(config, project_dir, &dialect, (None, custom_payloads, None))
});
as_rules_error(
py,
header.and_then(|header| {
Expand All @@ -178,12 +178,16 @@ pub(crate) fn selectionless_rules_request(
)
}

/// The request's version, paths, dialect, config, custom rules and, when given, scope index.
/// The request's version, paths, dialect, config, custom rules, cache files and scope index.
fn request_header(
config: &Bound<'_, PyAny>,
project_dir: &Bound<'_, PyAny>,
dialect: &Bound<'_, PyAny>,
(project, custom_payloads): (Option<&Bound<'_, PyAny>>, &Bound<'_, PyAny>),
(project, custom_payloads, cache_directory): (
Option<&Bound<'_, PyAny>>,
&Bound<'_, PyAny>,
Option<&str>,
),
) -> PyResult<Value> {
let py: Python<'_> = config.py();
let resolved: Bound<'_, PyAny> = project_dir.call_method0("resolve")?;
Expand All @@ -202,7 +206,7 @@ fn request_header(
header["custom_rules"] = plain_value(custom_payloads)?;
header["rules_cache_path"] = Value::String(path_text(
py,
rules_bulk_cache_path(&resolved_path, NATIVE_RULES_CACHE_FILE),
bulk_cache_file(&resolved_path, cache_directory, NATIVE_RULES_CACHE_FILE),
)?);
Ok(header)
}
Expand All @@ -216,11 +220,19 @@ fn built_request(
let config: Bound<'_, PyAny> = options.get("config")?;
let project_dir: Bound<'_, PyAny> = options.get("project_dir")?;
let dialect: Bound<'_, PyAny> = options.get("dialect")?;
let cache_directory: Option<String> = match options.optional("cache_directory")? {
Some(directory) if !directory.is_none() => Some(directory.extract()?),
_ => None,
};
let header: Value = request_header(
&config,
&project_dir,
&dialect,
(Some(&project), &options.get("custom_payloads")?),
(
Some(&project),
&options.get("custom_payloads")?,
cache_directory.as_deref(),
),
)?;
let (public_enums, public_constants) = declaration_rows(
PyTuple::new(
Expand All @@ -241,7 +253,11 @@ fn built_request(
current_code_identity(py)?,
path_text(
py,
rules_bulk_cache_path(&unresolved, NATIVE_RULES_MEMO_FILE),
bulk_cache_file(
&unresolved,
cache_directory.as_deref(),
NATIVE_RULES_MEMO_FILE,
),
)?,
))
} else {
Expand Down
Loading
Loading