Explorar o código

Merge branch 'version-numbers'

Benjamin Sago %!s(int64=8) %!d(string=hai) anos
pai
achega
ee5a06853c

+ 2 - 0
.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

+ 1 - 1
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)",

+ 7 - 1
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" ]

+ 2 - 2
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

+ 61 - 0
build.rs

@@ -0,0 +1,61 @@
+/// 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 {
+    // 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 {
+    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)
+}

+ 15 - 0
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

+ 11 - 1
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"
 

+ 11 - 1
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"
 

+ 8 - 12
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;