mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
feat: Support configurable ASDF_CONCURRENCY
(#1532)
Co-authored-by: James Hegedus <jthegedus@hey.com>
This commit is contained in:
parent
a1e858d254
commit
684f4f058f
1
defaults
1
defaults
@ -5,3 +5,4 @@ use_release_candidates = no
|
|||||||
always_keep_download = no
|
always_keep_download = no
|
||||||
plugin_repository_last_check_duration = 60
|
plugin_repository_last_check_duration = 60
|
||||||
disable_plugin_short_name_repository = no
|
disable_plugin_short_name_repository = no
|
||||||
|
concurrency = auto
|
||||||
|
@ -134,45 +134,85 @@ Disabling the plugin short-name repository does not remove plugins previously in
|
|||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
### `concurrency`
|
||||||
|
|
||||||
|
The default number of cores to use during compilation.
|
||||||
|
|
||||||
|
| Options | Description |
|
||||||
|
| :------ | :--------------------------------------------------------------------------------------------------- |
|
||||||
|
| integer | Number of cores to use when compiling the source code |
|
||||||
|
| `auto` | Calculate the number of cores using `nproc`, then `sysctl hw.ncpu`, then `/proc/cpuinfo` or else `1` |
|
||||||
|
|
||||||
|
Note: the environment variable `ASDF_CONCURRENCY` take precedence if set.
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
Setting environment variables varies depending on your system and Shell. Default locations depend upon your installation location and method (Git clone, Homebrew, AUR).
|
Setting environment variables varies depending on your system and Shell. Default locations depend upon your installation location and method (Git clone, Homebrew, AUR).
|
||||||
|
|
||||||
Environment variables should generally be set before sourcing `asdf.sh`/`asdf.fish` etc. For Elvish set above `use asdf`.
|
Environment variables should generally be set before sourcing `asdf.sh`/`asdf.fish` etc. For Elvish set above `use asdf`.
|
||||||
|
|
||||||
The following examples assume:
|
The following describe usage with a Bash Shell.
|
||||||
|
|
||||||
- an installation to `$HOME/.asdf`
|
|
||||||
- a Bash Shell
|
|
||||||
|
|
||||||
### `ASDF_CONFIG_FILE`
|
### `ASDF_CONFIG_FILE`
|
||||||
|
|
||||||
Path to the `.asdfrc` configuration file. Can be set to any location. Must be an absolute path.
|
Path to the `.asdfrc` configuration file. Can be set to any location. Must be an absolute path.
|
||||||
|
|
||||||
- Default: `$HOME/.asdfrc`
|
- If Unset: `$HOME/.asdfrc` will be used.
|
||||||
- Usage: `export ASDF_CONFIG_FILE=/home/john_doe/.config/asdf/.asdfrc`
|
- Usage: `export ASDF_CONFIG_FILE=/home/john_doe/.config/asdf/.asdfrc`
|
||||||
|
|
||||||
### `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`
|
### `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`
|
||||||
|
|
||||||
The filename of the file storing the tool names and versions. Can be any valid filename. Typically, you should not set this value unless you want to ignore `.tool-versions` files.
|
The filename of the file storing the tool names and versions. Can be any valid filename. Typically, you should not set this value unless you want to ignore `.tool-versions` files.
|
||||||
|
|
||||||
- Default: `.tool-versions`
|
- If Unset: `.tool-versions` will be used.
|
||||||
- Usage: `export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=tool_versions`
|
- Usage: `export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=tool_versions`
|
||||||
|
|
||||||
### `ASDF_DIR`
|
### `ASDF_DIR`
|
||||||
|
|
||||||
The location of `asdf` core scripts. Can be set to any location. Must be an absolute path.
|
The location of `asdf` core scripts. Can be set to any location. Must be an absolute path.
|
||||||
|
|
||||||
- Default: `$HOME/.asdf` (always the parent directory of the `bin/asdf` executable)
|
- If Unset: the parent directory of the `bin/asdf` executable is used.
|
||||||
- Usage: `export ASDF_DIR=/home/john_doe/.config/asdf`
|
- Usage: `export ASDF_DIR=/home/john_doe/.config/asdf`
|
||||||
|
|
||||||
### `ASDF_DATA_DIR`
|
### `ASDF_DATA_DIR`
|
||||||
|
|
||||||
The location where `asdf` will install plugins, shims and tool versions. Can be set to any location. Must be an absolute path.
|
The location where `asdf` will install plugins, shims and tool versions. Can be set to any location. Must be an absolute path.
|
||||||
|
|
||||||
- Default: `$HOME/.asdf`
|
- If Unset: `$HOME/.asdf` if it exists, or else the value of `ASDF_DIR`
|
||||||
- Usage: `export ASDF_DATA_DIR=/home/john_doe/.asdf`
|
- Usage: `export ASDF_DATA_DIR=/home/john_doe/.asdf`
|
||||||
|
|
||||||
|
### `ASDF_CONCURRENCY`
|
||||||
|
|
||||||
|
Number of cores to use when compiling the source code. If set, this value takes precedence over the asdf config `concurrency` value.
|
||||||
|
|
||||||
|
- If Unset: the asdf config `concurrency` value is used.
|
||||||
|
- Usage: `export ASDF_CONCURRENCY=32`
|
||||||
|
|
||||||
|
## Full Configuration Example
|
||||||
|
|
||||||
|
Following a simple asdf setup with:
|
||||||
|
|
||||||
|
- a Bash Shell
|
||||||
|
- an installation location of `$HOME/.asdf`
|
||||||
|
- installed via Git
|
||||||
|
- NO environment variables set
|
||||||
|
- NO custom `.asdfrc` file
|
||||||
|
|
||||||
|
would result in the following outcomes:
|
||||||
|
|
||||||
|
| Configuration | Value | Calculated by |
|
||||||
|
| :------------------------------------ | :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| config file location | `$HOME/.asdfrc` | `ASDF_CONFIG_FILE` is empty, so use `$HOME/.asdfrc` |
|
||||||
|
| default tool versions filename | `.tool-versions` | `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME` is empty, so use `.tool-versions` |
|
||||||
|
| asdf dir | `$HOME/.asdf` | `ASDF_DIR` is empty, so use parent dir of `bin/asdf` |
|
||||||
|
| asdf data dir | `$HOME/.asdf` | `ASDF_DATA_DIR` is empty so use `$HOME/.asdf` as `$HOME` exists. |
|
||||||
|
| concurrency | `auto` | `ASDF_CONCURRENCY` is empty, so rely on `concurrency` value from the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
|
||||||
|
| legacy_version_file | `no` | No custom `.asdfrc`, so use the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
|
||||||
|
| use_release_candidates | `no` | No custom `.asdfrc`, so use the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
|
||||||
|
| always_keep_download | `no` | No custom `.asdfrc`, so use the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
|
||||||
|
| plugin_repository_last_check_duration | `60` | No custom `.asdfrc`, so use the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
|
||||||
|
| disable_plugin_short_name_repository | `no` | No custom `.asdfrc`, so use the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
|
||||||
|
|
||||||
## Internal Configuration
|
## Internal Configuration
|
||||||
|
|
||||||
Users should not worry about this section as it describes configuration internal to `asdf` useful for Package Managers and integrators.
|
Users should not worry about this section as it describes configuration internal to `asdf` useful for Package Managers and integrators.
|
||||||
|
@ -25,15 +25,27 @@ install_command() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_concurrency() {
|
get_concurrency() {
|
||||||
if command -v nproc &>/dev/null; then
|
local asdf_concurrency=
|
||||||
nproc
|
|
||||||
elif command -v sysctl &>/dev/null && sysctl hw.ncpu &>/dev/null; then
|
if [ -n "$ASDF_CONCURRENCY" ]; then
|
||||||
sysctl -n hw.ncpu
|
asdf_concurrency="$ASDF_CONCURRENCY"
|
||||||
elif [ -f /proc/cpuinfo ]; then
|
|
||||||
grep -c processor /proc/cpuinfo
|
|
||||||
else
|
else
|
||||||
printf "1\n"
|
asdf_concurrency=$(get_asdf_config_value 'concurrency')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$asdf_concurrency" = 'auto' ]; then
|
||||||
|
if command -v nproc &>/dev/null; then
|
||||||
|
asdf_concurrency=$(nproc)
|
||||||
|
elif command -v sysctl &>/dev/null && sysctl hw.ncpu &>/dev/null; then
|
||||||
|
asdf_concurrency=$(sysctl -n hw.ncpu)
|
||||||
|
elif [ -f /proc/cpuinfo ]; then
|
||||||
|
asdf_concurrency=$(grep -c processor /proc/cpuinfo)
|
||||||
|
else
|
||||||
|
asdf_concurrency="1"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s\n" "$asdf_concurrency"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_one_local_tool() {
|
install_one_local_tool() {
|
||||||
|
@ -52,6 +52,25 @@ teardown() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "install_command set ASDF_CONCURRENCY via env var" {
|
||||||
|
ASDF_CONCURRENCY=-1 run asdf install dummy 1.0.0
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ -f "$ASDF_DIR/installs/dummy/1.0.0/env" ]
|
||||||
|
run grep ASDF_CONCURRENCY=-1 "$ASDF_DIR/installs/dummy/1.0.0/env"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "install_command set ASDF_CONCURRENCY via asdfrc" {
|
||||||
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
||||||
|
concurrency = -2
|
||||||
|
EOM
|
||||||
|
run asdf install dummy 1.0.0
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ -f "$ASDF_DIR/installs/dummy/1.0.0/env" ]
|
||||||
|
run grep ASDF_CONCURRENCY=-2 "$ASDF_DIR/installs/dummy/1.0.0/env"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
@test "install_command without arguments should work in directory containing whitespace" {
|
@test "install_command without arguments should work in directory containing whitespace" {
|
||||||
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
|
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
|
||||||
mkdir -p "$WHITESPACE_DIR"
|
mkdir -p "$WHITESPACE_DIR"
|
||||||
|
Loading…
Reference in New Issue
Block a user