Skip to content

Commit

Permalink
feat: migrate from flat to hierarchical installs (.ps1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Apr 17, 2024
1 parent 2a67706 commit a3aa730
Show file tree
Hide file tree
Showing 28 changed files with 396 additions and 20 deletions.
28 changes: 24 additions & 4 deletions cargo-dist/templates/installer/installer.ps1.j2
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down Expand Up @@ -213,28 +225,36 @@ function Invoke-Installer($bin_paths, $platforms) {
}
{% elif install_path.kind == "HomeSubdir" %}
# Install to this subdir of the user's home dir
$dest_dir = if (($base_dir = $HOME)) {
$root = if (($base_dir = $HOME)) {
Join-Path $base_dir "{{ install_path.subdir }}"
} else {
throw "ERROR: could not find your HOME dir to install binaries to"
}

# If we need to override the above
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
$root = $env:CARGO_DIST_FORCE_INSTALL_DIR
}

$dest_dir = Join-Path $root "bin"

MigrateInstallDir -old_root $root -new_root $dest_dir -bin_paths $bin_paths
{% elif install_path.kind == "EnvSubdir" %}
# Install to this subdir of the user's {{ install_path.env_key }} dir
$dest_dir = if (($base_dir = $env:{{ install_path.env_key }})) {
$root = if (($base_dir = $env:{{ install_path.env_key }})) {
Join-Path $base_dir "{{ install_path.subdir }}"
} else {
throw "ERROR: could not find your {{ install_path.env_key }} dir to install binaries to"
}

# If we need to override the above
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
$dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
$root = $env:CARGO_DIST_FORCE_INSTALL_DIR
}

$dest_dir = Join-Path $root "bin"

MigrateInstallDir -old_root $root -new_root $dest_dir -bin_paths $bin_paths
{% else %}
{{ error("unimplemented install_path format: " ~ install_path.kind) }}
{% endif %}
Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 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 @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/akaikatana_updaters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_updaters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
12 changes: 12 additions & 0 deletions cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
}
}

# Provides a way to migrate from an old "flat" layout to the new
# FHS-style organized layout.
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
foreach ($bin_name in $bin_paths) {
$bin_path = "$old_root\$bin_name"
if (Test-Path -Path "$bin_path") {
Copy-Item "$bin_path" -Destination "$new_root"
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
}
}
}

function Download($download_url, $platforms) {
$arch = Get-TargetTriple

Expand Down
Loading

0 comments on commit a3aa730

Please sign in to comment.