Skip to content

Commit 6572c42

Browse files
authored
Merge pull request #1377 from axodotdev/alt_env_var_force
feat: support app-specific force install
2 parents c77b0c1 + 701587a commit 6572c42

File tree

60 files changed

+1354
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1354
-449
lines changed

cargo-dist-schema/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ pub struct Release {
291291
/// The version of the app
292292
// FIXME: should be a Version but JsonSchema doesn't support (yet?)
293293
pub app_version: String,
294+
/// Environment variable to force an install location
295+
#[serde(default)]
296+
#[serde(skip_serializing_if = "Option::is_none")]
297+
pub install_dir_env_var: Option<String>,
294298
/// Alternative display name that can be prettier
295299
#[serde(default)]
296300
#[serde(skip_serializing_if = "Option::is_none")]
@@ -606,9 +610,12 @@ impl DistManifest {
606610
if let Some(position) = self.releases.iter().position(|r| r.app_name == name) {
607611
&mut self.releases[position]
608612
} else {
613+
let install_dir_env_var =
614+
Some(name.to_ascii_uppercase().replace('-', "_") + "_INSTALL_DIR");
609615
self.releases.push(Release {
610616
app_name: name,
611617
app_version: version,
618+
install_dir_env_var,
612619
artifacts: vec![],
613620
hosting: Hosting::default(),
614621
display: None,

cargo-dist-schema/src/snapshots/cargo_dist_schema__emit.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,13 @@ expression: json_schema
977977
"$ref": "#/definitions/Hosting"
978978
}
979979
]
980+
},
981+
"install_dir_env_var": {
982+
"description": "Environment variable to force an install location",
983+
"type": [
984+
"string",
985+
"null"
986+
]
980987
}
981988
}
982989
},

cargo-dist/src/backend/installer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub struct InstallerInfo {
7373
pub runtime_conditions: RuntimeConditions,
7474
/// platform support matrix
7575
pub platform_support: Option<PlatformSupport>,
76+
/// Environment variable to force an install location
77+
pub install_dir_env_var: String,
7678
}
7779

7880
/// A fake fragment of an ExecutableZip artifact for installers

cargo-dist/src/tasks.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,14 +1981,17 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
19811981
}
19821982
let release = self.release(to_release);
19831983
let release_id = &release.id;
1984-
let Some(download_url) = self
1984+
let schema_release = self
19851985
.manifest
19861986
.release_by_name(&release.app_name)
1987-
.and_then(|r| r.artifact_download_url())
1988-
else {
1989-
warn!("skipping shell installer: couldn't compute a URL to download artifacts from");
1990-
return;
1991-
};
1987+
.expect("couldn't find the release!?");
1988+
let install_dir_env_var = schema_release
1989+
.install_dir_env_var
1990+
.to_owned()
1991+
.expect("couldn't determine app-specific environment variable!?");
1992+
let download_url = schema_release
1993+
.artifact_download_url()
1994+
.expect("couldn't compute a URL to download artifacts from!?");
19921995
let artifact_name = format!("{release_id}-installer.sh");
19931996
let artifact_path = self.inner.dist_dir.join(&artifact_name);
19941997
let installer_url = format!("{download_url}/{artifact_name}");
@@ -2042,6 +2045,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
20422045
install_libraries: release.install_libraries.clone(),
20432046
runtime_conditions,
20442047
platform_support: None,
2048+
install_dir_env_var,
20452049
})),
20462050
is_global: true,
20472051
};
@@ -2059,14 +2063,11 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
20592063
} else {
20602064
&release.id
20612065
};
2062-
let Some(download_url) = self
2066+
let download_url = self
20632067
.manifest
20642068
.release_by_name(&release.id)
20652069
.and_then(|r| r.artifact_download_url())
2066-
else {
2067-
warn!("skipping Homebrew formula: couldn't compute a URL to download artifacts from");
2068-
return;
2069-
};
2070+
.expect("couldn't compute a URL to download artifacts from!?");
20702071

