Skip to content

maint(common): consolidate functions to determine OS #14109

Open
@ermshiperete

Description

@ermshiperete

We have at least three different functions to determine the current OS. From #14049 (comment):

We have a similar test in build-utils.sh and in builder.inc.sh... It would be good to have this in just one place. I am okay with this being a separate refactor task because there is a bit of a tangle with /resources/builder.inc.sh, /resources/build/builder.inc.sh, /resources/build/build-utils.sh, and /resources/shellHelperFunctions.sh that we need to sort out also.

fi
# --- Detect tools ---
local builder_installed_tools=()
# Detect delphi compiler (see also delphi_environment.inc.sh)
if [[ $builder_platform == win ]]; then
local ProgramFilesx86="$(cygpath -w -F 42)"
if [[ -x "$(cygpath -u "$ProgramFilesx86\\Embarcadero\\Studio\\20.0\\bin\\dcc32.exe")" ]]; then
builder_installed_tools+=(delphi)
fi
fi

_builder_get_operating_system() {
declare -g BUILDER_OS
# Default value, since it's the most general case/configuration to detect.
BUILDER_OS=linux
# Subject to change with future improvements.
if [[ $OSTYPE == darwin* ]]; then
BUILDER_OS=mac
elif [[ $OSTYPE == msys ]]; then
BUILDER_OS=win
elif [[ $OSTYPE == cygwin ]]; then
BUILDER_OS=win
fi
readonly BUILDER_OS
}
_builder_get_operating_system

and #14049 introduced:

# Returns 0 if we're running on Ubuntu.
is_ubuntu() {
if [[ "${OSTYPE:-}" == "linux-gnu" ]]; then
return 0
else
return 1
fi
}
# Returns 0 if we're running on Windows, i.e. if the environment variable
# `OSTYPE` is set to "msys" or "cygwin".
is_windows() {
if [[ "${OSTYPE:-}" == "msys" ]] || [[ "${OSTYPE:-}" == "cygwin" ]]; then
return 0
else
return 1
fi
}
# Returns 0 if we're running on macOS.
is_macos() {
if [[ "${OSTYPE:-}" == "darwin" ]]; then
return 0
else
return 1
fi
}

See also:

Metadata

Metadata

Labels

common/maintMaintenance work -- continuous integration, build scripts, infrastructure

Type

No type

Projects

Status

Todo

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions