Skip to content

Commit

Permalink
Obtain extension version from Cargo.toml (pgcentralfoundation#345)
Browse files Browse the repository at this point in the history
This change allows the version to flow from Cargo.toml into the control
file. To enable this behavior default_version in the control file must
be set to '@CARGO_VERSION@'.

Fixes pgcentralfoundation#344
  • Loading branch information
JamesGuthrie authored Jan 5, 2022
1 parent 47309db commit f00c335
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 19 deletions.
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-pgx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = [ "*.png" ]


[dependencies]
cargo_metadata = "0.14.1"
clap = { version = "2.34.0", features = [ "yaml" ] }
colored = "2.0.0"
env_proxy = "0.4.1"
Expand Down
14 changes: 12 additions & 2 deletions cargo-pgx/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// governed by the MIT license that can be found in the LICENSE file.

use crate::commands::get::{find_control_file, get_property};
use cargo_metadata::MetadataCommand;
use colored::Colorize;
use pgx_utils::pg_config::PgConfig;
use pgx_utils::{exit_with_error, get_target_dir, handle_result};
Expand Down Expand Up @@ -243,7 +244,16 @@ pub(crate) fn find_library_file(extname: &str, is_release: bool) -> PathBuf {

pub(crate) fn get_version() -> String {
match get_property("default_version") {
Some(v) => v,
Some(v) => {
if v == "@CARGO_VERSION@" {
let metadata = MetadataCommand::new()
.exec()
.expect("failed to parse Cargo.toml");
metadata.root_package().unwrap().version.to_string()
} else {
v
}
},
None => exit_with_error!("cannot determine extension version number. Is the `default_version` property declared in the control file?"),
}
}
Expand Down Expand Up @@ -285,7 +295,7 @@ fn filter_contents(mut input: String) -> String {
input = input.replace("@GIT_HASH@", &get_git_hash());
}

input = input.replace("@DEFAULT_VERSION@", &get_version());
input = input.replace("@CARGO_VERSION@", &get_version());

input
}
2 changes: 1 addition & 1 deletion cargo-pgx/src/templates/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = '{name}: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/{name}'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion nix/templates/default/pgx_demo.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'pgx_demo: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/pgx_demo'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/aggregate/aggregate.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'aggregate: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/aggregate'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/arrays/arrays.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'arrays: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/arrays'
relocatable = false
superuser = false
Expand Down
2 changes: 1 addition & 1 deletion pgx-examples/bad_ideas/bad_ideas.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'bad_ideas: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/bad_ideas'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/bgworker/bgworker.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'bgworker: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/bgworker'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/bytea/bytea.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'bytea: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/bytea'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/custom_sql/custom_sql.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'custom_sql: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/custom_sql'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/custom_types/custom_types.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'custom_types: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/custom_types'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/errors/errors.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'errors: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/errors'
relocatable = false
superuser = false
Expand Down
2 changes: 1 addition & 1 deletion pgx-examples/operators/operators.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'operators: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/operators'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/schemas/schemas.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'schemas: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/schemas'
relocatable = false
superuser = true # b/c this extension creates objects in "pg_catalog"
2 changes: 1 addition & 1 deletion pgx-examples/shmem/shmem.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'shmem: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/shmem'
relocatable = false
superuser = false
2 changes: 1 addition & 1 deletion pgx-examples/spi/spi.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'spi: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/spi'
relocatable = false
superuser = false
Expand Down
2 changes: 1 addition & 1 deletion pgx-examples/srf/srf.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'srf: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/srf'
relocatable = false
superuser = false
Expand Down
2 changes: 1 addition & 1 deletion pgx-examples/strings/strings.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'strings: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/strings'
relocatable = false
superuser = false
Expand Down
2 changes: 1 addition & 1 deletion pgx-examples/triggers/triggers.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
comment = 'triggers: Created by pgx'
default_version = '1.0'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/triggers'
relocatable = false
superuser = false

0 comments on commit f00c335

Please sign in to comment.