-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement choose_postgresql_version script in rust; also allow conf…
…iguration via env var
- Loading branch information
Marshall Pierce
committed
Nov 23, 2016
1 parent
e82bca2
commit 33b4405
Showing
2 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,7 +1,49 @@ | ||
use std::process::Command; | ||
use std::env; | ||
use std::fs; | ||
use std::os::unix::fs::symlink; | ||
|
||
fn main() { | ||
let output = Command::new("util/choose_postgresql_version").output().unwrap_or_else(|e| { | ||
panic!("Failed to execute process: {}", e) | ||
}); | ||
|
||
// allow configuration via env var. Set to the version number itself, like "9.5.3". | ||
let env_var = env::var("RPGFFI_PG_VERSION"); | ||
let pg_vers = if env_var.is_ok() { | ||
env_var.unwrap() | ||
} else { | ||
let cmd_vers = Command::new("pg_config").arg("--version").output().unwrap_or_else(|e| { | ||
panic!("Failed to execute pg_config: {}", e) | ||
}); | ||
|
||
if !cmd_vers.status.success() { | ||
panic!("pg_config failed with {}", cmd_vers.status.code().unwrap()); | ||
} | ||
|
||
// transform "PostgreSQL 9.6.1" to "9.6.1" | ||
String::from_utf8(cmd_vers.stdout).unwrap().chars() | ||
.skip_while(|c| *c != ' ') | ||
.skip(1) | ||
.collect::<String>() | ||
}; | ||
|
||
// transform "9.6.1" to "96" | ||
let short_vers = pg_vers.chars() | ||
.filter(|c| *c != '.') | ||
.take(2) | ||
.collect::<String>(); | ||
|
||
match fs::remove_file("src/lib.rs") { | ||
Ok(_) => (), | ||
Err(e) => panic!("couldn't remove lib.rs: {}", e) | ||
} | ||
|
||
let dest_filename = format!("pg{}.rs", short_vers); | ||
|
||
if let Err(_) = fs::File::open(format!("src/{}", dest_filename)) { | ||
panic!("Destination file src/{} does not exist", dest_filename); | ||
} | ||
|
||
if let Err(e) = symlink(dest_filename, "src/lib.rs") { | ||
panic!("Symlink failed: {}", e); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.