From 1d7af0bfdcfdeb9a5f4e66a9b9a4ff42ea64f45e Mon Sep 17 00:00:00 2001
From: Christopher Maier <cmaier@chef.io>
Date: Tue, 6 Aug 2019 10:38:23 -0400
Subject: [PATCH] Explicitly manage the version of Nightly Rust in tests

Some of our tests use nightly Rust to help test for specific
things. The version of Rust used was simply piggybacking on the
version of nightly Rust we use for `rustfmt`, rather than being
specifically managed.

Previously, this wasn't an issue, but with the latest nightly Rust
that works for `rustfmt`, we apparently have a bug around cargo
dealing with crates that have symlinks in them (possibly related to
https://github.com/rust-lang/cargo/issues/5664).

This commit introduces a `RUST_NIGHTLY_VERSION` file to explicitly
manage which version we're using in tests. For now, it also pins back
to the last known good nightly version for testing purposes.

Signed-off-by: Christopher Maier <cmaier@chef.io>
---
 RUST_NIGHTLY_VERSION                  | 1 +
 build.ps1                             | 2 +-
 support/ci/install-nightly-rustfmt.sh | 2 +-
 support/ci/rustfmt.sh                 | 2 +-
 support/ci/shared.ps1                 | 6 +++++-
 support/ci/shared.sh                  | 8 +++++++-
 test/run_cargo_test.ps1               | 2 +-
 7 files changed, 17 insertions(+), 6 deletions(-)
 create mode 100644 RUST_NIGHTLY_VERSION
 mode change 100644 => 100755 test/run_cargo_test.ps1

diff --git a/RUST_NIGHTLY_VERSION b/RUST_NIGHTLY_VERSION
new file mode 100644
index 00000000000..09c2799a1da
--- /dev/null
+++ b/RUST_NIGHTLY_VERSION
@@ -0,0 +1 @@
+nightly-2019-06-06
diff --git a/build.ps1 b/build.ps1
index d4e574da403..a71eb664349 100644
--- a/build.ps1
+++ b/build.ps1
@@ -39,7 +39,7 @@ if (!$Toolchain) {
 }
 
 if($Command -eq "Fmt") {
-    $toolchain = "$(Get-Content $PSScriptRoot/RUSTFMT_VERSION)"
+    $toolchain = Get-RustfmtToolchain
     Write-Host "Forcing the use of $toolchain toolchain for rustfmt"
 }
 
diff --git a/support/ci/install-nightly-rustfmt.sh b/support/ci/install-nightly-rustfmt.sh
index 6c6af8b5b01..73aa46e9626 100755
--- a/support/ci/install-nightly-rustfmt.sh
+++ b/support/ci/install-nightly-rustfmt.sh
@@ -5,6 +5,6 @@ set -euo pipefail
 dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
 # shellcheck disable=SC1090
 source "$dir/shared.sh"
-toolchain=$(get_nightly_toolchain)
+toolchain=$(get_rustfmt_toolchain)
 
 install_rustfmt "$toolchain"
diff --git a/support/ci/rustfmt.sh b/support/ci/rustfmt.sh
index 780f17623f4..6bce78996fd 100755
--- a/support/ci/rustfmt.sh
+++ b/support/ci/rustfmt.sh
@@ -5,7 +5,7 @@ set -euo pipefail
 dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
 # shellcheck disable=SC1090
 source "$dir/shared.sh"
-toolchain=$(get_nightly_toolchain)
+toolchain=$(get_rustfmt_toolchain)
 
 install_rustup
 install_rustfmt "$toolchain"
diff --git a/support/ci/shared.ps1 b/support/ci/shared.ps1
index 375c126eaa2..d0d4b2ff929 100644
--- a/support/ci/shared.ps1
+++ b/support/ci/shared.ps1
@@ -1,4 +1,4 @@
-function Get-NightlyToolchain {
+function Get-RustfmtToolchain {
   # It turns out that every nightly version of rustfmt has slight tweaks from the previous version.
   # This means that if we're always using the latest version, then we're going to have enormous
   # churn. Even PRs that don't touch rust code will likely fail CI, since master will have been
@@ -12,6 +12,10 @@ function Get-NightlyToolchain {
   Get-Content "$PSScriptRoot\..\..\RUSTFMT_VERSION"
 }
 
+function Get-NightlyToolchain {
+  Get-Content "$PSScriptRoot\..\..\RUST_NIGHTLY_VERSION"
+}
+
 function Install-Rustup($Toolchain) {
     if(Test-Path $env:USERPROFILE\.cargo\bin) {
         $env:path = New-PathString -StartingPath $env:path -Path "$env:USERPROFILE\.cargo\bin"
diff --git a/support/ci/shared.sh b/support/ci/shared.sh
index 9e55e2d673d..20c69eea325 100755
--- a/support/ci/shared.sh
+++ b/support/ci/shared.sh
@@ -6,7 +6,7 @@ dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
 
 sudo hab license accept
 
-get_nightly_toolchain() {
+get_rustfmt_toolchain() {
   # It turns out that every nightly version of rustfmt has slight tweaks from the previous version.
   # This means that if we're always using the latest version, then we're going to have enormous
   # churn. Even PRs that don't touch rust code will likely fail CI, since master will have been
@@ -20,6 +20,12 @@ get_nightly_toolchain() {
   cat "$dir/../../RUSTFMT_VERSION"
 }
 
+# Get the version of the nightly toolchain we use for compiling,
+# running, tests, etc.
+get_nightly_toolchain() {
+    cat "$dir/../../RUST_NIGHTLY_VERSION"
+}
+
 get_toolchain() {
   cat "$dir/../../rust-toolchain"
 }
diff --git a/test/run_cargo_test.ps1 b/test/run_cargo_test.ps1
old mode 100644
new mode 100755
index b8f58ee6cce..e7997689719
--- a/test/run_cargo_test.ps1
+++ b/test/run_cargo_test.ps1
@@ -16,7 +16,7 @@ $ErrorActionPreference="stop"
 . $PSScriptRoot\..\support\ci\shared.ps1
 
 $toolchain = Get-Toolchain
-if($Nightly) { $toolchain = (gc $PSScriptRoot\..\RUSTFMT_VERSION | out-string).Trim() }
+if($Nightly) { $toolchain = Get-NightlyToolchain }
 
 Setup-Environment