improve core build script logic
Output a helpful error message mentioning why SSL_CERT_FILE is needed.
Allow debug builds to succeed without the SSL_CERT_FILE making the dev
cycle simpler and unblocking new contributors who may not understand
the failure to build with a simple cargo build.
@@ -22,9 +22,30 @@ fn main() {
fn main() { populate_cacert(); }
pub fn populate_cacert() {
- let src = env::var("SSL_CERT_FILE").unwrap();
+ if let Ok(src) = env::var("SSL_CERT_FILE") {
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("cacert.pem");
if !dst.exists() {
- fs::copy(src, dst).unwrap();
+ fs::copy(&src, &dst).unwrap_or_else(|_| {
+ panic!("Failed to copy CA certificates from '{}' to '{}' for \
+ compiliation.",
+ src,
+ dst.display())
+ });
+ }
+ } else if env::var("PROFILE").unwrap() == "release" {
+ panic!("SSL_CERT_FILE environment variable must contain path to minimal CA certificates \
+ files to be used by Habitat in environments where core/cacerts package or native \
+ platform CA certificates are not available.");
+ } else {
+ let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("cacert.pem");
+ fs::write(&dst, "").unwrap_or_else(|_| {
+ panic!("Failed to write empty CA certificates file at '{}' for \
+ compiliation.",
+ dst.display())
+ });
+ println!("cargo:warning=SSL_CERT_FILE environment variable is not specified. Habitat \
+ will be built without a minimal set of CA root certificates. This may cause it \
+ to fail on https requests in environments where core/cacerts package or native \
+ platform CA certificates are not available.");
}
}
