Skip to content

Commit

Permalink
chore: address review and regen snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Mar 21, 2024
1 parent 2f138cf commit 50506d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
10 changes: 3 additions & 7 deletions cargo-dist/src/build/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! without needing to actually run platform-specific builds
use axoasset::LocalAsset;
use camino::Utf8PathBuf;
use cargo_dist_schema::DistManifest;

use crate::{BinaryIdx, CargoBuildStep, DistGraph, DistResult, GenericBuildStep};
Expand Down Expand Up @@ -39,13 +40,8 @@ fn build_fake_binaries(
binaries: &[BinaryIdx],
) -> DistResult<()> {
// Shove these in a temp dir inside the dist dir, where it's safe for us to do whatever
let tempdir = dist.dist_dir.join("_fake_tmp");
// Clear out old files (files we need get copied out by the time this function returns)
if tempdir.exists() {
LocalAsset::remove_dir_all(&tempdir)?;
}
LocalAsset::create_dir_all(&tempdir)?;

let tmp = temp_dir::TempDir::new()?;
let tempdir = Utf8PathBuf::from_path_buf(tmp.path().to_owned()).expect("temp_dir made non-utf8 path!?");
let mut expectations = BuildExpectations::new_fake(dist, binaries);

for idx in binaries {
Expand Down
31 changes: 23 additions & 8 deletions cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PRINT_VERBOSE=${INSTALLER_PRINT_VERBOSE:-0}
PRINT_QUIET=${INSTALLER_PRINT_QUIET:-0}
NO_MODIFY_PATH=${INSTALLER_NO_MODIFY_PATH:-0}
read -r RECEIPT <<EORECEIPT
{"binaries":["CARGO_DIST_BINS"],"install_prefix":"AXO_CARGO_HOME","provider":{"source":"cargo-dist","version":"CENSORED"},"source":{"app_name":"axolotlsay","name":"axolotlsay","owner":"axodotdev","release_type":"github"},"version":"CENSORED"}
{"binaries":["CARGO_DIST_BINS"],"install_prefix":"AXO_INSTALL_PREFIX","provider":{"source":"cargo-dist","version":"CENSORED"},"source":{"app_name":"axolotlsay","name":"axolotlsay","owner":"axodotdev","release_type":"github"},"version":"CENSORED"}
EORECEIPT
# Are we happy with this same path on Linux and Mac?
RECEIPT_HOME="${HOME}/.config/axolotlsay"
Expand Down Expand Up @@ -334,7 +334,7 @@ install() {
fi

# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_INSTALL_PREFIX,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -930,7 +930,7 @@ $app_name = 'axolotlsay'
$app_version = '0.2.1'

$receipt = @"
{"binaries":["CARGO_DIST_BINS"],"install_prefix":"AXO_CARGO_HOME","provider":{"source":"cargo-dist","version":"CENSORED"},"source":{"app_name":"axolotlsay","name":"axolotlsay","owner":"axodotdev","release_type":"github"},"version":"CENSORED"}
{"binaries":["CARGO_DIST_BINS"],"install_prefix":"AXO_INSTALL_PREFIX","provider":{"source":"cargo-dist","version":"CENSORED"},"source":{"app_name":"axolotlsay","name":"axolotlsay","owner":"axodotdev","release_type":"github"},"version":"CENSORED"}
"@
$receipt_home = "${env:LOCALAPPDATA}\axolotlsay"

Expand All @@ -953,7 +953,7 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer $fetched "$install_args"
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1064,7 +1064,7 @@ function Download($download_url, $platforms) {
return $bin_paths
}

function Invoke-Installer($bin_paths) {
function Invoke-Installer($bin_paths, $platforms) {

# first try CARGO_HOME, then fallback to HOME
# (for whatever reason $HOME is not a normal env var and doesn't need the $env: prefix)
Expand All @@ -1085,7 +1085,7 @@ function Invoke-Installer($bin_paths) {
}

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_INSTALL_PREFIX', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand All @@ -1099,6 +1099,19 @@ function Invoke-Installer($bin_paths) {

# Replaces the placeholder binary entry with the actual list of binaries
$arch = Get-TargetTriple

if (-not $platforms.ContainsKey($arch)) {
# X64 is well-supported, including in emulation on ARM64
Write-Verbose "$arch is not available, falling back to X64"
$arch = "x86_64-pc-windows-msvc"
}

if (-not $platforms.ContainsKey($arch)) {
# should not be possible, as currently we always produce X64 binaries.
$platforms_json = ConvertTo-Json $platforms
throw "ERROR: could not find binaries for this platform. Last platform tried: $arch platform info: $platforms_json"
}

$info = $platforms[$arch]
$formatted_bins = ($info["bins"] | ForEach-Object { '"' + $_ + '"' }) -join ","
$receipt = $receipt.Replace('"CARGO_DIST_BINS"', $formatted_bins)
Expand Down Expand Up @@ -1126,6 +1139,7 @@ function Invoke-Installer($bin_paths) {
# Returns true if the registry was modified, otherwise returns false
# (indicating it was already on PATH)
function Add-Path($OrigPathToAdd) {
Write-Verbose "Adding $OrigPathToAdd to your PATH"
$RegistryPath = "HKCU:\Environment"
$PropertyName = "Path"
$PathToAdd = $OrigPathToAdd
Expand All @@ -1147,21 +1161,22 @@ function Add-Path($OrigPathToAdd) {
$PathToAdd = "$PathToAdd;"
} catch {
# We'll be creating the PATH from scratch
Write-Verbose "Adding $PropertyName Property to $RegistryPath"
Write-Verbose "No $PropertyName Property exists on $RegistryPath (we'll make one)"
}

# Check if the path is already there
#
# We don't want to incorrectly match "C:\blah\" to "C:\blah\blah\", so we include the semicolon
# delimiters when searching, ensuring exact matches. To avoid corner cases we add semicolons to
# both sides of the input, allowing us to pretend we're always in the middle of a list.
Write-Verbose "Old $PropertyName Property is $OldPath"
if (";$OldPath;" -like "*;$OrigPathToAdd;*") {
# Already on path, nothing to do
Write-Verbose "install dir already on PATH, all done!"
return $false
} else {
# Actually update PATH
Write-Verbose "Adding $OrigPathToAdd to your PATH"
Write-Verbose "Actually mutating $PropertyName Property"
$NewPath = $PathToAdd + $OldPath
# We use -Force here to make the value already existing not be an error
$Item | New-ItemProperty -Name $PropertyName -Value $NewPath -PropertyType String -Force | Out-Null
Expand Down
18 changes: 13 additions & 5 deletions cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2077,9 +2077,6 @@ maybeInstall(true).then(run);
"announcement_title": "Version 0.2.1",
"announcement_changelog": "```text\n +--------------------------------------+\n | now with linux static musl binary!!! |\n +--------------------------------------+\n /\n≽(◕ ᴗ ◕)≼\n```",
"announcement_github_body": "## Release Notes\n\n```text\n +--------------------------------------+\n | now with linux static musl binary!!! |\n +--------------------------------------+\n /\n≽(◕ ᴗ ◕)≼\n```\n\n## Install axolotlsay 0.2.1\n\n### Install prebuilt binaries via shell script\n\n```sh\ncurl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-installer.sh | sh\n```\n\n### Install prebuilt binaries via powershell script\n\n```sh\npowershell -c \"irm https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-installer.ps1 | iex\"\n```\n\n### Install prebuilt binaries via Homebrew\n\n```sh\nbrew install axodotdev/homebrew-packages/axolotlsay\n```\n\n### Install prebuilt binaries into your npm project\n\n```sh\nnpm install [email protected]\n```\n\n## Download axolotlsay 0.2.1\n\n| File | Platform | Checksum |\n|--------|----------|----------|\n| [axolotlsay-aarch64-apple-darwin.tar.gz](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-aarch64-apple-darwin.tar.gz) | Apple Silicon macOS | [checksum](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-aarch64-apple-darwin.tar.gz.sha256) |\n| [axolotlsay-x86_64-apple-darwin.tar.gz](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-apple-darwin.tar.gz) | Intel macOS | [checksum](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-apple-darwin.tar.gz.sha256) |\n| [axolotlsay-x86_64-pc-windows-msvc.tar.gz](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-pc-windows-msvc.tar.gz) | x64 Windows | [checksum](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-pc-windows-msvc.tar.gz.sha256) |\n| [axolotlsay-x86_64-pc-windows-msvc.msi](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-pc-windows-msvc.msi) | x64 Windows | [checksum](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-pc-windows-msvc.msi.sha256) |\n| [axolotlsay-x86_64-unknown-linux-gnu.tar.gz](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-unknown-linux-gnu.tar.gz) | x64 Linux | [checksum](https://github.com/axodotdev/axolotlsay/releases/download/v0.2.1/axolotlsay-x86_64-unknown-linux-gnu.tar.gz.sha256) |\n\n",
"system_info": {
"cargo_version_line": "CENSORED"
},
"releases": [
{
"app_name": "axolotlsay",
Expand Down Expand Up @@ -2138,6 +2135,7 @@ maybeInstall(true).then(run);
"kind": "readme"
},
{
"id": "axolotlsay-aarch64-apple-darwin-axolotlsay",
"name": "axolotlsay",
"path": "axolotlsay",
"kind": "executable"
Expand Down Expand Up @@ -2264,6 +2262,7 @@ maybeInstall(true).then(run);
"kind": "readme"
},
{
"id": "axolotlsay-x86_64-apple-darwin-axolotlsay",
"name": "axolotlsay",
"path": "axolotlsay",
"kind": "executable"
Expand All @@ -2286,6 +2285,7 @@ maybeInstall(true).then(run);
],
"assets": [
{
"id": "axolotlsay-x86_64-pc-windows-msvc-axolotlsay",
"name": "axolotlsay",
"path": "axolotlsay.exe",
"kind": "executable"
Expand Down Expand Up @@ -2329,6 +2329,7 @@ maybeInstall(true).then(run);
"kind": "readme"
},
{
"id": "axolotlsay-x86_64-pc-windows-msvc-axolotlsay",
"name": "axolotlsay",
"path": "axolotlsay.exe",
"kind": "executable"
Expand Down Expand Up @@ -2371,6 +2372,7 @@ maybeInstall(true).then(run);
"kind": "readme"
},
{
"id": "axolotlsay-x86_64-unknown-linux-gnu-axolotlsay",
"name": "axolotlsay",
"path": "axolotlsay",
"kind": "executable"
Expand Down Expand Up @@ -2406,6 +2408,12 @@ maybeInstall(true).then(run);
"kind": "checksum"
}
},
"systems": {
"plan:all:": {
"id": "plan:all:",
"cargo_version_line": "CENSORED"
}
},
"publish_prereleases": false,
"ci": {
"github": {
Expand Down Expand Up @@ -2591,7 +2599,7 @@ jobs:
run: |
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

cp dist-manifest.json "$BUILD_MANIFEST_NAME"
Expand Down Expand Up @@ -2634,7 +2642,7 @@ jobs:

# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

cp dist-manifest.json "$BUILD_MANIFEST_NAME"
Expand Down

0 comments on commit 50506d7

Please sign in to comment.