Skip to content

Commit

Permalink
make deprecationWarnings/Errors consistent
Browse files Browse the repository at this point in the history
There was different behavior in GDC and deprecationWarnings did not
perform expected results with DMD and LDC.
  • Loading branch information
WebFreak001 committed Dec 15, 2022
1 parent 1330c9d commit e9dad94
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 6 deletions.
22 changes: 22 additions & 0 deletions changelog/deprecations-warnings-errors.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Made deprecations, warnings and errors consistent across compilers

With DMD and LDC there is a special "Deprecation" compile log message class, which
does not abort the build, even if `buildOptions "warningsAsErrors"` is set. With
GDC this special log class doesn't exist, so previously DUB would have aborted
compilation on deprecations due to the warningsAsErrors build option being set
by default.

DMD and LDC didn't abort the build at all if `buildOptions "deprecationWarnings"`
was set, even if `"warningsAsErrors"` was (implicitly or explicitly) set.

Now the behavior is consistent across all compilers:

- deprecations are not treated as errors inside GDC with the default `"warningsAsErrors"` flag anymore
- from this release on, the old GDC behavior can be replicated across all compilers using `buildOptions "deprecationWarnings"`
- to do this with previous DUB versions, use `buildOptions "deprecationErrors"` if you haven't manually disabled the default warningsAsErrors behavior.
- `"deprecationWarnings"` now implies `"deprecationErrors"` if `"warningsAsErrors"` is set (the default)

