Skip to content

Commit 60dbf57

Browse files
authored
Merge pull request #331 from aminya/llvm-remove-repo [skip ci]
feat: remove the LLVM repo on apt install failures + support LLVM 11-16 on Ubuntu 24 + fix GCC on Linux Arm64 + install GCC without PPA if possible
2 parents 1fd8139 + 035c062 commit 60dbf57

14 files changed

+527
-46
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.13.0
1+
22.13.1

dist/legacy/llvm_repo_remove.bash

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/bash -e
2+
3+
# This script will remove the llvm repository from the system
4+
# It's the opposite of https://apt.llvm.org/llvm.sh
5+
6+
set -eux
7+
8+
CURRENT_LLVM_STABLE=18
9+
BASE_URL="http://apt.llvm.org"
10+
11+
# Check for required tools
12+
needed_binaries=(lsb_release wget add-apt-repository gpg)
13+
missing_binaries=()
14+
for binary in "${needed_binaries[@]}"; do
15+
if ! which $binary &>/dev/null ; then
16+
missing_binaries+=($binary)
17+
fi
18+
done
19+
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
20+
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
21+
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
22+
exit 4
23+
fi
24+
25+
# Set default values for commandline arguments
26+
# We default to the current stable branch of LLVM
27+
LLVM_VERSION=$CURRENT_LLVM_STABLE
28+
ALL=0
29+
DISTRO=$(lsb_release -is)
30+
VERSION=$(lsb_release -sr)
31+
UBUNTU_CODENAME=""
32+
CODENAME_FROM_ARGUMENTS=""
33+
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
34+
source /etc/os-release
35+
DISTRO=${DISTRO,,}
36+
case ${DISTRO} in
37+
debian)
38+
# Debian Trixie has a workaround because of
39+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383
40+
if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then
41+
CODENAME=unstable
42+
LINKNAME=
43+
else
44+
# "stable" Debian release
45+
CODENAME=${VERSION_CODENAME}
46+
LINKNAME=-${CODENAME}
47+
fi
48+
;;
49+
*)
50+
# ubuntu and its derivatives
51+
if [[ -n "${UBUNTU_CODENAME}" ]]; then
52+
CODENAME=${UBUNTU_CODENAME}
53+
if [[ -n "${CODENAME}" ]]; then
54+
LINKNAME=-${CODENAME}
55+
fi
56+
fi
57+
;;
58+
esac
59+
60+
# read optional command line arguments
61+
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
62+
if [ "$1" != "all" ]; then
63+
LLVM_VERSION=$1
64+
else
65+
# special case for ./llvm.sh all
66+
ALL=1
67+
fi
68+
OPTIND=2
69+
if [ "$#" -ge 2 ]; then
70+
if [ "$2" == "all" ]; then
71+
# Install all packages
72+
ALL=1
73+
OPTIND=3
74+
fi
75+
fi
76+
fi
77+
78+
while getopts ":hm:n:" arg; do
79+
case $arg in
80+
h)
81+
usage
82+
;;
83+
m)
84+
BASE_URL=${OPTARG}
85+
;;
86+
n)
87+
CODENAME=${OPTARG}
88+
if [[ "${CODENAME}" == "unstable" ]]; then
89+
# link name does not apply to unstable repository
90+
LINKNAME=
91+
else
92+
LINKNAME=-${CODENAME}
93+
fi
94+
CODENAME_FROM_ARGUMENTS="true"
95+
;;
96+
esac
97+
done
98+
99+
if [[ $EUID -ne 0 ]]; then
100+
echo "This script must be run as root!"
101+
exit 1
102+
fi
103+
104+
declare -A LLVM_VERSION_PATTERNS
105+
LLVM_VERSION_PATTERNS[9]="-9"
106+
LLVM_VERSION_PATTERNS[10]="-10"
107+
LLVM_VERSION_PATTERNS[11]="-11"
108+
LLVM_VERSION_PATTERNS[12]="-12"
109+
LLVM_VERSION_PATTERNS[13]="-13"
110+
LLVM_VERSION_PATTERNS[14]="-14"
111+
LLVM_VERSION_PATTERNS[15]="-15"
112+
LLVM_VERSION_PATTERNS[16]="-16"
113+
LLVM_VERSION_PATTERNS[17]="-17"
114+
LLVM_VERSION_PATTERNS[18]="-18"
115+
LLVM_VERSION_PATTERNS[19]="-19"
116+
LLVM_VERSION_PATTERNS[20]=""
117+
118+
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
119+
echo "This script does not support LLVM version $LLVM_VERSION"
120+
exit 3
121+
fi
122+
123+
LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
124+
125+
# join the repository name
126+
if [[ -n "${CODENAME}" ]]; then
127+
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"
128+
129+
# check if the repository exists for the distro and version
130+
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
131+
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
132+
echo "Specified codename '${CODENAME}' is not supported by this script."
133+
else
134+
echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script."
135+
fi
136+
exit 2
137+
fi
138+
fi
139+
140+
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
141+
# add it twice to workaround:
142+
# https://github.com/llvm/llvm-project/issues/62475
143+
add-apt-repository -y "${REPO_NAME}"
144+
fi
145+
146+
add-apt-repository -y --no-update --remove "${REPO_NAME}"
147+
apt-get update

