toolchain: create unique names for clang crash diagnoses

This patch add board and date information when naming the artifact of
clang crash diagnoses in builders, therefore not overwriting the other
artifacts with the same name when uploaded to a centralized GS bucket.

BUG=chromium:1056904
TEST=Standalone test and unit test passed.

Change-Id: I0f06f2a01009dc185e8c85ae11966b86ad39db4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2305595
Reviewed-by: Tiancong Wang <tcwang@google.com>
Tested-by: Jian Cai <jiancai@google.com>
Commit-Queue: George Burgess <gbiv@chromium.org>
diff --git a/lib/toolchain_util.py b/lib/toolchain_util.py
index b76d1a8..9a57f10 100644
--- a/lib/toolchain_util.py
+++ b/lib/toolchain_util.py
@@ -2396,7 +2396,10 @@
         logging.info('No clang crashes found, skip bundle artifact')
         return []
 
-      output = os.path.join(self.output_dir, 'clang_crash_diagnoses.tar.xz')
+      now = datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d')
+      output = os.path.join(
+          self.output_dir,
+          f'{self.build_target}.{now}.clang_crash_diagnoses.tar.xz')
       cros_build_lib.CreateTarball(output, tempdir)
       return [output]
 
diff --git a/lib/toolchain_util_unittest.py b/lib/toolchain_util_unittest.py
index 0512262..b7dfddf 100644
--- a/lib/toolchain_util_unittest.py
+++ b/lib/toolchain_util_unittest.py
@@ -615,9 +615,8 @@
       for l in ['log1.json', 'log2.json', 'log3.notjson']:
         osutils.Touch(os.path.join(d, l))
     tarball = self.obj.Bundle()
-    artifact = os.path.join(
-        self.outdir,
-        '%s.DATE.fatal_clang_warnings.tar.xz' % self.board)
+    artifact = os.path.join(self.outdir,
+                            '%s.DATE.fatal_clang_warnings.tar.xz' % self.board)
     self.assertEqual(tarball, [artifact])
 
     # Make sure the duplicate logs are renamed and all logs are captured.
@@ -710,18 +709,19 @@
     self.SetUpBundle('ClangCrashDiagnoses')
     src_dir = '/tmp/clang_crash_diagnostics'
     check_dirs = [
-        self.chroot.full_path(x) for x in [
-            src_dir,
-            '/build/%s%s' % (self.board, src_dir)
-        ]
+        self.chroot.full_path(x)
+        for x in [src_dir, '/build/%s%s' % (self.board, src_dir)]
     ]
     for d in check_dirs:
       osutils.SafeMakedirs(d)
       for l in ['1.cpp', '1.sh', '2.cc', '2.sh']:
         osutils.Touch(os.path.join(d, l))
     tarball = self.obj.Bundle()
-    self.assertEqual(
-        tarball, [os.path.join(self.outdir, 'clang_crash_diagnoses.tar.xz')])
+    self.assertEqual(tarball, [
+        os.path.join(self.outdir,
+                     '%s.DATE.clang_crash_diagnoses.tar.xz' % self.board)
+    ])
+
 
 class ReleaseChromeAFDOProfileTest(PrepareBundleTest):
   """Test functions related to create a release CrOS profile.