Internally for GDC DUB will now emit `-Wno-error=deprecated` when build option
`"warningsAsError"` is on, not aborting the build, when there is a deprecation.
Note that GDC will still print "Warning" for deprecations, but not abort the
build.
3 changes: 2 additions & 1 deletion source/dub/compilers/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DMDCompiler : Compiler {
tuple(BuildOption.ignoreDeprecations, ["-d"]),
tuple(BuildOption.deprecationWarnings, ["-dw"]),
tuple(BuildOption.deprecationErrors, ["-de"]),
tuple(BuildOption.deprecationWarnings | BuildOption.warningsAsErrors, ["-de"]),
tuple(BuildOption.property, ["-property"]),
tuple(BuildOption.profileGC, ["-profile=gc"]),
tuple(BuildOption.betterC, ["-betterC"]),
Expand Down Expand Up @@ -232,7 +233,7 @@ config /etc/dmd.conf

if (!(fields & BuildSetting.options)) {
foreach (t; s_options)
if (settings.options & t[0])
if ((settings.options & t[0]) == BitFlags!BuildOption(t[0]))
settings.addDFlags(t[1]);
}

Expand Down
9 changes: 5 additions & 4 deletions source/dub/compilers/gdc.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ class GDCCompiler : Compiler {
tuple(BuildOption.verbose, ["-v"]),
tuple(BuildOption.ignoreUnknownPragmas, ["-fignore-unknown-pragmas"]),
tuple(BuildOption.syntaxOnly, ["-fsyntax-only"]),
tuple(BuildOption.warnings, ["-Wall"]),
tuple(BuildOption.warningsAsErrors, ["-Werror", "-Wall"]),
tuple(BuildOption.warnings, ["-Wall", "-Wextra"]),
tuple(BuildOption.warningsAsErrors, ["-Werror", "-Wall", "-Wextra", "-Wno-error=deprecated"]),
tuple(BuildOption.ignoreDeprecations, ["-Wno-deprecated"]),
tuple(BuildOption.deprecationWarnings, ["-Wdeprecated"]),
tuple(BuildOption.deprecationErrors, ["-Werror", "-Wdeprecated"]),
tuple(BuildOption.deprecationErrors, ["-Werror=deprecated"]),
tuple(BuildOption.deprecationWarnings | BuildOption.warningsAsErrors, ["-Werror=deprecated"]),
tuple(BuildOption.property, ["-fproperty"]),
//tuple(BuildOption.profileGC, ["-?"]),
tuple(BuildOption.betterC, ["-fno-druntime"]),
Expand Down Expand Up @@ -91,7 +92,7 @@ class GDCCompiler : Compiler {

if (!(fields & BuildSetting.options)) {
foreach (t; s_options)
if (settings.options & t[0])
if ((settings.options & t[0]) == BitFlags!BuildOption(t[0]))
settings.addDFlags(t[1]);
}

Expand Down
3 changes: 2 additions & 1 deletion source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LDCCompiler : Compiler {
tuple(BuildOption.ignoreDeprecations, ["-d"]),
tuple(BuildOption.deprecationWarnings, ["-dw"]),
tuple(BuildOption.deprecationErrors, ["-de"]),
tuple(BuildOption.deprecationWarnings | BuildOption.warningsAsErrors, ["-de"]),
tuple(BuildOption.property, ["-property"]),
//tuple(BuildOption.profileGC, ["-?"]),
tuple(BuildOption.betterC, ["-betterC"]),
Expand Down Expand Up @@ -109,7 +110,7 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)

if (!(fields & BuildSetting.options)) {
foreach (t; s_options)
if (settings.options & t[0])
if ((settings.options & t[0]) == BitFlags!BuildOption(t[0]))
settings.addDFlags(t[1]);
}

Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ version-filters-source-dep/version-filters-source-dep
version-filters/version-filters
version-spec/newfoo/foo-test-application
version-spec/oldfoo/foo-test-application
warnings/warnings
43 changes: 43 additions & 0 deletions test/warnings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

. $(dirname "${BASH_SOURCE[0]}")/common.sh

echo "Regular run"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable 2>&1 >/dev/null
echo "Expect bar() to be called"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-d 2>&1 | grep 'called bar' -c

echo "Should have no deprecation message"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-d --build=no-d 2>&1 | { ! grep -F 'deprecated' -c; }
echo "Deprecation should cause error"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-d --build=de 2>&1 >/dev/null
echo "Deprecation should cause warning, thus an error because of default warning-as-error behavior"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-d --build=dw 2>&1 >/dev/null
echo "Deprecation as error should cause error, even if warnings are allowed"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-d --build=de-allow 2>&1 >/dev/null
echo "Deprecation as warning should be fine if warnings are allowed"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-d --build=dw-allow 2>&1 | grep -F 'deprecated' -c
echo "Allowing warnings should leave deprecations untouched"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-d --build=allow 2>&1 | grep -F 'deprecated' -c

echo "Expecting warning output with deprecationErrors still working as usual"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-w --build=de-allow 2>&1 | grep -i 'warning' -c
echo "Expecting warning output with deprecationWarnings still working as usual"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-w --build=dw-allow 2>&1 | grep -i 'warning' -c
echo "Expecting warning output with allowed warnings working as usual"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-w --build=allow 2>&1 | grep -i 'warning' -c
echo "Make sure the deprecated function didn't somehow get in"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-w --build=allow 2>&1 | { ! grep 'called bar' -c; }

echo "Warning should break build, deprecation should still be in"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-dw --build=no-d 2>&1 | grep -F 'deprecated' -c
echo "Warning + deprecation as error should break build"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-dw --build=de 2>&1 | grep -F 'deprecated' -c
echo "Warning + deprecation as warning should break build"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-dw --build=dw 2>&1 | grep -F 'deprecated' -c
echo "deprecation as error with allowed warnings should break build"
! $DUB run --force --root="$CURR_DIR/warnings" --config=executable-dw --build=de-allow 2>&1 >/dev/null
echo "deprecation as warnings with allowed warnings should work fine"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-dw --build=dw-allow 2>&1 | grep -F 'deprecated' -c
echo "allowed warnings should work fine"
$DUB run --force --root="$CURR_DIR/warnings" --config=executable-dw --build=allow 2>&1 | grep -F 'deprecated' -c
Empty file added test/warnings/.no_build
Empty file.
Empty file added test/warnings/.no_run
Empty file.
Empty file added test/warnings/.no_test
Empty file.
46 changes: 46 additions & 0 deletions test/warnings/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name "warnings"

configuration "executable" {
targetType "executable"
}

configuration "executable-d" {
targetType "executable"
versions "Include_Deprecation"
}

configuration "executable-w" {
targetType "executable"
versions "Include_Warning"
}

configuration "executable-dw" {
targetType "executable"
versions "Include_Deprecation" "Include_Warning"
}

buildType "no-d" {
buildRequirements "silenceDeprecations"
}

buildType "de" {
buildOptions "deprecationErrors"
}

buildType "dw" {
buildOptions "deprecationWarnings"
}

buildType "de-allow" {
buildOptions "deprecationErrors"
buildRequirements "allowWarnings"
}

buildType "dw-allow" {
buildOptions "deprecationWarnings"
buildRequirements "allowWarnings"
}

buildType "allow" {
buildRequirements "allowWarnings"
}
29 changes: 29 additions & 0 deletions test/warnings/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import std.stdio;

version(Include_Warning)
{
void foo()
{
return;
writeln("unreachable statement");
}
}

version(Include_Deprecation)
{
deprecated void bar()
{
writeln("called bar");
}
}

void main()
{
version(Include_Warning)
foo();

version(Include_Deprecation)
bar();

writeln("done");
}

0 comments on commit e9dad94

Please sign in to comment.