Invert --cfg debug to --cfg ndebug

Many people will be very confused that their debug! statements aren't working
when they first use rust only to learn that they should have been building with
`--cfg debug` the entire time. This inverts the meaning of the flag to instead
of enabling debug statements, now it disables debug statements.

This way the default behavior is a bit more reasonable, and requires less
end-user configuration. Furthermore, this turns on debug by default when
building the rustc compiler.
This commit is contained in:
Alex Crichton 2013-09-17 21:02:11 -07:00
parent 89cc8529cc
commit 833a64d76e
8 changed files with 12 additions and 12 deletions

View File

@ -102,9 +102,9 @@ endif
ifdef CFG_ENABLE_DEBUG
$(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
CFG_RUSTC_FLAGS += --cfg debug
CFG_GCCISH_CFLAGS += -DRUST_DEBUG
else
CFG_RUSTC_FLAGS += --cfg ndebug
CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
endif

View File

@ -10,8 +10,8 @@ Version 0.8 (October 2013)
* Many trait inheritance bugs fixed.
* Owned and borrowed trait objects work more reliably.
* `copy` is no longer a keyword. It has been replaced by the `Clone` trait.
* rustc no longer emits code for the `debug!` macro unless it is passed
`--cfg debug`
* rustc can omit emission of code for the `debug!` macro if it is passed
`--cfg ndebug`
* mod.rs is now "blessed". When loading `mod foo;`, rustc will now look
for foo.rs, then foo/mod.rs, and will generate an error when both are
present.

2
configure vendored
View File

@ -373,7 +373,7 @@ opt optimize-cxx 1 "build optimized C++ code"
opt optimize-llvm 1 "build optimized LLVM"
opt optimize-tests 1 "build tests with optimizations"
opt llvm-assertions 1 "build LLVM with assertions"
opt debug 0 "build with extra debug fun"
opt debug 1 "build with extra debug fun"
opt ratchet-bench 0 "ratchet benchmarks"
opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
opt manage-submodules 1 "let the build manage the git submodules"

View File

@ -3428,8 +3428,8 @@ sign (`=`) followed by the log level, from 1 to 4, inclusive. Level 1
is the error level, 2 is warning, 3 info, and 4 debug. You can also
use the symbolic constants `error`, `warn`, `info`, and `debug`. Any
logs less than or equal to the specified level will be output. If not
specified then log level 4 is assumed. However, debug messages are
only available if `--cfg=debug` is passed to `rustc`.
specified then log level 4 is assumed. Debug messages can be omitted
by passing `--cfg ndebug` to `rustc`.
As an example, to see all the logs generated by the compiler, you would set
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `link`

View File

@ -575,7 +575,7 @@ TEST_SREQ$(1)_T_$(2)_H_$(3) = \
# The tests select when to use debug configuration on their own;
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
CTEST_RUSTC_FLAGS := $$(subst --cfg debug,,$$(CFG_RUSTC_FLAGS))
CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
# The tests can not be optimized while the rest of the compiler is optimized, so
# filter out the optimization (if any) from rustc and then figure out if we need

View File

@ -715,7 +715,7 @@ pub fn std_macros() -> @str {
macro_rules! warn ( ($($arg:tt)*) => (log!(2u32, $($arg)*)) )
macro_rules! info ( ($($arg:tt)*) => (log!(3u32, $($arg)*)) )
macro_rules! debug( ($($arg:tt)*) => (
if cfg!(debug) { log!(4u32, $($arg)*) }
if cfg!(not(ndebug)) { log!(4u32, $($arg)*) }
))
macro_rules! log2(
@ -730,7 +730,7 @@ pub fn std_macros() -> @str {
macro_rules! warn2 ( ($($arg:tt)*) => (log2!(2u32, $($arg)*)) )
macro_rules! info2 ( ($($arg:tt)*) => (log2!(3u32, $($arg)*)) )
macro_rules! debug2( ($($arg:tt)*) => (
if cfg!(debug) { log2!(4u32, $($arg)*) }
if cfg!(not(ndebug)) { log2!(4u32, $($arg)*) }
))
macro_rules! fail(

View File

@ -9,9 +9,10 @@
// except according to those terms.
// xfail-fast exec-env directive doesn't work for check-fast
// compile-flags: --cfg ndebug
// exec-env:RUST_LOG=conditional-debug-macro-off=4
fn main() {
// only fails if debug! evaluates its argument.
debug!({ if true { fail!() } });
}
}

View File

@ -9,7 +9,6 @@
// except according to those terms.
// xfail-fast compile-flags directive doesn't work for check-fast
// compile-flags: --cfg debug
// exec-env:RUST_LOG=conditional-debug-macro-on=4
fn main() {
@ -18,4 +17,4 @@ fn main() {
debug!({ if true { return; } });
fail!();
}
}