Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ Run:
bash install.sh
```

The script installs Tempyr with:
The script first builds Tempyr in release mode:

```bash
cargo build --release --manifest-path crates/tempyr-cli/Cargo.toml --locked --bin tempyr
```

Then it installs Tempyr with:

```bash
cargo install --path crates/tempyr-cli --root "${XDG_DATA_HOME:-$HOME/.local/share}/tempyr" --locked --force --bin tempyr
Expand All @@ -32,7 +38,13 @@ Run:
powershell -ExecutionPolicy Bypass -File .\install.ps1
```

The script installs Tempyr with:
The script first builds Tempyr in release mode:

```powershell
cargo build --release --manifest-path .\crates\tempyr-cli\Cargo.toml --locked --bin tempyr
```

Then it installs Tempyr with:

```powershell
cargo install --path .\crates\tempyr-cli --root "$Env:LocalAppData\Tempyr" --locked --force --bin tempyr
Expand All @@ -48,7 +60,7 @@ If you want `install.ps1` to skip user `PATH` changes, pass `-NoPathUpdate`:

## Updating safely

Rerun the installer to update Tempyr. Both installers check whether the target Tempyr binary is already in use before invoking `cargo install`. If it is, they only stop processes whose executable path exactly matches the target installed binary. They do not kill processes based on name alone.
Rerun the installer to update Tempyr. Both installers run the release build before checking whether the target Tempyr binary is already in use, so compile failures do not interrupt a currently running installed binary. If the target binary is in use, they only stop processes whose executable path exactly matches the target installed binary. They do not kill processes based on name alone.

If the binary becomes locked during the install anyway, the installers stop matching Tempyr processes and retry. On Windows, the installer also waits and retries a few times before failing when the lock appears to be transient.

Expand Down
67 changes: 54 additions & 13 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -323,33 +323,25 @@ function ConvertTo-WindowsArgument {
return $builder.ToString()
}

function Invoke-CargoInstall {
function Invoke-CargoCommand {
param(
[Parameter(Mandatory)]
[string]$CratePath,
[string[]]$Arguments,
[Parameter(Mandatory)]
[string]$InstallRootPath
[string]$WorkingDirectory
)

$cargoExe = (Get-Command cargo -ErrorAction Stop).Source
$cargoArgs = @(
"install",
"--path", $CratePath,
"--root", $InstallRootPath,
"--locked",
"--force",
"--bin", "tempyr"
)
$stdoutFile = New-TemporaryFile
$stderrFile = New-TemporaryFile
try {
# Windows PowerShell 5.1 turns native stderr into a terminating NativeCommandError
# when ErrorActionPreference=Stop, even for cargo's normal progress output.
$argumentLine = ($cargoArgs | ForEach-Object { ConvertTo-WindowsArgument -Value "$_" }) -join ' '
$argumentLine = ($Arguments | ForEach-Object { ConvertTo-WindowsArgument -Value "$_" }) -join ' '
$process = Start-Process `
-FilePath $cargoExe `
-ArgumentList $argumentLine `
-WorkingDirectory $CratePath `
-WorkingDirectory $WorkingDirectory `
-RedirectStandardOutput $stdoutFile.FullName `
-RedirectStandardError $stderrFile.FullName `
-NoNewWindow `
Expand Down Expand Up @@ -381,6 +373,53 @@ function Invoke-CargoInstall {
}
}

function Invoke-CargoInstall {
param(
[Parameter(Mandatory)]
[string]$CratePath,
[Parameter(Mandatory)]
[string]$InstallRootPath
)

$cargoArgs = @(
"install",
"--path", $CratePath,
"--root", $InstallRootPath,
"--locked",
"--force",
"--bin", "tempyr"
)

return Invoke-CargoCommand -Arguments $cargoArgs -WorkingDirectory $CratePath
}

function Invoke-CargoBuild {
param(
[Parameter(Mandatory)]
[string]$CratePath
)

$cargoArgs = @(
"build",
"--release",
"--manifest-path", (Join-Path $CratePath "Cargo.toml"),
"--locked",
"--bin", "tempyr"
)

$buildResult = Invoke-CargoCommand -Arguments $cargoArgs -WorkingDirectory $CratePath
if ($buildResult.ExitCode -ne 0) {
$message = "cargo build --release failed with exit code $($buildResult.ExitCode)."
if (-not [string]::IsNullOrWhiteSpace($buildResult.Output)) {
$output = $buildResult.Output.TrimEnd()
if (-not [string]::IsNullOrWhiteSpace($output)) {
$message = "$message`n$output"
}
}
throw $message
}
}

function Invoke-CargoInstallWithLockRecovery {
param(
[Parameter(Mandatory)]
Expand Down Expand Up @@ -455,6 +494,8 @@ if (-not (Test-Path -LiteralPath (Join-Path $cratePath "Cargo.toml"))) {
throw "Could not find crates/tempyr-cli/Cargo.toml relative to $scriptRoot."
}

Invoke-CargoBuild -CratePath $cratePath

$installResult = Invoke-CargoInstallWithLockRecovery `
-CratePath $cratePath `
-InstallRootPath $InstallRoot `
Expand Down
9 changes: 9 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ run_cargo_install() {
return "$status"
}

run_cargo_build() {
cargo build \
--release \
--manifest-path "$CRATE_PATH/Cargo.toml" \
--locked \
--bin tempyr
}

preflight_locked_target() {
[[ -e "$TARGET_BIN" ]] || return 0

Expand Down Expand Up @@ -313,6 +321,7 @@ ensure_path_persistence() {
esac
}

run_cargo_build
preflight_locked_target

run_cargo_install || {
Expand Down
Loading