-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `Builder` struct defines the public interface for building a PGXN release. Internally, it delegates `configure`, `compile`, and `test` commands (so far) to pipeline-specific build modules. Its `new` constructor reads the pgxn_meta Release pipeline to determine which one to instantiate; in the future it will also fall back on detecting the pipeline where none is specified. The `error` module define errors returned by the crate, while the `pipeline` module defines a trait with the functions `Builder` expects to dispatch to. All pipelines must implement this trait. This will make it easy to add new pipelines in the future; They just have to implement the trait, add a new `Build` enum, then add appropriate calls to its methods in `Builder`'s dispatching methods. For now, the `pgxs` and `pgrx` modules alone define structs that implement the `pipeline.Pipeline` trait with no-op functions. Add tests for basic functionality of `Builder`.
- Loading branch information
Showing
8 changed files
with
1,227 additions
and
28 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//! Build Errors. | ||
use thiserror::Error; | ||
|
||
/// Build errors. | ||
#[derive(Error, Debug, PartialEq)] | ||
pub enum BuildError { | ||
/// Errors configuring a build. | ||
#[error("configuration failure")] | ||
Configuration(), | ||
|
||
/// Unknown pipeline error. | ||
#[error("unknown build pipeline `{0}`")] | ||
UnknownPipeline(String), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! Builder implementation for [pgrx] Pipelines. | ||
//! | ||
//! [pgrx]: https://github.com/pgcentralfoundation/pgrx | ||
use crate::error::BuildError; | ||
use crate::pipeline::Pipeline; | ||
use pgxn_meta::release::Release; | ||
|
||
/// Builder implementation for [pgrx] Pipelines. | ||
/// | ||
/// [pgrx]: https://github.com/pgcentralfoundation/pgrx | ||
#[derive(Debug, PartialEq)] | ||
pub(crate) struct Pgrx { | ||
meta: Release, | ||
} | ||
|
||
impl Pipeline for Pgrx { | ||
fn new(meta: Release) -> Self { | ||
Pgrx { meta } | ||
} | ||
fn configure(&self) -> Result<(), BuildError> { | ||
Ok(()) | ||
} | ||
|
||
fn compile(&self) -> Result<(), BuildError> { | ||
Ok(()) | ||
} | ||
|
||
fn test(&self) -> Result<(), BuildError> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! Builder implementation for [PGXS] Pipelines. | ||
//! | ||
//! [PGXS]: https://www.postgresql.org/docs/current/extend-pgxs.html | ||
use crate::error::BuildError; | ||
use crate::pipeline::Pipeline; | ||
use pgxn_meta::release::Release; | ||
|
||
/// Builder implementation for [PGXS] Pipelines. | ||
/// | ||
/// [PGXS]: https://www.postgresql.org/docs/current/extend-pgxs.html | ||
#[derive(Debug, PartialEq)] | ||
pub(crate) struct Pgxs { | ||
meta: Release, | ||
} | ||
|
||
impl Pipeline for Pgxs { | ||
fn new(meta: Release) -> Self { | ||
Pgxs { meta } | ||
} | ||
|
||
fn configure(&self) -> Result<(), BuildError> { | ||
Ok(()) | ||
} | ||
|
||
fn compile(&self) -> Result<(), BuildError> { | ||
Ok(()) | ||
} | ||
|
||
fn test(&self) -> Result<(), BuildError> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! Build Pipeline interface definition. | ||
use crate::error::BuildError; | ||
use pgxn_meta::release::Release; | ||
|
||
/// Defines the interface for build pipelines to configure, compile, and test | ||
/// PGXN distributions. | ||
pub(crate) trait Pipeline { | ||
/// Creates an instance of a Builder. | ||
fn new(meta: Release) -> Self; | ||
|
||
/// Configures a distribution to build on a particular platform and | ||
/// Postgres version. | ||
fn configure(&self) -> Result<(), BuildError>; | ||
|
||
/// Compiles a distribution on a particular platform and Postgres version. | ||
fn compile(&self) -> Result<(), BuildError>; | ||
|
||
/// Tests a distribution a particular platform and Postgres version. | ||
fn test(&self) -> Result<(), BuildError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use super::*; | ||
use serde_json::{json, Value}; | ||
|
||
fn release_meta(pipeline: &str) -> Value { | ||
json!({ | ||
"name": "pair", | ||
"abstract": "A key/value pair data type", | ||
"version": "0.1.8", | ||
"maintainers": [ | ||
{ "name": "David E. Wheeler", "email": "[email protected]" } | ||
], | ||
"license": "PostgreSQL", | ||
"contents": { | ||
"extensions": { | ||
"pair": { | ||
"sql": "sql/pair.sql", | ||
"control": "pair.control" | ||
} | ||
} | ||
}, | ||
"dependencies": { "pipeline": pipeline }, | ||
"meta-spec": { "version": "2.0.0" }, | ||
"certs": { | ||
"pgxn": { | ||
"payload": "eyJ1c2VyIjoidGhlb3J5IiwiZGF0ZSI6IjIwMjQtMDktMTNUMTc6MzI6NTVaIiwidXJpIjoiZGlzdC9wYWlyLzAuMS43L3BhaXItMC4xLjcuemlwIiwiZGlnZXN0cyI6eyJzaGE1MTIiOiJiMzUzYjVhODJiM2I1NGU5NWY0YTI4NTllN2EyYmQwNjQ4YWJjYjM1YTdjMzYxMmIxMjZjMmM3NTQzOGZjMmY4ZThlZTFmMTllNjFmMzBmYTU0ZDdiYjY0YmNmMjE3ZWQxMjY0NzIyYjQ5N2JjYjYxM2Y4MmQ3ODc1MTUxNWI2NyJ9fQ", | ||
"signature": "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q", | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
#[test] | ||
fn pgxs() { | ||
// Test pgxs pipeline. | ||
let meta = release_meta("pgxs"); | ||
let rel = Release::try_from(meta.clone()).unwrap(); | ||
let builder = Builder::new(rel).unwrap(); | ||
let rel = Release::try_from(meta).unwrap(); | ||
let exp = Builder(Build::Pgxs(Pgxs::new(rel))); | ||
assert_eq!(exp, builder, "pgxs"); | ||
assert!(builder.download().is_ok()); | ||
assert!(builder.unpack().is_ok()); | ||
assert!(builder.configure().is_ok()); | ||
assert!(builder.compile().is_ok()); | ||
assert!(builder.test().is_ok()); | ||
} | ||
|
||
#[test] | ||
fn pgrx() { | ||
// Test pgrx pipeline. | ||
let meta = release_meta("pgrx"); | ||
let rel = Release::try_from(meta.clone()).unwrap(); | ||
let builder = Builder::new(rel).unwrap(); | ||
let rel = Release::try_from(meta).unwrap(); | ||
let exp = Builder(Build::Pgrx(Pgrx::new(rel))); | ||
assert_eq!(exp, builder, "pgrx"); | ||
assert!(builder.download().is_ok()); | ||
assert!(builder.unpack().is_ok()); | ||
assert!(builder.configure().is_ok()); | ||
assert!(builder.compile().is_ok()); | ||
assert!(builder.test().is_ok()); | ||
} | ||
|
||
#[test] | ||
fn unsupported_pipeline() { | ||
// Test unsupported pipeline. | ||
let meta = release_meta("meson"); | ||
let rel = Release::try_from(meta).unwrap(); | ||
assert_eq!( | ||
BuildError::UnknownPipeline("meson".to_string()), | ||
Builder::new(rel).unwrap_err(), | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Detect pipeline")] | ||
fn detect_pipeline() { | ||
// Test unspecified pipeline. | ||
let mut meta = release_meta(""); | ||
meta.as_object_mut().unwrap().remove("dependencies"); | ||
let rel = Release::try_from(meta).unwrap(); | ||
_ = Builder::new(rel); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Detect pipeline")] | ||
fn no_pipeline() { | ||
// Test unspecified pipeline. | ||
let mut meta = release_meta(""); | ||
let deps = meta | ||
.as_object_mut() | ||
.unwrap() | ||
.get_mut("dependencies") | ||
.unwrap() | ||
.as_object_mut() | ||
.unwrap(); | ||
|
||
deps.remove("pipeline"); | ||
deps.insert("postgres".to_string(), json!({"version": "14"})); | ||
let rel = Release::try_from(meta).unwrap(); | ||
_ = Builder::new(rel); | ||
} |