MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / write_generated_extension_api

Function write_generated_extension_api

xtask/src/extension_catalog.rs:484–578  ·  view source on GitHub ↗
(catalog: &ExtensionCatalog)

Source from the content-addressed store, hash-verified

482}
483
484fn write_generated_extension_api(catalog: &ExtensionCatalog) -> Result<()> {
485 let promoted = promoted_extensions(catalog);
486 let candidates = packaged_extensions(catalog);
487 let mut text = String::new();
488 text.push_str("// @generated by `cargo run -p xtask -- extensions generate`\n\n");
489 text.push_str("use super::{Extension, ExtensionSetup};\n\n");
490 text.push_str("const EMPTY_SQL_NAMES: &[&str] = &[];\n");
491 text.push_str("const EMPTY_SQL: &[&str] = &[];\n\n");
492
493 for extension in &candidates {
494 let prefix = extension.rust_constant.as_str();
495 let candidate_const = format!("CANDIDATE_{prefix}");
496 let dependencies = api_dependencies(extension);
497 if dependencies.is_empty() {
498 text.push_str(&format!(
499 "const {candidate_const}_DEPENDENCIES: &[&str] = EMPTY_SQL_NAMES;\n"
500 ));
501 } else {
502 text.push_str(&format!(
503 "const {candidate_const}_DEPENDENCIES: &[&str] = &{};\n",
504 rust_string_array(&dependencies)
505 ));
506 }
507 if extension.lifecycle.load_sql.is_empty() {
508 text.push_str(&format!(
509 "const {candidate_const}_LOAD_SQL: &[&str] = EMPTY_SQL;\n"
510 ));
511 } else {
512 text.push_str(&format!(
513 "const {candidate_const}_LOAD_SQL: &[&str] = &{};\n",
514 rust_string_array(&extension.lifecycle.load_sql)
515 ));
516 }
517 if extension.lifecycle.post_create_sql.is_empty() {
518 text.push_str(&format!(
519 "const {candidate_const}_POST_CREATE_SQL: &[&str] = EMPTY_SQL;\n"
520 ));
521 } else {
522 text.push_str(&format!(
523 "const {candidate_const}_POST_CREATE_SQL: &[&str] = &{};\n",
524 rust_string_array(&extension.lifecycle.post_create_sql)
525 ));
526 }
527 text.push('\n');
528 let archive = extension
529 .promotion
530 .archive
531 .as_deref()
532 .ok_or_else(|| anyhow!("packaged extension {} is missing archive", extension.id))?;
533 text.push_str(&format!(
534 "pub(crate) const {candidate_const}: Extension = Extension::new(\n {:?},\n {:?},\n {:?},\n {},\n {},\n {candidate_const}_DEPENDENCIES,\n ExtensionSetup::new(\n {},\n {},\n {candidate_const}_LOAD_SQL,\n {candidate_const}_POST_CREATE_SQL,\n ),\n);\n\n",
535 extension.display_name,
536 extension.sql_name,
537 archive,
538 option_string_literal(extension.native_module_file.as_deref()),
539 option_string_literal(
540 extension
541 .native_module_file

Callers 1

extensionsFunction · 0.85

Calls 6

promoted_extensionsFunction · 0.85
packaged_extensionsFunction · 0.85
api_dependenciesFunction · 0.85
pushMethod · 0.80
iterMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected