[PATCH] D121438: [llvm-mt] Add support /notify_update

Alex Brachet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 10 19:48:09 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe970d2823cf2: [llvm-mt] Add support /notify_update (authored by abrachet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121438/new/

https://reviews.llvm.org/D121438

Files:
  llvm/test/tools/llvm-mt/notify_update.test
  llvm/tools/llvm-mt/Opts.td
  llvm/tools/llvm-mt/llvm-mt.cpp


Index: llvm/tools/llvm-mt/llvm-mt.cpp
===================================================================
--- llvm/tools/llvm-mt/llvm-mt.cpp
+++ llvm/tools/llvm-mt/llvm-mt.cpp
@@ -141,6 +141,29 @@
   std::unique_ptr<MemoryBuffer> OutputBuffer = Merger.getMergedManifest();
   if (!OutputBuffer)
     reportError("empty manifest not written");
+
+  int ExitCode = 0;
+  if (InputArgs.hasArg(OPT_notify_update)) {
+    ErrorOr<std::unique_ptr<MemoryBuffer>> OutBuffOrErr =
+        MemoryBuffer::getFile(OutputFile);
+    // Assume if we couldn't open the output file then it doesn't exist meaning
+    // there was a change.
+    bool Same = false;
+    if (OutBuffOrErr) {
+      const std::unique_ptr<MemoryBuffer> &FileBuffer = *OutBuffOrErr;
+      Same = std::equal(OutputBuffer->getBufferStart(),
+                        OutputBuffer->getBufferEnd(),
+                        FileBuffer->getBufferStart());
+    }
+    if (!Same) {
+#if LLVM_ON_UNIX
+      ExitCode = 0xbb;
+#elif defined(_WIN32)
+      ExitCode = 0x41020001;
+#endif
+    }
+  }
+
   Expected<std::unique_ptr<FileOutputBuffer>> FileOrErr =
       FileOutputBuffer::create(OutputFile, OutputBuffer->getBufferSize());
   if (!FileOrErr)
@@ -149,5 +172,5 @@
   std::copy(OutputBuffer->getBufferStart(), OutputBuffer->getBufferEnd(),
             FileBuffer->getBufferStart());
   error(FileBuffer->commit());
-  return 0;
+  return ExitCode;
 }
Index: llvm/tools/llvm-mt/Opts.td
===================================================================
--- llvm/tools/llvm-mt/Opts.td
+++ llvm/tools/llvm-mt/Opts.td
@@ -23,7 +23,7 @@
 def canonicalize : Flag<["/", "-"], "canonicalize:">, HelpText<"Not supported">, Group<unsupported>;
 def check_for_duplicates : Flag<["/", "-"], "check_for_duplicates:">, HelpText<"Not supported">, Group<unsupported>;
 def make_cdfs : Flag<["/", "-"], "makecdfs:">, HelpText<"Not supported">, Group<unsupported>;
-def notify_update : Flag<["/", "-"], "notify_update">, HelpText<"Not supported">, Group<unsupported>;
+def notify_update : Flag<["/", "-"], "notify_update">, HelpText<"Exit with a special exit code if the output file has changed">;
 def verbose : Flag<["/", "-"], "verbose">, HelpText<"Not supported">, Group<unsupported>;
 def help : Flag<["/", "-"], "?">;
 def help_long : Flag<["/", "-"], "help">, Alias<help>;
Index: llvm/test/tools/llvm-mt/notify_update.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-mt/notify_update.test
@@ -0,0 +1,16 @@
+REQUIRES: libxml2
+UNSUPPORTED: system-windows
+
+Exits normally without /notify_update
+RUN: llvm-mt /manifest %p/Inputs/test_manifest.manifest /out:%t.manifest
+RUN: rm -f %t.manifest
+
+We can't check exit code so all we can do is see if not considered it as a failure
+
+File didn't exist previously so it's an update
+RUN: not llvm-mt /manifest %p/Inputs/test_manifest.manifest /out:%t.manifest /notify_update
+RUN: llvm-mt /manifest %p/Inputs/test_manifest.manifest /out:%t.manifest /notify_update
+
+New manifest, so it's an update
+RUN: not llvm-mt /manifest %p/Inputs/additional.manifest /out:%t.manifest /notify_update
+RUN: llvm-mt /manifest %p/Inputs/additional.manifest /out:%t.manifest /notify_update


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121438.414566.patch
Type: text/x-patch
Size: 3240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220311/227b9034/attachment-0001.bin>


More information about the llvm-commits mailing list