Skip to content

Commit 7e6536d

Browse files
authored
Merge pull request #34786 from artemcm/DependencyScanLibrary
Dependency Scanning Library
2 parents 267d776 + 4eae21c commit 7e6536d

34 files changed

+3185
-1077
lines changed
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
//===--- DependencyScan.h - C API for Swift Dependency Scanning ---*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This C API is primarily intended to serve as the Swift Driver's
14+
// dependency scanning facility (https://github.com/apple/swift-driver).
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
19+
#define SWIFT_C_DEPENDENCY_SCAN_H
20+
21+
#include "DependencyScanMacros.h"
22+
#include <stdbool.h>
23+
#include <stddef.h>
24+
#include <stdint.h>
25+
26+
/// The version constants for the SwiftDependencyScan C API.
27+
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
28+
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
29+
#define SWIFTSCAN_VERSION_MAJOR 0
30+
#define SWIFTSCAN_VERSION_MINOR 1
31+
32+
SWIFTSCAN_BEGIN_DECLS
33+
34+
//=== Public Scanner Data Types -------------------------------------------===//
35+
36+
/**
37+
* A character string used to pass around dependency scan result metadata.
38+
* Lifetime of the string is strictly tied to the object whose field it
39+
* represents. When the owning object is released, string memory is freed.
40+
*/
41+
typedef struct {
42+
const void *data;
43+
size_t length;
44+
} swiftscan_string_ref_t;
45+
46+
typedef struct {
47+
swiftscan_string_ref_t *strings;
48+
size_t count;
49+
} swiftscan_string_set_t;
50+
51+
typedef enum {
52+
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
53+
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
54+
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2,
55+
SWIFTSCAN_DEPENDENCY_INFO_CLANG = 3
56+
} swiftscan_dependency_info_kind_t;
57+
58+
/// Opaque container of the details specific to a given module dependency.
59+
typedef struct swiftscan_module_details_s *swiftscan_module_details_t;
60+
61+
/// Opaque container to a dependency info of a given module.
62+
typedef struct swiftscan_dependency_info_s *swiftscan_dependency_info_t;
63+
64+
/// Opaque container to an overall result of a dependency scan.
65+
typedef struct swiftscan_dependency_graph_s *swiftscan_dependency_graph_t;
66+
67+
/// Opaque container to contain the result of a dependency prescan.
68+
typedef struct swiftscan_import_set_s *swiftscan_import_set_t;
69+
70+
/// Full Dependency Graph (Result)
71+
typedef struct {
72+
swiftscan_dependency_info_t *modules;
73+
size_t count;
74+
} swiftscan_dependency_set_t;
75+
76+
//=== Batch Scan Input Specification --------------------------------------===//
77+
78+
/// Opaque container to a container of batch scan entry information.
79+
typedef struct swiftscan_batch_scan_entry_s *swiftscan_batch_scan_entry_t;
80+
81+
typedef struct {
82+
swiftscan_batch_scan_entry_t *modules;
83+
size_t count;
84+
} swiftscan_batch_scan_input_t;
85+
86+
typedef struct {
87+
swiftscan_dependency_graph_t *results;
88+
size_t count;
89+
} swiftscan_batch_scan_result_t;
90+
91+
//=== Scanner Invocation Specification ------------------------------------===//
92+
93+
/// Opaque container of all relevant context required to launch a dependency
94+
/// scan (command line arguments, working directory, etc.)
95+
typedef struct swiftscan_scan_invocation_s *swiftscan_scan_invocation_t;
96+
97+
//=== Dependency Result Functions -----------------------------------------===//
98+
99+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
100+
swiftscan_dependency_graph_get_main_module_name(
101+
swiftscan_dependency_graph_t result);
102+
103+
SWIFTSCAN_PUBLIC swiftscan_dependency_set_t *
104+
swiftscan_dependency_graph_get_dependencies(
105+
swiftscan_dependency_graph_t result);
106+
107+
//=== Dependency Module Info Functions ------------------------------------===//
108+
109+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
110+
swiftscan_module_info_get_module_name(swiftscan_dependency_info_t info);
111+
112+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
113+
swiftscan_module_info_get_module_path(swiftscan_dependency_info_t info);
114+
115+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
116+
swiftscan_module_info_get_source_files(swiftscan_dependency_info_t info);
117+
118+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
119+
swiftscan_module_info_get_direct_dependencies(swiftscan_dependency_info_t info);
120+
121+
SWIFTSCAN_PUBLIC swiftscan_module_details_t
122+
swiftscan_module_info_get_details(swiftscan_dependency_info_t info);
123+
124+
//=== Dependency Module Info Details Functions ----------------------------===//
125+
126+
SWIFTSCAN_PUBLIC swiftscan_dependency_info_kind_t
127+
swiftscan_module_detail_get_kind(swiftscan_module_details_t details);
128+
129+
//=== Swift Textual Module Details query APIs -----------------------------===//
130+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
131+
swiftscan_swift_textual_detail_get_module_interface_path(
132+
swiftscan_module_details_t details);
133+
134+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
135+
swiftscan_swift_textual_detail_get_compiled_module_candidates(
136+
swiftscan_module_details_t details);
137+
138+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
139+
swiftscan_swift_textual_detail_get_bridging_header_path(
140+
swiftscan_module_details_t details);
141+
142+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
143+
swiftscan_swift_textual_detail_get_bridging_source_files(
144+
swiftscan_module_details_t details);
145+
146+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
147+
swiftscan_swift_textual_detail_get_bridging_module_dependencies(
148+
swiftscan_module_details_t details);
149+
150+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
151+
swiftscan_swift_textual_detail_get_command_line(
152+
swiftscan_module_details_t details);
153+
154+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
155+
swiftscan_swift_textual_detail_get_extra_pcm_args(
156+
swiftscan_module_details_t details);
157+
158+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
159+
swiftscan_swift_textual_detail_get_context_hash(
160+
swiftscan_module_details_t details);
161+
162+
SWIFTSCAN_PUBLIC bool swiftscan_swift_textual_detail_get_is_framework(
163+
swiftscan_module_details_t details);
164+
165+
//=== Swift Binary Module Details query APIs ------------------------------===//
166+
167+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
168+
swiftscan_swift_binary_detail_get_compiled_module_path(
169+
swiftscan_module_details_t details);
170+
171+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
172+
swiftscan_swift_binary_detail_get_module_doc_path(
173+
swiftscan_module_details_t details);
174+
175+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
176+
swiftscan_swift_binary_detail_get_module_source_info_path(
177+
swiftscan_module_details_t details);
178+
179+
//=== Swift Placeholder Module Details query APIs -------------------------===//
180+
181+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
182+
swiftscan_swift_placeholder_detail_get_compiled_module_path(
183+
swiftscan_module_details_t details);
184+
185+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
186+
swiftscan_swift_placeholder_detail_get_module_doc_path(
187+
swiftscan_module_details_t details);
188+
189+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
190+
swiftscan_swift_placeholder_detail_get_module_source_info_path(
191+
swiftscan_module_details_t details);
192+
193+
//=== Clang Module Details query APIs -------------------------------------===//
194+
195+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
196+
swiftscan_clang_detail_get_module_map_path(swiftscan_module_details_t details);
197+
198+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
199+
swiftscan_clang_detail_get_context_hash(swiftscan_module_details_t details);
200+
201+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
202+
swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
203+
204+
//=== Batch Scan Input Functions ------------------------------------------===//
205+
206+
/// Create an \c swiftscan_batch_scan_input_t instance.
207+
/// The returned \c swiftscan_batch_scan_input_t is owned by the caller and must be disposed
208+
/// of using \c swiftscan_batch_scan_input_dispose .
209+
SWIFTSCAN_PUBLIC swiftscan_batch_scan_input_t *
210+
swiftscan_batch_scan_input_create();
211+
212+
SWIFTSCAN_PUBLIC void
213+
swiftscan_batch_scan_input_set_modules(swiftscan_batch_scan_input_t *input,
214+
int count,
215+
swiftscan_batch_scan_entry_t *modules);
216+
217+
//=== Batch Scan Entry Functions ------------------------------------------===//
218+
219+
/// Create an \c swiftscan_batch_scan_entry_t instance.
220+
/// The returned \c swiftscan_batch_scan_entry_t is owned by the caller and must be disposed
221+
/// of using \c swiftscan_batch_scan_entry_dispose .
222+
SWIFTSCAN_PUBLIC swiftscan_batch_scan_entry_t
223+
swiftscan_batch_scan_entry_create();
224+
225+
SWIFTSCAN_PUBLIC void
226+
swiftscan_batch_scan_entry_set_module_name(swiftscan_batch_scan_entry_t entry,
227+
const char *name);
228+
229+
SWIFTSCAN_PUBLIC void
230+
swiftscan_batch_scan_entry_set_arguments(swiftscan_batch_scan_entry_t entry,
231+
const char *arguments);
232+
233+
SWIFTSCAN_PUBLIC void
234+
swiftscan_batch_scan_entry_set_is_swift(swiftscan_batch_scan_entry_t entry,
235+
bool is_swift);
236+
237+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
238+
swiftscan_batch_scan_entry_get_module_name(swiftscan_batch_scan_entry_t entry);
239+
240+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
241+
swiftscan_batch_scan_entry_get_arguments(swiftscan_batch_scan_entry_t entry);
242+
243+
SWIFTSCAN_PUBLIC bool
244+
swiftscan_batch_scan_entry_get_is_swift(swiftscan_batch_scan_entry_t entry);
245+
246+
//=== Prescan Result Functions --------------------------------------------===//
247+
248+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
249+
swiftscan_import_set_get_imports(swiftscan_import_set_t result);
250+
251+
//=== Scanner Invocation Functions ----------------------------------------===//
252+
253+
/// Create an \c swiftscan_scan_invocation_t instance.
254+
/// The returned \c swiftscan_scan_invocation_t is owned by the caller and must be disposed
255+
/// of using \c swiftscan_scan_invocation_dispose .
256+
SWIFTSCAN_PUBLIC swiftscan_scan_invocation_t swiftscan_scan_invocation_create();
257+
258+
SWIFTSCAN_PUBLIC void swiftscan_scan_invocation_set_working_directory(
259+
swiftscan_scan_invocation_t invocation, const char *working_directory);
260+
261+
SWIFTSCAN_PUBLIC void
262+
swiftscan_scan_invocation_set_argv(swiftscan_scan_invocation_t invocation,
263+
int argc, const char **argv);
264+
265+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
266+
swiftscan_scan_invocation_get_working_directory(
267+
swiftscan_scan_invocation_t invocation);
268+
269+
SWIFTSCAN_PUBLIC int
270+
swiftscan_scan_invocation_get_argc(swiftscan_scan_invocation_t invocation);
271+
272+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
273+
swiftscan_scan_invocation_get_argv(swiftscan_scan_invocation_t invocation);
274+
275+
//=== Cleanup Functions ---------------------------------------------------===//
276+
277+
SWIFTSCAN_PUBLIC void
278+
swiftscan_dependency_graph_dispose(swiftscan_dependency_graph_t result);
279+
280+
SWIFTSCAN_PUBLIC void
281+
swiftscan_import_set_dispose(swiftscan_import_set_t result);
282+
283+
SWIFTSCAN_PUBLIC void
284+
swiftscan_batch_scan_entry_dispose(swiftscan_batch_scan_entry_t entry);
285+
286+
SWIFTSCAN_PUBLIC void
287+
swiftscan_batch_scan_input_dispose(swiftscan_batch_scan_input_t *input);
288+
289+
SWIFTSCAN_PUBLIC void
290+
swiftscan_batch_scan_result_dispose(swiftscan_batch_scan_result_t *result);
291+
292+
SWIFTSCAN_PUBLIC void
293+
swiftscan_scan_invocation_dispose(swiftscan_scan_invocation_t invocation);
294+
295+
//=== Scanner Functions ---------------------------------------------------===//
296+
297+
/// Container of the configuration state and shared cache for dependency
298+
/// scanning.
299+
typedef void *swiftscan_scanner_t;
300+
301+
/// Create an \c swiftscan_scanner_t instance.
302+
/// The returned \c swiftscan_scanner_t is owned by the caller and must be disposed
303+
/// of using \c swiftscan_scanner_dispose .
304+
SWIFTSCAN_PUBLIC swiftscan_scanner_t swiftscan_scanner_create(void);
305+
SWIFTSCAN_PUBLIC void swiftscan_scanner_dispose(swiftscan_scanner_t);
306+
307+
/// Invoke a dependency scan using arguments specified in the \c
308+
/// swiftscan_scan_invocation_t argument. The returned \c
309+
/// swiftscan_dependency_graph_t is owned by the caller and must be disposed of
310+
/// using \c swiftscan_dependency_graph_dispose .
311+
SWIFTSCAN_PUBLIC swiftscan_dependency_graph_t swiftscan_dependency_graph_create(
312+
swiftscan_scanner_t scanner, swiftscan_scan_invocation_t invocation);
313+
314+
/// Invoke the scan for an input batch of modules specified in the
315+
/// \c swiftscan_batch_scan_input_t argument. The returned
316+
/// \c swiftscan_batch_scan_result_t is owned by the caller and must be disposed
317+
/// of using \c swiftscan_batch_scan_result_dispose .
318+
SWIFTSCAN_PUBLIC swiftscan_batch_scan_result_t *
319+
swiftscan_batch_scan_result_create(swiftscan_scanner_t scanner,
320+
swiftscan_batch_scan_input_t *batch_input,
321+
swiftscan_scan_invocation_t invocation);
322+
323+
/// Invoke the import prescan using arguments specified in the \c
324+
/// swiftscan_scan_invocation_t argument. The returned \c swiftscan_import_set_t
325+
/// is owned by the caller and must be disposed of using \c
326+
/// swiftscan_import_set_dispose .
327+
SWIFTSCAN_PUBLIC swiftscan_import_set_t swiftscan_import_set_create(
328+
swiftscan_scanner_t scanner, swiftscan_scan_invocation_t invocation);
329+
330+
SWIFTSCAN_END_DECLS
331+
332+
#endif // SWIFT_C_DEPENDENCY_SCAN_H
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===-- DependencyScanMacros.h - Swift Dependency Scanning Macros -*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifdef __cplusplus
14+
# define SWIFTSCAN_BEGIN_DECLS extern "C" {
15+
# define SWIFTSCAN_END_DECLS }
16+
#else
17+
# define SWIFTSCAN_BEGIN_DECLS
18+
# define SWIFTSCAN_END_DECLS
19+
#endif
20+
21+
#ifndef SWIFTSCAN_PUBLIC
22+
# ifdef _WIN32
23+
# ifdef libSwiftScan_EXPORTS
24+
# define SWIFTSCAN_PUBLIC __declspec(dllexport)
25+
# else
26+
# define SWIFTSCAN_PUBLIC __declspec(dllimport)
27+
# endif
28+
# else
29+
# define SWIFTSCAN_PUBLIC
30+
# endif
31+
#endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module _InternalSwiftScan {
2+
header "DependencyScan.h"
3+
link "_InternalSwiftScan"
4+
}

0 commit comments

Comments
 (0)