From 11b79827dee45f8f914a61bc6810af68aa34e366 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 24 Dec 2019 08:28:22 -0800 Subject: [PATCH] Add script that can produce a full source tarball Full means "including git submodules" and makes it easier for folks to download and build a release without sucking down large repos from various locations, especially for folks with bandwidth constraints. Upload the source tarball to the associated release. Refs: https://github.com/wez/wezterm/issues/81 Refs: https://github.com/wez/wezterm/pull/46 Refs: https://github.com/wez/wezterm/pull/48 --- azure-pipelines.yml | 3 +++ build.rs | 15 ++++++++++++--- ci/deploy.sh | 2 ++ ci/source-archive.sh | 40 ++++++++++++++++++++++++++++++++++++++++ src/main.rs | 14 +++++++++++++- 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100755 ci/source-archive.sh diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 04372f44a..0de1598d4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -159,6 +159,8 @@ jobs: assets: | $(Build.SourcesDirectory)/*.zip $(Build.SourcesDirectory)/*.deb + $(Build.SourcesDirectory)/*.tar.xz + $(Build.SourcesDirectory)/*.tar.gz title: $(wezterm.tagname) assetUploadMode: replace addChangeLog: false @@ -178,6 +180,7 @@ jobs: $(Build.SourcesDirectory)/*.zip $(Build.SourcesDirectory)/*.deb $(Build.SourcesDirectory)/*.tar.xz + $(Build.SourcesDirectory)/*.tar.gz title: "Nightly Builds" assetUploadMode: replace addChangeLog: false diff --git a/build.rs b/build.rs index 14408c9bf..595fc8cf4 100644 --- a/build.rs +++ b/build.rs @@ -1,13 +1,22 @@ use vergen::{generate_cargo_keys, ConstantsFlags}; fn main() { - // Setup the flags, toggling off the 'SEMVER_FROM_CARGO_PKG' flag let mut flags = ConstantsFlags::all(); - flags.toggle(ConstantsFlags::SEMVER_FROM_CARGO_PKG); - + flags.remove(ConstantsFlags::SEMVER_FROM_CARGO_PKG); // Generate the 'cargo:' key output generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate the cargo keys!"); + // If a file named `.tag` is present, we'll take its contents for the + // version number that we report in wezterm -h. + let mut ci_tag = String::new(); + if let Ok(tag) = std::fs::read(".tag") { + if let Ok(s) = String::from_utf8(tag) { + ci_tag = s.trim().to_string(); + println!("cargo:rerun-if-changed=.tag"); + } + } + println!("cargo:rustc-env=WEZTERM_CI_TAG={}", ci_tag); + #[cfg(windows)] embed_resource::compile("assets/windows/resource.rc"); } diff --git a/ci/deploy.sh b/ci/deploy.sh index b743b6c96..fe42c9ebd 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -81,8 +81,10 @@ EOF fakeroot dpkg-deb --build pkg/debian $debname.deb tar cJf $debname.tar.xz -C pkg/debian/usr/bin wezterm rm -rf pkg + ;; esac + ./ci/source-archive.sh ;; *) diff --git a/ci/source-archive.sh b/ci/source-archive.sh new file mode 100755 index 000000000..3e136d328 --- /dev/null +++ b/ci/source-archive.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Generate a source tarball that includes git submodules + +set -x + +TAG_NAME=${TAG_NAME:-$(git describe --tags)} +TAG_NAME=${TAG_NAME:-$(date +'%Y%m%d-%H%M%S')-$(git log --format=%h -1)} + +if [[ "$BUILD_REASON" == "Schedule" ]] ; then + TAR_NAME=wezterm-nightly-src.tar +else + TAR_NAME=wezterm-${TAG_NAME}-src.tar +fi + +rm -f ${TAR_NAME}* + +git archive --prefix=wezterm-${TAG_NAME}/ -o ${TAR_NAME} HEAD + +p=`pwd` +# `git submodule foreach` outputs lines like: +# Enter 'path' +# So we need to focus on the path and strip the quotes +git submodule foreach | while read entering path; do + path="${path%\'}"; + path="${path#\'}"; + [ "$path" = "" ] && continue; + cd $path + git archive --prefix=wezterm-${TAG_NAME}/$path/ HEAD > tmp.tar && \ + tar --concatenate --file=$p/${TAR_NAME} tmp.tar + rm tmp.tar + cd $p +done + +echo $TAG_NAME > .tag +tar --owner root --group root --transform "s,^,wezterm-$TAG_NAME/," -c -f tmp.tar .tag +tar --concatenate --file=${TAR_NAME} tmp.tar +rm tmp.tar .tag + +gzip ${TAR_NAME} + diff --git a/src/main.rs b/src/main.rs index db33a82ec..e3adf3bec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,11 +44,23 @@ use crate::font::FontConfiguration; // terminal.advance_bytes(message); // != +fn wezterm_version() -> &'static str { + // Prefer our version override, if present (see build.rs) + let tag = env!("WEZTERM_CI_TAG"); + if tag.is_empty() { + // Otherwise, fallback to the vergen-generated information, + // which is basically `git describe --tags` computed in build.rs + env!("VERGEN_SEMVER_LIGHTWEIGHT") + } else { + tag + } +} + #[derive(Debug, StructOpt)] #[structopt(about = "Wez's Terminal Emulator\nhttp://github.com/wez/wezterm")] #[structopt(raw( global_setting = "structopt::clap::AppSettings::ColoredHelp", - version = r#"env!("VERGEN_SEMVER_LIGHTWEIGHT")"#, + version = r#"wezterm_version()"#, ))] struct Opt { /// Skip loading ~/.wezterm.toml