Skip to content

Commit

Permalink
feat: allow overriding install path
Browse files Browse the repository at this point in the history
This provides a way to override any configuration on the installer and
install to a location specified by a new environment variable. It provides
a more predictable way to insist that it gets installed to a specific place,
regardless of how the installer was built.

Possible fix for axodotdev/axoupdater#32, where we'd like to be able to
install a new version to exactly the same path as the previous version.
  • Loading branch information
mistydemeo committed Mar 8, 2024
1 parent 45e1671 commit ac8ef06
Show file tree
Hide file tree
Showing 30 changed files with 473 additions and 37 deletions.
12 changes: 9 additions & 3 deletions cargo-dist/templates/installer/installer.ps1.j2
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ function Invoke-Installer($bin_paths) {
}

$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))
{% elif install_path.kind == "HomeSubdir" %}
# Install to this subdir of the user's home dir
$dest_dir = if (($base_dir = $HOME)) {
Expand All @@ -226,6 +223,15 @@ function Invoke-Installer($bin_paths) {
{% else %}
{{ error("unimplemented install_path format: " ~ install_path.kind) }}
{% endif %}
# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
# Just copy the binaries from the temp location to the install dir
Expand Down
10 changes: 10 additions & 0 deletions cargo-dist/templates/installer/installer.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ install() {
{% else %}
{{ error("unimplemented install_path format: " ~ install_path.kind) }}
{% endif %}
# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down
16 changes: 16 additions & 0 deletions cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1064,6 +1074,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down
12 changes: 10 additions & 2 deletions cargo-dist/tests/snapshots/akaikatana_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1387,5 +1397,3 @@ jobs:
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
artifacts: "artifacts/*"
16 changes: 16 additions & 0 deletions cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1064,6 +1074,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down
16 changes: 16 additions & 0 deletions cargo-dist/tests/snapshots/akaikatana_updaters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1080,6 +1090,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down
18 changes: 16 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1065,6 +1075,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down Expand Up @@ -2946,5 +2962,3 @@ jobs:
</Product>
</Wix>
18 changes: 16 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1065,6 +1075,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down Expand Up @@ -2918,5 +2934,3 @@ jobs:
</Product>

</Wix>


16 changes: 16 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1065,6 +1075,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down
16 changes: 16 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1065,6 +1075,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down
12 changes: 10 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -2282,5 +2292,3 @@ jobs:
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
artifacts: "artifacts/*"
12 changes: 10 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -2228,5 +2238,3 @@ jobs:
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
artifacts: "artifacts/*"
18 changes: 16 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ install() {
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
_install_home="$CARGO_DIST_FORCE_INSTALL_DIR"
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
_install_dir_expr='$CARGO_DIST_FORCE_INSTALL_DIR/bin'
_env_script_path_expr='$CARGO_DIST_FORCE_INSTALL_DIR/env'
fi

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"

Expand Down Expand Up @@ -1065,6 +1075,12 @@ function Invoke-Installer($bin_paths) {

$dest_dir = Join-Path $root "bin"

# ...ignoring all of the above, if the user asked us to completely override
# those choices and use a specified directory, then pick that now
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
}

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

Expand Down Expand Up @@ -2657,5 +2673,3 @@ jobs:
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
artifacts: "artifacts/*"

0 comments on commit ac8ef06

Please sign in to comment.