Repository: bazelbuild/bazel
Issue: __STDC_FORMAT_MACROS warning when bootstrapping on macOS
Labels: type: bug
P2
category: misc > misc
area-EngProd
team-OSS

### Description of the problem / feature request:

When building Bazel "from scratch" on macOS, the following warning is emitted:

```
INFO: From Compiling src/tools/singlejar/output_jar.cc:
In file included from src/tools/singlejar/output_jar.cc:18:
In file included from ./src/tools/singlejar/output_jar.h:31:
In file included from ./src/tools/singlejar/combiners.h:24:
./src/tools/singlejar/transient_bytes.h:17:9: warning: '__STDC_FORMAT_MACROS' macro redefined [-Wmacro-redefined]
#define __STDC_FORMAT_MACROS 1
        ^
/Applications/Xcode-10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/inttypes.h:244:12: note: previous definition is here
#   define __STDC_FORMAT_MACROS
           ^
1 warning generated.
```

Is there an issue here? Or perhaps the `#define __STDC_FORMAT_MACROS 1` should be guarded with an `#ifndef  __STDC_FORMAT_MACROS`, just to avoid the warning? I'm no C expert, so I don't know if it's appropriate for this to be unconditionally defined here.

This does not break the build or affect functionality as far as I can tell; it's just a warning to clean up.

### Feature requests: what underlying problem are you trying to solve with this feature?

I'm trying to eliminate a warning during the Bazel build. It would be nice if Bazel built warning-free, so new users can be confident it built correctly.

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

This is on:
* macOS 10.13.6
* Xcode 10
* Oracle JDK 7, 8, 9, 10; OpenJDK 11 installed; at the system level

Also happens under Xcode 9.4.

Procedure to build:

```
wget https://github.com/bazelbuild/bazel/releases/download/0.19.0/bazel-0.19.0-dist.zip
unzip bazel-0.19.0-dist.zip
mv bazel-0.19.0-dist.zip ..
./compile.sh
```

The warning is emitted during the `./compile.sh` run.

### What operating system are you running Bazel on?

macOS 10.13.6

### What's the output of `bazel info release`?

```
$ bazel info release
zsh: command not found: bazel
```

This is expected; I do not have Bazel installed, and am building it "from scratch".

### What's the output of `git remote get-url origin ; git rev-parse master ; git rev-parse HEAD` ?

```
$ git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
```

This is expected; I'm building it from scratch from a release tarball.

###  Have you found anything relevant by searching the web?

* It looks like this was introduced in: https://github.com/bazelbuild/bazel/commit/070859a55d7b04f1afe7f46c5b714c8d267bde59
 * Which looks like it was to fix: https://github.com/bazelbuild/bazel/issues/3455
* Looks like the same thing is done in input_jar.h at: https://github.com/bazelbuild/bazel/blob/f8be43cebfe5d9ee80e838c883fb305969ece743/src/tools/singlejar/input_jar.h#L18

Most of the other Google results I found were instances of using `__STDC_FORMAT_MACROS` as a compiler command line option via `-D__STDC_FORMAT_MACROS`, instead of defining it in a header file, which makes me wonder if it's being used in quite the conventional manner here?

### Any other information, logs, or outputs that you want to share?

I am a Bazel newbie. I first encountered this while building Bazel to test for https://github.com/Homebrew/homebrew-core/pull/33484. Sorry if this is an obvious issue or inappropriate for this forum.


Issue comments:
Thanks for the detailed bug report! :) I agree that this should be cleaned up.
I think your suggestion to guard this #define with an #ifndef block is fine.

I'll fix this right now.

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/tools/singlejar/transient_bytes.h b/src/tools/singlejar/transient_bytes.h
index c7577aeee3294d..fb239620e39740 100644
--- a/src/tools/singlejar/transient_bytes.h
+++ b/src/tools/singlejar/transient_bytes.h
@@ -14,6 +14,7 @@
 #ifndef SRC_TOOLS_SINGLEJAR_TRANSIENT_BYTES_H_
 #define SRC_TOOLS_SINGLEJAR_TRANSIENT_BYTES_H_
 
+#undef __STDC_FORMAT_MACROS
 #define __STDC_FORMAT_MACROS 1
 
 #include <inttypes.h>


Test patch: