1 //===- tools/dsymutil/Reproducer.h ------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
10 #define LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
11 
12 #include "llvm/Support/Error.h"
13 #include "llvm/Support/FileCollector.h"
14 #include "llvm/Support/VirtualFileSystem.h"
15 
16 namespace llvm {
17 namespace dsymutil {
18 
19 /// The reproducer mode.
20 enum class ReproducerMode {
21   Generate,
22   Use,
23   Off,
24 };
25 
26 /// The reproducer class manages the sate related to reproducers in dsymutil.
27 /// Instances should be created with Reproducer::createReproducer. An instance
28 /// of this class is returned when reproducers are off. The VFS returned by
29 /// this instance is the real file system.
30 class Reproducer {
31 public:
32   Reproducer();
33   virtual ~Reproducer();
34 
getVFS()35   IntrusiveRefCntPtr<vfs::FileSystem> getVFS() const { return VFS; }
36 
37   /// Create a Reproducer instance based on the given mode.
38   static llvm::Expected<std::unique_ptr<Reproducer>>
39   createReproducer(ReproducerMode Mode, StringRef Root);
40 
41 protected:
42   IntrusiveRefCntPtr<vfs::FileSystem> VFS;
43 };
44 
45 /// Reproducer instance used to generate a new reproducer. The VFS returned by
46 /// this instance is a FileCollectorFileSystem that tracks every file used by
47 /// dsymutil.
48 class ReproducerGenerate : public Reproducer {
49 public:
50   ReproducerGenerate(std::error_code &EC);
51   ~ReproducerGenerate() override;
52 
53 private:
54   /// The path to the reproducer.
55   std::string Root;
56 
57   /// The FileCollector used by the FileCollectorFileSystem.
58   std::shared_ptr<FileCollector> FC;
59 };
60 
61 /// Reproducer instance used to use an existing reproducer. The VFS returned by
62 /// this instance is a RedirectingFileSystem that remaps paths to their
63 /// counterpart in the reproducer.
64 class ReproducerUse : public Reproducer {
65 public:
66   ReproducerUse(StringRef Root, std::error_code &EC);
67   ~ReproducerUse() override;
68 
69 private:
70   /// The path to the reproducer.
71   std::string Root;
72 };
73 
74 } // end namespace dsymutil
75 } // end namespace llvm
76 
77 #endif // LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
78