diff --git a/changelog/deprecations-warnings-errors.dd b/changelog/deprecations-warnings-errors.dd new file mode 100644 index 000000000..ddbb020d7 --- /dev/null +++ b/changelog/deprecations-warnings-errors.dd @@ -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. diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 78fd9d4b5..bf62251bc 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -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"]), @@ -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]); } diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 0d34446ec..48e47a25c 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -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"]), @@ -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]); } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 3cb90e5b2..f6e8ba31e 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -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"]), @@ -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]); } diff --git a/test/.gitignore b/test/.gitignore index cfe8d612f..aadec6e9f 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -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 diff --git a/test/warnings.sh b/test/warnings.sh new file mode 100755 index 000000000..88b718f59 --- /dev/null +++ b/test/warnings.sh @@ -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 diff --git a/test/warnings/.no_build b/test/warnings/.no_build new file mode 100644 index 000000000..e69de29bb diff --git a/test/warnings/.no_run b/test/warnings/.no_run new file mode 100644 index 000000000..e69de29bb diff --git a/test/warnings/.no_test b/test/warnings/.no_test new file mode 100644 index 000000000..e69de29bb diff --git a/test/warnings/dub.sdl b/test/warnings/dub.sdl new file mode 100644 index 000000000..148ad0023 --- /dev/null +++ b/test/warnings/dub.sdl @@ -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" +} diff --git a/test/warnings/source/app.d b/test/warnings/source/app.d new file mode 100644 index 000000000..e2c8e4751 --- /dev/null +++ b/test/warnings/source/app.d @@ -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"); +}