20712072
let artifact_name = format!("{formula}.rb");
20722073
let artifact_path = self.inner.dist_dir.join(&artifact_name);
@@ -2198,6 +2199,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
21982199
install_libraries: release.install_libraries.clone(),
21992200
runtime_conditions,
22002201
platform_support: None,
2202+
// Not actually needed for this installer type
2203+
install_dir_env_var: String::new(),
22012204
},
22022205
install_libraries: release.install_libraries.clone(),
22032206
})),
@@ -2215,16 +2218,17 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
22152218
// Get the basic info about the installer
22162219
let release = self.release(to_release);
22172220
let release_id = &release.id;
2218-
let Some(download_url) = self
2221+
let schema_release = self
22192222
.manifest
22202223
.release_by_name(&release.app_name)
2221-
.and_then(|r| r.artifact_download_url())
2222-
else {
2223-
warn!(
2224-
"skipping powershell installer: couldn't compute a URL to download artifacts from"
2225-
);
2226-
return;
2227-
};
2224+
.expect("couldn't find the release!?");
2225+
let install_dir_env_var = schema_release
2226+
.install_dir_env_var
2227+
.to_owned()
2228+
.expect("couldn't determine app-specific environment variable!?");
2229+
let download_url = schema_release
2230+
.artifact_download_url()
2231+
.expect("couldn't compute a URL to download artifacts from!?");
22282232
let artifact_name = format!("{release_id}-installer.ps1");
22292233
let artifact_path = self.inner.dist_dir.join(&artifact_name);
22302234
let installer_url = format!("{download_url}/{artifact_name}");
@@ -2274,6 +2278,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
22742278
install_libraries: release.install_libraries.clone(),
22752279
runtime_conditions: RuntimeConditions::default(),
22762280
platform_support: None,
2281+
install_dir_env_var,
22772282
})),
22782283
is_global: true,
22792284
};
@@ -2287,14 +2292,11 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
22872292
}
22882293
let release = self.release(to_release);
22892294
let release_id = &release.id;
2290-
let Some(download_url) = self
2295+
let download_url = self
22912296
.manifest
22922297
.release_by_name(&release.app_name)
22932298
.and_then(|r| r.artifact_download_url())
2294-
else {
2295-
warn!("skipping npm installer: couldn't compute a URL to download artifacts from");
2296-
return;
2297-
};
2299+
.expect("couldn't compute a URL to download artifacts from!?");
22982300

