Repository: SCons/scons

Issue:
CompilationDatabase tool emits a field called `target` which should be called `output`
**Describe the bug**
With the new integrated SCons compilation database support, there is a field called `target` in the resulting file:

```
"target": "build/cached/third_party/s2/base/int128.dyn.o"
```

Per the compilation database documentation, it seems this field should instead be called `output`:

https://clang.llvm.org/docs/JSONCompilationDatabase.html#format


**Required information**
* Link to SCons Users thread discussing your issue.
Discussed directly with @bdbaddog 

* Version of SCons
master

* Version of Python
3.7

* Which python distribution if applicable (python.org, cygwin, anaconda, macports, brew,etc)
* How you installed SCons
Using it from source

* What Platform are you on? (Linux/Windows and which version)
macOS, but it shouldn't matter.



Discussion:
I asked that question in the review of the PR - couldn't tell if it was important; `output` is listed a optional anyway.
@mwichmann - Yes, definitely optional, which is why the MongoDB version didn't have it. I'm not even sure it was part of the spec when we wrote the tool. But if it is going to be emitted, I think it should be under the correct field name.
@ivankravets - Thoughts on naming of target field. I think this came from PlatformIO's code?
@bdbaddog No, we don't use `output` field. See

- https://github.com/platformio/platformio-core/blob/develop/platformio/builder/tools/compilation_db.py#L138
- https://github.com/mongodb/mongo/blob/master/site_scons/site_tools/compilation_db.py#L128

Resolving patch:
diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py
--- a/SCons/Tool/compilation_db.py
+++ b/SCons/Tool/compilation_db.py
@@ -84,7 +84,7 @@ def emit_compilation_db_entry(target, source, env):
         entry = env.__COMPILATIONDB_Entry(
             target=dbtarget,
             source=[],
-            __COMPILATIONDB_UTARGET=target,
+            __COMPILATIONDB_UOUTPUT=target,
             __COMPILATIONDB_USOURCE=source,
             __COMPILATIONDB_UACTION=user_action,
             __COMPILATIONDB_ENV=env,
@@ -116,7 +116,7 @@ def compilation_db_entry_action(target, source, env, **kw):
     """
 
     command = env["__COMPILATIONDB_UACTION"].strfunction(
-        target=env["__COMPILATIONDB_UTARGET"],
+        target=env["__COMPILATIONDB_UOUTPUT"],
         source=env["__COMPILATIONDB_USOURCE"],
         env=env["__COMPILATIONDB_ENV"],
     )
@@ -125,7 +125,7 @@ def compilation_db_entry_action(target, source, env, **kw):
         "directory": env.Dir("#").abspath,
         "command": command,
         "file": env["__COMPILATIONDB_USOURCE"][0],
-        "target": env['__COMPILATIONDB_UTARGET'][0]
+        "output": env['__COMPILATIONDB_UOUTPUT'][0]
     }
 
     target[0].write(entry)
@@ -139,25 +139,25 @@ def write_compilation_db(target, source, env):
     for s in __COMPILATION_DB_ENTRIES:
         entry = s.read()
         source_file = entry['file']
-        target_file = entry['target']
+        output_file = entry['output']
 
         if use_abspath:
             source_file = source_file.abspath
-            target_file = target_file.abspath
+            output_file = output_file.abspath
         else:
             source_file = source_file.path
-            target_file = target_file.path
+            output_file = output_file.path
 
         path_entry = {'directory': entry['directory'],
                       'command': entry['command'],
                       'file': source_file,
-                      'target': target_file}
+                      'output': output_file}
 
         entries.append(path_entry)
 
-    with open(target[0].path, "w") as target_file:
+    with open(target[0].path, "w") as output_file:
         json.dump(
-            entries, target_file, sort_keys=True, indent=4, separators=(",", ": ")
+            entries, output_file, sort_keys=True, indent=4, separators=(",", ": ")
         )
 
 


Test patch:
diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py
--- a/test/CompilationDatabase/basic.py
+++ b/test/CompilationDatabase/basic.py
@@ -63,7 +63,7 @@
         "command": "%s mygcc.py cc -o test_main.o -c test_main.c",
         "directory": "%s",
         "file": "test_main.c",
-        "target": "test_main.o"
+        "output": "test_main.o"
     }
 ]""" % (sys.executable, test.workdir)
 
@@ -77,7 +77,7 @@
         "command": "%s mygcc.py cc -o test_main.o -c test_main.c",
         "directory": "%s",
         "file": "%s/test_main.c",
-        "target": "%s/test_main.o"
+        "output": "%s/test_main.o"
     }
 ]""" % (sys.executable, test.workdir, test.workdir, test.workdir)