dist/legacy/setup-cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/llvm_repo_remove.bash

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/bash -e
2+
3+
# This script will remove the llvm repository from the system
4+
# It's the opposite of https://apt.llvm.org/llvm.sh
5+
6+
set -eux
7+
8+
CURRENT_LLVM_STABLE=18
9+
BASE_URL="http://apt.llvm.org"
10+
11+
# Check for required tools
12+
needed_binaries=(lsb_release wget add-apt-repository gpg)
13+
missing_binaries=()
14+
for binary in "${needed_binaries[@]}"; do
15+
if ! which $binary &>/dev/null ; then
16+
missing_binaries+=($binary)
17+
fi
18+
done
19+
if [[ ${#missing_binaries[@]} -gt 0 ]] ; then
20+
echo "You are missing some tools this script requires: ${missing_binaries[@]}"
21+
echo "(hint: apt install lsb-release wget software-properties-common gnupg)"
22+
exit 4
23+
fi
24+
25+
# Set default values for commandline arguments
26+
# We default to the current stable branch of LLVM
27+
LLVM_VERSION=$CURRENT_LLVM_STABLE
28+
ALL=0
29+
DISTRO=$(lsb_release -is)
30+
VERSION=$(lsb_release -sr)
31+
UBUNTU_CODENAME=""
32+
CODENAME_FROM_ARGUMENTS=""
33+
# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives)
34+
source /etc/os-release
35+
DISTRO=${DISTRO,,}
36+
case ${DISTRO} in
37+
debian)
38+
# Debian Trixie has a workaround because of
39+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383
40+
if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then
41+
CODENAME=unstable
42+
LINKNAME=
43+
else
44+
# "stable" Debian release
45+
CODENAME=${VERSION_CODENAME}
46+
LINKNAME=-${CODENAME}
47+
fi
48+
;;
49+
*)
50+
# ubuntu and its derivatives
51+
if [[ -n "${UBUNTU_CODENAME}" ]]; then
52+
CODENAME=${UBUNTU_CODENAME}
53+
if [[ -n "${CODENAME}" ]]; then
54+
LINKNAME=-${CODENAME}
55+
fi
56+
fi
57+
;;
58+
esac
59+
60+
# read optional command line arguments
61+
if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then
62+
if [ "$1" != "all" ]; then
63+
LLVM_VERSION=$1
64+
else
65+
# special case for ./llvm.sh all
66+
ALL=1
67+
fi
68+
OPTIND=2
69+
if [ "$#" -ge 2 ]; then
70+
if [ "$2" == "all" ]; then
71+
# Install all packages
72+
ALL=1
73+
OPTIND=3
74+
fi
75+
fi
76+
fi
77+
78+
while getopts ":hm:n:" arg; do
79+
case $arg in
80+
h)
81+
usage
82+
;;
83+
m)
84+
BASE_URL=${OPTARG}
85+
;;
86+
n)
87+
CODENAME=${OPTARG}
88+
if [[ "${CODENAME}" == "unstable" ]]; then
89+
# link name does not apply to unstable repository
90+
LINKNAME=
91+
else
92+
LINKNAME=-${CODENAME}
93+
fi
94+
CODENAME_FROM_ARGUMENTS="true"
95+
;;
96+
esac
97+
done
98+
99+
if [[ $EUID -ne 0 ]]; then
100+
echo "This script must be run as root!"
101+
exit 1
102+
fi
103+
104+
declare -A LLVM_VERSION_PATTERNS
105+
LLVM_VERSION_PATTERNS[9]="-9"
106+
LLVM_VERSION_PATTERNS[10]="-10"
107+
LLVM_VERSION_PATTERNS[11]="-11"
108+
LLVM_VERSION_PATTERNS[12]="-12"
109+
LLVM_VERSION_PATTERNS[13]="-13"
110+
LLVM_VERSION_PATTERNS[14]="-14"
111+
LLVM_VERSION_PATTERNS[15]="-15"
112+
LLVM_VERSION_PATTERNS[16]="-16"
113+
LLVM_VERSION_PATTERNS[17]="-17"
114+
LLVM_VERSION_PATTERNS[18]="-18"
115+
LLVM_VERSION_PATTERNS[19]="-19"
116+
LLVM_VERSION_PATTERNS[20]=""
117+
118+
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
119+
echo "This script does not support LLVM version $LLVM_VERSION"
120+
exit 3
121+
fi
122+
123+
LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]}
124+
125+
# join the repository name
126+
if [[ -n "${CODENAME}" ]]; then
127+
REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main"
128+
129+
# check if the repository exists for the distro and version
130+
if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null; then
131+
if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then
132+
echo "Specified codename '${CODENAME}' is not supported by this script."
133+
else
134+
echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script."
135+
fi
136+
exit 2
137+
fi
138+
fi
139+
140+
if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then
141+
# add it twice to workaround:
142+
# https://github.com/llvm/llvm-project/issues/62475
143+
add-apt-repository -y "${REPO_NAME}"
144+
fi
145+
146+
add-apt-repository -y --no-update --remove "${REPO_NAME}"
147+
apt-get update

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
"tsconfig.json"
2727
],
2828
"scripts": {
29-
"build": "turbo build && run-p lint.root.tsc build.vite build.vite.legacy && run-s build.json",
29+
"build": "turbo build && run-p lint.root.tsc build.vite build.vite.legacy && run-p build.json build.bash",
3030
"build.vite": "cross-env NODE_ENV=production vite build",
3131
"build.vite.legacy": "cross-env NODE_ENV=production TARGET=legacy vite build",
3232
"build.json": "shx cp ./src/*/*.json ./dist/legacy/ && shx cp ./dist/legacy/*.json ./dist/modern && minijson --file ./dist/**/*.json",
33+
"build.bash": "shx cp ./src/*/*.bash ./dist/legacy/ && shx cp ./dist/legacy/*.bash ./dist/modern",
3334
"bump": "ncu -u -x execa,numerous,eslint,@types/eslint,which && pnpm update && pnpx typesync && pnpm run clean",
3435
"bump.llvm": "GITHUB_TOKEN=$(gh auth token) tsx ./src/llvm/assets-list.ts",
3536
"bump.gcc": "GITHUB_TOKEN=$(gh auth token) tsx ./src/gcc/assets-list.ts",
@@ -191,7 +192,7 @@
191192
"node": ">=12.x",
192193
"pnpm": "^9"
193194
},
194-
"packageManager": "[email protected].3",
195+
"packageManager": "[email protected].4",
195196
"workspaces": [
196197
"packages/*"
197198
],

packages/setup-apt/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-apt",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"description": "Setup apt packages and repositories in Debian/Ubuntu-based distributions",
55
"repository": "https://github.com/aminya/setup-cpp",
66
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-apt",

packages/setup-apt/src/apt-repository.ts

+13
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ export async function installAddAptRepo(apt: string) {
2626
{ ...defaultExecOptions, env: getAptEnv(apt) },
2727
)
2828
}
29+
30+
export async function removeAptRepository(repo: string, apt = getApt()) {
31+
await initAptMemoized(apt)
32+
await installAddAptRepo(apt)
33+
execRootSync("add-apt-repository", ["-y", "--no-update", "--remove", repo], {
34+
...defaultExecOptions,
35+
env: getAptEnv(apt),
36+
})
37+
38+
// Update the repos
39+
updateAptReposMemoized.clear() // ensure update is called
40+
updateAptReposMemoized(apt)
41+
}

0 commit comments

Comments
 (0)