From c7497f3778a7d17fe45bb3bb8859b159d35f4b20 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 8 Oct 2017 20:09:46 +0100 Subject: [PATCH 1/4] Display more information for non-release releases --- Cargo.lock | 2 +- Cargo.toml | 8 +++++- build.rs | 59 ++++++++++++++++++++++++++++++++++++++++++ src/options/version.rs | 20 ++++++-------- 4 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 build.rs diff --git a/Cargo.lock b/Cargo.lock index c42fe88..8834cc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "exa" -version = "0.8.0" +version = "0.9.0-pre" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "datetime 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 3efefc1..37c4780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "exa" -version = "0.8.0" +version = "0.9.0-pre" authors = [ "ogham@bsago.me" ] +build = "build.rs" description = "A modern replacement for ls" homepage = "https://the.exa.website/" @@ -13,11 +14,13 @@ categories = ["command-line-utilities"] keywords = ["ls", "files", "command-line"] license = "MIT" + [[bin]] name = "exa" path = "src/bin/main.rs" doc = false + [lib] name = "exa" path = "src/exa.rs" @@ -41,6 +44,9 @@ unicode-width = "0.1.4" users = "0.5.2" zoneinfo_compiled = "0.4.5" +[build-dependencies] +datetime = "0.4.5" + [features] default = [ "git" ] git = [ "git2" ] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..909633b --- /dev/null +++ b/build.rs @@ -0,0 +1,59 @@ +/// The version string isn’t the simplest: we want to show the version, +/// current Git hash, and compilation date when building *debug* versions, but +/// just the version for *release* versions so the builds are reproducible. +/// +/// This script generates the string from the environment variables that Cargo +/// adds (http://doc.crates.io/environment-variables.html) and runs `git` to +/// get the SHA1 hash. It then writes the string into a file, which exa then +/// includes at build-time. +/// +/// - https://stackoverflow.com/q/43753491/3484614 +/// - https://crates.io/crates/vergen + +extern crate datetime; +use std::io::Result as IOResult; +use std::env; + +fn git_hash() -> String { + use std::process::Command; + + String::from_utf8_lossy( + &Command::new("git") + .args(&["rev-parse", "--short", "HEAD"]) + .output().unwrap() + .stdout).trim().to_string() +} + +fn main() { + write_statics().unwrap(); +} + +fn is_development_version() -> bool { + env::var("PROFILE").unwrap() == "debug" +} + +fn cargo_version() -> String { + env::var("CARGO_PKG_VERSION").unwrap() +} + +fn build_date() -> String { + use datetime::{LocalDateTime, ISO}; + + let now = LocalDateTime::now(); + format!("{}", now.date().iso()) +} + +fn write_statics() -> IOResult<()> { + use std::fs::File; + use std::io::Write; + use std::path::PathBuf; + + let ver = match is_development_version() { + true => format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date()), + false => format!("exa v{}", cargo_version()), + }; + + let out = PathBuf::from(env::var("OUT_DIR").unwrap()); + let mut f = File::create(&out.join("version_string.txt"))?; + write!(f, "{:?}", ver) +} diff --git a/src/options/version.rs b/src/options/version.rs index fc4fa96..c5b60b9 100644 --- a/src/options/version.rs +++ b/src/options/version.rs @@ -1,16 +1,16 @@ +//! Printing the version string. +//! +//! The code that works out which string to print is done in `build.rs`. + use std::fmt; use options::flags; use options::parser::MatchedFlags; -/// All the information needed to display the version information. #[derive(PartialEq, Debug)] -pub struct VersionString { - - /// The version number from cargo. - cargo: &'static str, -} +pub struct VersionString; +// There were options here once, but there aren’t anymore! impl VersionString { @@ -21,7 +21,7 @@ impl VersionString { /// Like --help, this doesn’t bother checking for errors. pub fn deduce(matches: &MatchedFlags) -> Result<(), VersionString> { if matches.count(&flags::VERSION) > 0 { - Err(VersionString { cargo: env!("CARGO_PKG_VERSION") }) + Err(VersionString) } else { Ok(()) // no version needs to be shown @@ -30,16 +30,12 @@ impl VersionString { } impl fmt::Display for VersionString { - - /// Format this help options into an actual string of help - /// text to be displayed to the user. fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "exa v{}", self.cargo) + write!(f, "{}", include!(concat!(env!("OUT_DIR"), "/version_string.txt"))) } } - #[cfg(test)] mod test { use options::Options; From 2e2598c9a0fe6e84b0e41e2821787b024d8f54a0 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 8 Oct 2017 20:44:34 +0100 Subject: [PATCH 2/4] Rename the zips for weekly releases --- Vagrantfile | 4 ++-- build.rs | 4 +++- devtools/dev-package-for-linux.sh | 12 +++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 189cfd5..9f7b72a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -78,8 +78,8 @@ Vagrant.configure(2) do |config| echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa ln -sf /usr/bin/compile-exa /usr/bin/c - echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh" > /usr/bin/package-exa - echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp + echo -e "#!/bin/sh\nbash /vagrant/devtools/dev-package-for-linux.sh \\$@" > /usr/bin/package-exa + echo -e "#!/bin/sh\ncat /etc/motd" > /usr/bin/halp chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa,halp} EOF diff --git a/build.rs b/build.rs index 909633b..79a0174 100644 --- a/build.rs +++ b/build.rs @@ -29,7 +29,9 @@ fn main() { } fn is_development_version() -> bool { - env::var("PROFILE").unwrap() == "debug" + // Both weekly releases and actual releases are --release releases, + // but actual releases will have a proper version number + cargo_version().ends_with("-pre") || env::var("PROFILE").unwrap() == "debug" } fn cargo_version() -> String { diff --git a/devtools/dev-package-for-linux.sh b/devtools/dev-package-for-linux.sh index ff64c5e..8c33e2d 100644 --- a/devtools/dev-package-for-linux.sh +++ b/devtools/dev-package-for-linux.sh @@ -25,6 +25,13 @@ eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g") if [ -z "$exa_version" ]; then echo "Failed to parse version number! Can't build exa!" exit 1 +fi + +# Weekly builds have a bit more information in their version number (see build.rs). +if [[ "$1" == "--weekly" ]]; then + git_hash=`GIT_DIR=/vagrant/.git git rev-parse --short --verify HEAD` + date=`date +"%Y-%m-%d"` + echo "Building exa weekly v$exa_version, date $date, Git hash $git_hash" else echo "Building exa v$exa_version" fi @@ -50,7 +57,10 @@ strip -v "$exa_linux_binary" # the binaries can have consistent names, and it’s still possible to tell # different *downloads* apart. echo -e "\n\033[4mZipping binary...\033[0m" -exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}.zip" +if [[ "$1" == "--weekly" ]] + then exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}-${date}-${git_hash}.zip" + else exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}.zip" +fi rm -vf "$exa_linux_zip" zip -j "$exa_linux_zip" "$exa_linux_binary" From 1ebb2e95ffd12ce2e69528fde4ef5d45ac7448d2 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 8 Oct 2017 20:54:18 +0100 Subject: [PATCH 3/4] Copy weekly changes into macos script --- devtools/local-package-for-macos.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devtools/local-package-for-macos.sh b/devtools/local-package-for-macos.sh index 48d6bc7..57dfbe6 100644 --- a/devtools/local-package-for-macos.sh +++ b/devtools/local-package-for-macos.sh @@ -32,6 +32,13 @@ eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g") if [ -z "$exa_version" ]; then echo "Failed to parse version number! Can't build exa!" exit 1 +fi + +# Weekly builds have a bit more information in their version number (see build.rs). +if [[ "$1" == "--weekly" ]]; then + git_hash=`GIT_DIR=$exa_root/.git git rev-parse --short --verify HEAD` + date=`date +"%Y-%m-%d"` + echo "Building exa weekly v$exa_version, date $date, Git hash $git_hash" else echo "Building exa v$exa_version" fi @@ -58,7 +65,10 @@ echo "strip $exa_macos_binary" # the binaries can have consistent names, and it’s still possible to tell # different *downloads* apart. echo -e "\n\033[4mZipping binary...\033[0m" -exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}.zip" +if [[ "$1" == "--weekly" ]] + then exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}-${date}-${git_hash}.zip" + else exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}.zip" +fi rm -vf "$exa_macos_zip" | sed 's/^/removing /' zip -j "$exa_macos_zip" "$exa_macos_binary" From d9f6b6e55924e5035e973e0a957c0d708ce52b6a Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 8 Oct 2017 21:04:34 +0100 Subject: [PATCH 4/4] Add script to generate checksums --- .gitignore | 2 ++ devtools/dev-generate-checksums.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 devtools/dev-generate-checksums.sh diff --git a/.gitignore b/.gitignore index 2f34c09..c720071 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ ubuntu-xenial-16.04-cloudimg-console.log /exa-linux-x86_64-*.zip /exa-macos-x86_64 /exa-macos-x86_64-*.zip +/MD5SUMS +/SHA1SUMS diff --git a/devtools/dev-generate-checksums.sh b/devtools/dev-generate-checksums.sh new file mode 100644 index 0000000..0075c3f --- /dev/null +++ b/devtools/dev-generate-checksums.sh @@ -0,0 +1,15 @@ +# This script generates the MD5SUMS and SHA1SUMS files. +# You’ll need to have run ‘dev-download-and-check-release.sh’ and +# ‘local-package-for-macos.sh’ scripts to generate the binaries first. + +set +x +trap 'exit' ERR + +cd /vagrant +rm -f MD5SUMS SHA1SUMS + +echo -e "\n\033[4mValidating MD5 checksums...\033[0m" +md5sum exa-linux-x86_64 exa-macos-x86_64 | tee MD5SUMS + +echo -e "\n\033[4mValidating SHA1 checksums...\033[0m" +sha1sum exa-linux-x86_64 exa-macos-x86_64 | tee SHA1SUMS