]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Allow dumping stdin by giving - as path (#879)
authorAnders Björklund <anders.f.bjorklund@gmail.com>
Sat, 3 Jul 2021 18:10:36 +0000 (20:10 +0200)
committerGitHub <noreply@github.com>
Sat, 3 Jul 2021 18:10:36 +0000 (20:10 +0200)
Similar to other commands, such as tar.

doc/MANUAL.adoc
src/Manifest.cpp
src/Result.cpp

index 8e503e86e830d2c829c74e1b0c5902d120a1ceaa..326a1cd0dc33d66b3b6581525c4fc325622411de 100644 (file)
@@ -182,11 +182,13 @@ compiler's documentation.
 
     Dump manifest file at _PATH_ in text format to standard output. This is
     only useful when debugging ccache and its behavior.
+    A path of `-` means to read from standard input.
 
 *`--dump-result`* _PATH_::
 
     Dump result file at _PATH_ in text format to standard output. This is only
     useful when debugging ccache and its behavior.
+    A path of `-` means to read from standard input.
 
 *`--extract-result`* _PATH_::
 
index 0dce17b429fdd74936cd1da9576fc422c0d73673..d0eac687cf08e16462293b2d0d841628783710b7 100644 (file)
@@ -294,12 +294,19 @@ struct FileStats
 std::unique_ptr<ManifestData>
 read_manifest(const std::string& path, FILE* dump_stream = nullptr)
 {
-  File file(path, "rb");
-  if (!file) {
-    return {};
+  FILE* file_stream;
+  File file;
+  if (path == "-") {
+    file_stream = stdin;
+  } else {
+    file = File(path, "rb");
+    if (!file) {
+      return {};
+    }
+    file_stream = file.get();
   }
 
-  CacheEntryReader reader(file.get(), Manifest::k_magic, Manifest::k_version);
+  CacheEntryReader reader(file_stream, Manifest::k_magic, Manifest::k_version);
 
   if (dump_stream) {
     reader.dump_header(dump_stream);
index 4c0cdb83f922b194f49c866dbcaa3507015d38b3..86ba5a24a70a3a45b1909cb9bb75217b7cfeb924 100644 (file)
@@ -228,13 +228,20 @@ Result::Reader::read(Consumer& consumer)
 bool
 Reader::read_result(Consumer& consumer)
 {
-  File file(m_result_path, "rb");
-  if (!file) {
-    // Cache miss.
-    return false;
+  FILE* file_stream;
+  File file;
+  if (m_result_path == "-") {
+    file_stream = stdin;
+  } else {
+    file = File(m_result_path, "rb");
+    if (!file) {
+      // Cache miss.
+      return false;
+    }
+    file_stream = file.get();
   }
 
-  CacheEntryReader cache_entry_reader(file.get(), k_magic, k_version);
+  CacheEntryReader cache_entry_reader(file_stream, k_magic, k_version);
 
   consumer.on_header(cache_entry_reader);