Skip to content

Commit a3aa730

Browse files
committed
feat: migrate from flat to hierarchical installs (.ps1)
1 parent 2a67706 commit a3aa730

28 files changed

+396
-20
lines changed

cargo-dist/templates/installer/installer.ps1.j2

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ function Get-TargetTriple() {
120120
}
121121
}
122122

123+
# Provides a way to migrate from an old "flat" layout to the new
124+
# FHS-style organized layout.
125+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
126+
foreach ($bin_name in $bin_paths) {
127+
$bin_path = "$old_root\$bin_name"
128+
if (Test-Path -Path "$bin_path") {
129+
Copy-Item "$bin_path" -Destination "$new_root"
130+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
131+
}
132+
}
133+
}
134+
123135
function Download($download_url, $platforms) {
124136
$arch = Get-TargetTriple
125137

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

222234
# If we need to override the above
223235
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
224-
$dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
236+
$root = $env:CARGO_DIST_FORCE_INSTALL_DIR
225237
}
238+
239+
$dest_dir = Join-Path $root "bin"
240+
241+
MigrateInstallDir -old_root $root -new_root $dest_dir -bin_paths $bin_paths
226242
{% elif install_path.kind == "EnvSubdir" %}
227243
# Install to this subdir of the user's {{ install_path.env_key }} dir
228-
$dest_dir = if (($base_dir = $env:{{ install_path.env_key }})) {
244+
$root = if (($base_dir = $env:{{ install_path.env_key }})) {
229245
Join-Path $base_dir "{{ install_path.subdir }}"
230246
} else {
231247
throw "ERROR: could not find your {{ install_path.env_key }} dir to install binaries to"
232248
}
233249

234250
# If we need to override the above
235251
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
236-
$dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
252+
$root = $env:CARGO_DIST_FORCE_INSTALL_DIR
237253
}
254+
255+
$dest_dir = Join-Path $root "bin"
256+
257+
MigrateInstallDir -old_root $root -new_root $dest_dir -bin_paths $bin_paths
238258
{% else %}
239259
{{ error("unimplemented install_path format: " ~ install_path.kind) }}
240260
{% endif %}

cargo-dist/tests/snapshots/akaikatana_basic.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/akaikatana_updaters.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,18 @@ function Get-TargetTriple() {
10441044
}
10451045
}
10461046

1047+
# Provides a way to migrate from an old "flat" layout to the new
1048+
# FHS-style organized layout.
1049+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1050+
foreach ($bin_name in $bin_paths) {
1051+
$bin_path = "$old_root\$bin_name"
1052+
if (Test-Path -Path "$bin_path") {
1053+
Copy-Item "$bin_path" -Destination "$new_root"
1054+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1055+
}
1056+
}
1057+
}
1058+
10471059
function Download($download_url, $platforms) {
10481060
$arch = Get-TargetTriple
10491061

cargo-dist/tests/snapshots/axolotlsay_abyss.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_basic.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,18 @@ function Get-TargetTriple() {
10311031
}
10321032
}
10331033

1034+
# Provides a way to migrate from an old "flat" layout to the new
1035+
# FHS-style organized layout.
1036+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1037+
foreach ($bin_name in $bin_paths) {
1038+
$bin_path = "$old_root\$bin_name"
1039+
if (Test-Path -Path "$bin_path") {
1040+
Copy-Item "$bin_path" -Destination "$new_root"
1041+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1042+
}
1043+
}
1044+
}
1045+
10341046
function Download($download_url, $platforms) {
10351047
$arch = Get-TargetTriple
10361048

cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,18 @@ function Get-TargetTriple() {
987987
}
988988
}
989989

990+
# Provides a way to migrate from an old "flat" layout to the new
991+
# FHS-style organized layout.
992+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
993+
foreach ($bin_name in $bin_paths) {
994+
$bin_path = "$old_root\$bin_name"
995+
if (Test-Path -Path "$bin_path") {
996+
Copy-Item "$bin_path" -Destination "$new_root"
997+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
998+
}
999+
}
1000+
}
1001+
9901002
function Download($download_url, $platforms) {
9911003
$arch = Get-TargetTriple
9921004

cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,18 @@ function Get-TargetTriple() {
987987
}
988988
}
989989

990+
# Provides a way to migrate from an old "flat" layout to the new
991+
# FHS-style organized layout.
992+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
993+
foreach ($bin_name in $bin_paths) {
994+
$bin_path = "$old_root\$bin_name"
995+
if (Test-Path -Path "$bin_path") {
996+
Copy-Item "$bin_path" -Destination "$new_root"
997+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
998+
}
999+
}
1000+
}
1001+
9901002
function Download($download_url, $platforms) {
9911003
$arch = Get-TargetTriple
9921004

cargo-dist/tests/snapshots/axolotlsay_updaters.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,18 @@ function Get-TargetTriple() {
10441044
}
10451045
}
10461046

1047+
# Provides a way to migrate from an old "flat" layout to the new
1048+
# FHS-style organized layout.
1049+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1050+
foreach ($bin_name in $bin_paths) {
1051+
$bin_path = "$old_root\$bin_name"
1052+
if (Test-Path -Path "$bin_path") {
1053+
Copy-Item "$bin_path" -Destination "$new_root"
1054+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1055+
}
1056+
}
1057+
}
1058+
10471059
function Download($download_url, $platforms) {
10481060
$arch = Get-TargetTriple
10491061

cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ function Get-TargetTriple() {
10281028
}
10291029
}
10301030

1031+
# Provides a way to migrate from an old "flat" layout to the new
1032+
# FHS-style organized layout.
1033+
function MigrateInstallDir($old_root, $new_root, $bin_paths) {
1034+
foreach ($bin_name in $bin_paths) {
1035+
$bin_path = "$old_root\$bin_name"
1036+
if (Test-Path -Path "$bin_path") {
1037+
Copy-Item "$bin_path" -Destination "$new_root"
1038+
Write-Verbose "Migrated $bin_path to $new_root\$bin_name"
1039+
}
1040+
}
1041+
}
1042+
10311043
function Download($download_url, $platforms) {
10321044
$arch = Get-TargetTriple
10331045

0 commit comments

Comments
 (0)