1/*==-- clang-c/BuildSystem.h - Utilities for use by build systems -*- C -*-===*\
2|* *|
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides various utilities for use by build systems. *|
11|* *|
12\*===----------------------------------------------------------------------===*/
13
14#ifndef LLVM_CLANG_C_BUILDSYSTEM_H
15#define LLVM_CLANG_C_BUILDSYSTEM_H
16
17#include "clang-c/CXErrorCode.h"
18#include "clang-c/CXString.h"
19#include "clang-c/ExternC.h"
20#include "clang-c/Platform.h"
21#include <time.h>
22
23LLVM_CLANG_C_EXTERN_C_BEGIN
24
25/**
26 * \defgroup BUILD_SYSTEM Build system utilities
27 * @{
28 */
29
30/**
31 * Return the timestamp for use with Clang's
32 * \c -fbuild-session-timestamp= option.
33 */
34CINDEX_LINKAGE unsigned long long clang_getBuildSessionTimestamp(void);
35
36/**
37 * Object encapsulating information about overlaying virtual
38 * file/directories over the real file system.
39 */
40typedef struct CXVirtualFileOverlayImpl *CXVirtualFileOverlay;
41
42/**
43 * Create a \c CXVirtualFileOverlay object.
44 * Must be disposed with \c clang_VirtualFileOverlay_dispose().
45 *
46 * \param options is reserved, always pass 0.
47 */
48CINDEX_LINKAGE CXVirtualFileOverlay
49clang_VirtualFileOverlay_create(unsigned options);
50
51/**
52 * Map an absolute virtual file path to an absolute real one.
53 * The virtual path must be canonicalized (not contain "."/"..").
54 * \returns 0 for success, non-zero to indicate an error.
55 */
56CINDEX_LINKAGE enum CXErrorCode
57clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay,
58 const char *virtualPath,
59 const char *realPath);
60
61/**
62 * Set the case sensitivity for the \c CXVirtualFileOverlay object.
63 * The \c CXVirtualFileOverlay object is case-sensitive by default, this
64 * option can be used to override the default.
65 * \returns 0 for success, non-zero to indicate an error.
66 */
67CINDEX_LINKAGE enum CXErrorCode
68clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay,
69 int caseSensitive);
70
71/**
72 * Write out the \c CXVirtualFileOverlay object to a char buffer.
73 *
74 * \param options is reserved, always pass 0.
75 * \param out_buffer_ptr pointer to receive the buffer pointer, which should be
76 * disposed using \c clang_free().
77 * \param out_buffer_size pointer to receive the buffer size.
78 * \returns 0 for success, non-zero to indicate an error.
79 */
80CINDEX_LINKAGE enum CXErrorCode
81clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options,
82 char **out_buffer_ptr,
83 unsigned *out_buffer_size);
84
85/**
86 * free memory allocated by libclang, such as the buffer returned by
87 * \c CXVirtualFileOverlay() or \c clang_ModuleMapDescriptor_writeToBuffer().
88 *
89 * \param buffer memory pointer to free.
90 */
91CINDEX_LINKAGE void clang_free(void *buffer);
92
93/**
94 * Dispose a \c CXVirtualFileOverlay object.
95 */
96CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay);
97
98/**
99 * Object encapsulating information about a module.modulemap file.
100 */
101typedef struct CXModuleMapDescriptorImpl *CXModuleMapDescriptor;
102
103/**
104 * Create a \c CXModuleMapDescriptor object.
105 * Must be disposed with \c clang_ModuleMapDescriptor_dispose().
106 *
107 * \param options is reserved, always pass 0.
108 */
109CINDEX_LINKAGE CXModuleMapDescriptor
110clang_ModuleMapDescriptor_create(unsigned options);
111
112/**
113 * Sets the framework module name that the module.modulemap describes.
114 * \returns 0 for success, non-zero to indicate an error.
115 */
116CINDEX_LINKAGE enum CXErrorCode
117clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor,
118 const char *name);
119
120/**
121 * Sets the umbrella header name that the module.modulemap describes.
122 * \returns 0 for success, non-zero to indicate an error.
123 */
124CINDEX_LINKAGE enum CXErrorCode
125clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor,
126 const char *name);
127
128/**
129 * Write out the \c CXModuleMapDescriptor object to a char buffer.
130 *
131 * \param options is reserved, always pass 0.
132 * \param out_buffer_ptr pointer to receive the buffer pointer, which should be
133 * disposed using \c clang_free().
134 * \param out_buffer_size pointer to receive the buffer size.
135 * \returns 0 for success, non-zero to indicate an error.
136 */
137CINDEX_LINKAGE enum CXErrorCode
138clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, unsigned options,
139 char **out_buffer_ptr,
140 unsigned *out_buffer_size);
141
142/**
143 * Dispose a \c CXModuleMapDescriptor object.
144 */
145CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor);
146
147/**
148 * Prune module files in the module cache directory that haven't been accessed
149 * in a long time.
150 *
151 * \param Path the path to the module cache directory.
152 *
153 * \param PruneInterval the minimum time in seconds between two prune
154 * operations. If the timestamp file is newer than this, pruning is skipped.
155 *
156 * \param PruneAfter the time in seconds after which unused module files are
157 * removed.
158 *
159 */
160CINDEX_LINKAGE void clang_ModuleCache_prune(const char *Path,
161 time_t PruneInterval,
162 time_t PruneAfter);
163
164/**
165 * @}
166 */
167
168LLVM_CLANG_C_EXTERN_C_END
169
170#endif /* CLANG_C_BUILD_SYSTEM_H */
171
172