22992301
let app_name = if let Some(name) = &release.npm_package {
23002302
name.clone()
@@ -2388,6 +2390,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
23882390
install_libraries: release.install_libraries.clone(),
23892391
runtime_conditions,
23902392
platform_support: None,
2393+
// Not actually needed for this installer type
2394+
install_dir_env_var: String::new(),
23912395
},
23922396
})),
23932397
is_global: true,

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ function Invoke-Installer($artifacts, $platforms) {
246246

247247
$info = $platforms[$arch]
248248

249+
# Forces the install to occur at this path, not the default
250+
$force_install_dir = $null
251+
# Check the newer app-specific variable before falling back
252+
# to the older generic one
253+
if (($env:{{ install_dir_env_var }})) {
254+
$force_install_dir = $env:{{ install_dir_env_var }}
255+
} elseif (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
256+
$force_install_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
257+
}
258+
249259
# The actual path we're going to install to
250260
$dest_dir = $null
251261
$dest_dir_lib = $null
@@ -256,15 +266,15 @@ function Invoke-Installer($artifacts, $platforms) {
256266
$receipt_dest_dir = $null
257267
# Before actually consulting the configured install strategy, see
258268
# if we're overriding it.
259-
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
269+
if (($force_install_dir)) {
260270
{% if install_paths| selectattr("kind", "equalto", "CargoHome") %}
261-
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
271+
$dest_dir = Join-Path $force_install_dir "bin"
262272
$dest_dir_lib = $dest_dir
263273
{%- else -%}
264-
$dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
274+
$dest_dir = $force_install_dir
265275
$dest_dir_lib = $dest_dir
266276
{%- endif %}
267-
$receipt_dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
277+
$receipt_dest_dir = $force_install_dir
268278
}
269279
{%- for install_path in install_paths %}
270280
if (-Not $dest_dir) {

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,24 +394,34 @@ install() {
394394
local _install_dir_expr
395395
# Potentially-late-bound version of env_script_path to write to rcfiles like $HOME/.profile
396396
local _env_script_path_expr
397+
# Forces the install to occur at this path, not the default
398+
local _force_install_dir
399+
400+
# Check the newer app-specific variable before falling back
401+
# to the older generic one
402+
if [ -n "{{ '${' }}{{ install_dir_env_var }}:-}" ]; then
403+
_force_install_dir="${{ install_dir_env_var }}"
404+
elif [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
405+
_force_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
406+
fi
397407
398408
# Before actually consulting the configured install strategy, see
399409
# if we're overriding it.
400-
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
410+
if [ -n "${_force_install_dir:-}" ]; then
401411
{%- if install_paths | selectattr("kind", "equalto", "CargoHome") %}
402-
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
403-
_lib_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
404-
_receipt_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
405-
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
406-
_install_dir_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/bin")"
407-
_env_script_path_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/env")"
412+
_install_dir="$_force_install_dir/bin"
413+
_lib_install_dir="$_force_install_dir/bin"
414+
_receipt_install_dir="$_force_install_dir"
415+
_env_script_path="$_force_install_dir/env"
416+
_install_dir_expr="$(replace_home "$_force_install_dir/bin")"
417+
_env_script_path_expr="$(replace_home "$_force_install_dir/env")"
408418
{%- else %}
409-
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
410-
_lib_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
419+
_install_dir="$_force_install_dir"
420+
_lib_install_dir="$_force_install_dir"
411421
_receipt_install_dir="$_install_dir"
412-
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
413-
_install_dir_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR")"
414-
_env_script_path_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/env")"
422+
_env_script_path="$_force_install_dir/env"
423+
_install_dir_expr="$(replace_home "$_force_install_dir")"
424+
_env_script_path_expr="$(replace_home "$_force_install_dir/env")"
415425
{%- endif %}
416426
fi
417427

cargo-dist/tests/snapshots/akaikatana_basic.snap

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,26 @@ install() {
473473
local _install_dir_expr
474474
# Potentially-late-bound version of env_script_path to write to rcfiles like $HOME/.profile
475475
local _env_script_path_expr
476+
# Forces the install to occur at this path, not the default
477+
local _force_install_dir
478+
479+
# Check the newer app-specific variable before falling back
480+
# to the older generic one
481+
if [ -n "${AKAIKATANA_REPACK_INSTALL_DIR:-}" ]; then
482+
_force_install_dir="$AKAIKATANA_REPACK_INSTALL_DIR"
483+
elif [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
484+
_force_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
485+
fi
476486

477487
# Before actually consulting the configured install strategy, see
478488
# if we're overriding it.
479-
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
480-
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
481-
_lib_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
482-
_receipt_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
483-
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
484-
_install_dir_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/bin")"
485-
_env_script_path_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/env")"
489+
if [ -n "${_force_install_dir:-}" ]; then
490+
_install_dir="$_force_install_dir/bin"
491+
_lib_install_dir="$_force_install_dir/bin"
492+
_receipt_install_dir="$_force_install_dir"
493+
_env_script_path="$_force_install_dir/env"
494+
_install_dir_expr="$(replace_home "$_force_install_dir/bin")"
495+
_env_script_path_expr="$(replace_home "$_force_install_dir/env")"
486496
fi
487497
if [ -z "${_install_dir:-}" ]; then
488498
# first try $CARGO_HOME, then fallback to $HOME/.cargo
@@ -1427,6 +1437,16 @@ function Invoke-Installer($artifacts, $platforms) {
14271437

14281438
$info = $platforms[$arch]
14291439

1440+
# Forces the install to occur at this path, not the default
1441+
$force_install_dir = $null
1442+
# Check the newer app-specific variable before falling back
1443+
# to the older generic one
1444+
if (($env:AKAIKATANA_REPACK_INSTALL_DIR)) {
1445+
$force_install_dir = $env:AKAIKATANA_REPACK_INSTALL_DIR
1446+
} elseif (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
1447+
$force_install_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
1448+
}
1449+
14301450
# The actual path we're going to install to
14311451
$dest_dir = $null
14321452
$dest_dir_lib = $null
@@ -1437,11 +1457,11 @@ function Invoke-Installer($artifacts, $platforms) {
14371457
$receipt_dest_dir = $null
14381458
# Before actually consulting the configured install strategy, see
14391459
# if we're overriding it.
1440-
if (($env:CARGO_DIST_FORCE_INSTALL_DIR)) {
1460+
if (($force_install_dir)) {
14411461

1442-
$dest_dir = Join-Path $env:CARGO_DIST_FORCE_INSTALL_DIR "bin"
1462+
$dest_dir = Join-Path $force_install_dir "bin"
14431463
$dest_dir_lib = $dest_dir
1444-
$receipt_dest_dir = $env:CARGO_DIST_FORCE_INSTALL_DIR
1464+
$receipt_dest_dir = $force_install_dir
14451465
}
14461466
if (-Not $dest_dir) {
14471467
# first try $env:CARGO_HOME, then fallback to $HOME
@@ -1664,6 +1684,7 @@ try {
16641684
{
16651685
"app_name": "akaikatana-repack",
16661686
"app_version": "0.2.0",
1687+
"install_dir_env_var": "AKAIKATANA_REPACK_INSTALL_DIR",
16671688
"artifacts": [
16681689
"source.tar.gz",
16691690
"source.tar.gz.sha256",

cargo-dist/tests/snapshots/akaikatana_musl.snap

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,26 @@ install() {
481481
local _install_dir_expr
482482
# Potentially-late-bound version of env_script_path to write to rcfiles like $HOME/.profile
483483
local _env_script_path_expr
484+
# Forces the install to occur at this path, not the default
485+
local _force_install_dir
486+
487+
# Check the newer app-specific variable before falling back
488+
# to the older generic one
489+
if [ -n "${AKAIKATANA_REPACK_INSTALL_DIR:-}" ]; then
490+
_force_install_dir="$AKAIKATANA_REPACK_INSTALL_DIR"
491+
elif [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
492+
_force_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
493+
fi
484494

485495
# Before actually consulting the configured install strategy, see
486496
# if we're overriding it.
487-
if [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
488-
_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
489-
_lib_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR/bin"
490-
_receipt_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
491-
_env_script_path="$CARGO_DIST_FORCE_INSTALL_DIR/env"
492-
_install_dir_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/bin")"
493-
_env_script_path_expr="$(replace_home "$CARGO_DIST_FORCE_INSTALL_DIR/env")"
497+
if [ -n "${_force_install_dir:-}" ]; then
498+
_install_dir="$_force_install_dir/bin"
499+
_lib_install_dir="$_force_install_dir/bin"
500+
_receipt_install_dir="$_force_install_dir"
501+
_env_script_path="$_force_install_dir/env"
502+
_install_dir_expr="$(replace_home "$_force_install_dir/bin")"
503+
_env_script_path_expr="$(replace_home "$_force_install_dir/env")"
494504
fi
495505
if [ -z "${_install_dir:-}" ]; then
496506
# first try $CARGO_HOME, then fallback to $HOME/.cargo
@@ -1159,6 +1169,7 @@ download_binary_and_run_installer "$@" || exit 1
11591169
{
11601170
"app_name": "akaikatana-repack",
11611171
"app_version": "0.2.0",
1172+
"install_dir_env_var": "AKAIKATANA_REPACK_INSTALL_DIR",
11621173
"artifacts": [
11631174
"source.tar.gz",
11641175
"source.tar.gz.sha256",

0 commit comments

Comments
 (0)