Skip to content

Commit 32b31f2

Browse files
committed
ci/run.sh: Improve handling of host D compiler (de)activation
1 parent bcafd73 commit 32b31f2

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

.github/workflows/main.yml

-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ jobs:
157157
arch: ${{ env.MODEL == '64' && 'x64' || 'x86' }}
158158
- name: Build
159159
run: ${{ matrix.disable_debug_for_dmd_unittests && 'ENABLE_DEBUG=0' || '' }} ci/run.sh build
160-
env:
161-
# on Windows, `ci/run.sh build` expects the DMD env var to be set to the DMD-CLI-compatible host compiler
162-
DMD: ${{ runner.os == 'Windows' && (startsWith(matrix.host_dmd, 'ldc') && 'ldmd2' || 'dmd') || '' }}
163160
- name: Rebuild dmd (with enabled coverage)
164161
if: matrix.coverage
165162
run: ENABLE_RELEASE=0 ENABLE_DEBUG=1 ENABLE_COVERAGE=1 ci/run.sh rebuild

ci/run.sh

+30-14
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,15 @@ clone() {
6666
# build dmd (incl. building and running the unittests), druntime, phobos
6767
build() {
6868
local unittest=${1:-1}
69-
if [ "$OS_NAME" != "windows" ]; then
70-
source ~/dlang/*/activate # activate host compiler, incl. setting `DMD`
71-
fi
69+
activate_host_compiler
7270
$DMD compiler/src/build.d -ofgenerated/build
7371
if [ $unittest -eq 1 ]; then
7472
generated/build -j$N MODEL=$MODEL HOST_DMD=$DMD DFLAGS="$CI_DFLAGS" BUILD=debug unittest
7573
fi
7674
generated/build -j$N MODEL=$MODEL HOST_DMD=$DMD DFLAGS="$CI_DFLAGS" ENABLE_RELEASE=${ENABLE_RELEASE:-1} dmd
7775
make -j$N -C druntime MODEL=$MODEL
7876
make -j$N -C ../phobos MODEL=$MODEL
79-
if [ "$OS_NAME" != "windows" ]; then
80-
deactivate # deactivate host compiler
81-
fi
77+
deactivate_host_compiler
8278
}
8379

8480
# self-compile dmd
@@ -176,7 +172,7 @@ test_phobos() {
176172
elif [ "$HOST_DMD" == "dmd-2.079.0" ]; then
177173
echo "Skipping publictests with DMD v2.079 host compiler (dub too old)"
178174
else
179-
source ~/dlang/*/activate # activate host compiler - need dub
175+
activate_host_compiler # need dub
180176

181177
make -j$N -C ../phobos MODEL=$MODEL publictests
182178
make -j$N -C ../phobos MODEL=$MODEL publictests NO_BOUNDSCHECKS=1
@@ -187,15 +183,13 @@ test_phobos() {
187183
make -j$N -C ../phobos MODEL=$MODEL betterc
188184
fi
189185

190-
deactivate # deactivate host compiler
186+
deactivate_host_compiler
191187
fi
192188
}
193189

194190
# test dub package
195191
test_dub_package() {
196-
if [ "$OS_NAME" != "windows" ]; then
197-
source ~/dlang/*/activate # activate host compiler
198-
fi
192+
activate_host_compiler
199193
# GDC's standard library is too old for some example scripts
200194
if [[ "${DMD:-dmd}" =~ "gdmd" ]] ; then
201195
echo "Skipping DUB examples on GDC."
@@ -217,9 +211,7 @@ test_dub_package() {
217211
# Test rdmd build
218212
"${build_path}/dmd" -version=NoBackend -version=GC -version=NoMain -Jgenerated/dub -Jsrc/dmd/res -Isrc -i -run test/dub_package/frontend.d
219213
fi
220-
if [ "$OS_NAME" != "windows" ]; then
221-
deactivate
222-
fi
214+
deactivate_host_compiler
223215
}
224216

225217
# clone phobos repos if not already available
@@ -303,6 +295,30 @@ install_host_compiler() {
303295
fi
304296
}
305297

298+
# activate D host compiler (set PATH and DMD environment variables)
299+
activate_host_compiler()
300+
{
301+
if [ "$OS_NAME" == "windows" ]; then
302+
# PATH is already set
303+
if [ "${HOST_DMD:0:4}" == "ldc-" ]; then
304+
export DMD="ldmd2"
305+
else
306+
export DMD="dmd"
307+
fi
308+
else
309+
source ~/dlang/*/activate
310+
fi
311+
}
312+
313+
deactivate_host_compiler()
314+
{
315+
if [ "$OS_NAME" == "windows" ]; then
316+
unset DMD
317+
else
318+
deactivate
319+
fi
320+
}
321+
306322
# Upload coverage reports
307323
codecov()
308324
{

0 commit comments

Comments
 (0)