Skip to content

Commit 2ad9600

Browse files
committed
[Dependency Scanning] Use an opaque type for dependency module details with API query functions for individual fields
1 parent 75b8a0e commit 2ad9600

File tree

11 files changed

+543
-306
lines changed

11 files changed

+543
-306
lines changed

include/swift-c/DependencyScan/DSString.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ DEPSCAN_BEGIN_DECLS
2020
/**
2121
* A character string used to pass around dependency scan result metadata.
2222
* A slightly-reduced variation of clang's CXString
23-
* Use \c depscan_get_C_string() to retrieve the string data and, once finished
24-
* with the string data, call \c depscan_dispose_string() to free the string.
23+
* Use \c ds_get_C_string() to retrieve the string data and, once finished
24+
* with the string data, call \c ds_dispose_string() to free the string.
2525
*/
2626
typedef struct {
2727
const void *data;
@@ -35,15 +35,15 @@ typedef struct {
3535

3636
//=== Public API ----------------------------------------------------------===//
3737
/// Retrieve the character data associated with the given string.
38-
DEPSCAN_PUBLIC const char *depscan_get_C_string(ds_string_t string);
38+
DEPSCAN_PUBLIC const char *ds_get_C_string(ds_string_t string);
3939

4040

4141
/// Free the given string.
42-
DEPSCAN_PUBLIC void depscan_string_dispose(ds_string_t string);
42+
DEPSCAN_PUBLIC void ds_string_dispose(ds_string_t string);
4343

4444

4545
/// Free the given string set.
46-
DEPSCAN_PUBLIC void depscan_string_set_dispose(ds_string_set_t *set);
46+
DEPSCAN_PUBLIC void ds_string_set_dispose(ds_string_set_t *set);
4747

4848
DEPSCAN_END_DECLS
4949

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 102 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#ifndef SWIFT_C_DEPENDENCY_SCAN_H
1919
#define SWIFT_C_DEPENDENCY_SCAN_H
2020

21-
#include "DependencyScanMacros.h"
2221
#include "DSString.h"
22+
#include "DependencyScanMacros.h"
2323
#include <stdbool.h>
2424
#include <stddef.h>
2525
#include <stdint.h>
@@ -32,94 +32,17 @@
3232

3333
DEPSCAN_BEGIN_DECLS
3434

35-
//=== Scanner Data Types --------------------------------------------------===//
35+
//=== Public Scanner Data Types -------------------------------------------===//
3636

3737
typedef enum {
3838
DEPSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
3939
DEPSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
4040
DEPSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2,
4141
DEPSCAN_DEPENDENCY_INFO_CLANG = 3
42-
} depscan_dependency_info_kind_t;
43-
44-
/// Swift modules to be built from a module interface, may have a bridging
45-
/// header.
46-
typedef struct {
47-
/// The module interface from which this module was built, if any.
48-
ds_string_t module_interface_path;
49-
50-
/// The paths of potentially ready-to-use compiled modules for the interface.
51-
ds_string_set_t* compiled_module_candidates;
52-
53-
/// The bridging header, if any.
54-
ds_string_t bridging_header_path;
55-
56-
/// The source files referenced by the bridging header.
57-
ds_string_set_t* bridging_source_files;
42+
} ds_dependency_info_kind_t;
5843

59-
/// (Clang) modules on which the bridging header depends.
60-
ds_string_set_t* bridging_module_dependencies;
61-
62-
/// Options to the compile command required to build this module interface
63-
ds_string_set_t* command_line;
64-
65-
/// To build a PCM to be used by this Swift module, we need to append these
66-
/// arguments to the generic PCM build arguments reported from the dependency
67-
/// graph.
68-
ds_string_set_t* extra_pcm_args;
69-
70-
/// The hash value that will be used for the generated module
71-
ds_string_t context_hash;
72-
73-
/// A flag to indicate whether or not this module is a framework.
74-
bool is_framework;
75-
} depscan_swift_textual_details_t;
76-
77-
/// Swift modules with only a binary module file.
78-
typedef struct {
79-
/// The path to the pre-compiled binary module
80-
ds_string_t compiled_module_path;
81-
82-
/// The path to the .swiftModuleDoc file.
83-
ds_string_t module_doc_path;
84-
85-
/// The path to the .swiftSourceInfo file.
86-
ds_string_t module_source_info_path;
87-
} depscan_swift_binary_details_t;
88-
89-
/// Swift placeholder modules carry additional details that specify their
90-
/// module doc path and source info paths.
91-
typedef struct {
92-
/// The path to the pre-compiled binary module
93-
ds_string_t compiled_module_path;
94-
95-
/// The path to the .swiftModuleDoc file.
96-
ds_string_t module_doc_path;
97-
98-
/// The path to the .swiftSourceInfo file.
99-
ds_string_t module_source_info_path;
100-
} depscan_swift_placeholder_details_t;
101-
102-
/// Clang modules are built from a module map file.
103-
typedef struct {
104-
/// The path to the module map used to build this module.
105-
ds_string_t module_map_path;
106-
107-
/// clang-generated context hash
108-
ds_string_t context_hash;
109-
110-
/// Options to the compile command required to build this clang modulemap
111-
ds_string_set_t* command_line;
112-
} depscan_clang_details_t;
113-
114-
typedef struct {
115-
depscan_dependency_info_kind_t kind;
116-
union {
117-
depscan_swift_textual_details_t swift_textual_details;
118-
depscan_swift_binary_details_t swift_binary_details;
119-
depscan_swift_placeholder_details_t swift_placeholder_details;
120-
depscan_clang_details_t clang_details;
121-
};
122-
} depscan_module_details_t;
44+
/// Opaque container of the details specific to a given module dependency.
45+
typedef void *ds_module_details_t;
12346

12447
typedef struct {
12548
/// The module's name
@@ -136,78 +59,139 @@ typedef struct {
13659
ds_string_t module_path;
13760

13861
/// The source files used to build this module.
139-
ds_string_set_t* source_files;
62+
ds_string_set_t *source_files;
14063

14164
/**
14265
* The list of modules which this module direct depends on.
14366
* The format is:
14467
* `<module-kind>:<module-name>`
14568
*/
146-
ds_string_set_t* direct_dependencies;
69+
ds_string_set_t *direct_dependencies;
14770

14871
/// Specific details of a particular kind of module.
149-
depscan_module_details_t* details;
150-
} depscan_dependency_info_t;
72+
ds_module_details_t details;
73+
} ds_dependency_info_t;
15174

15275
/// Full Dependency Graph (Result)
15376

15477
typedef struct {
15578
int count;
156-
depscan_dependency_info_t *modules;
157-
} depscan_dependency_set_t;
79+
ds_dependency_info_t *modules;
80+
} ds_dependency_set_t;
15881

15982
typedef struct {
16083
/// The name of the main module for this dependency graph (root node)
16184
ds_string_t main_module_name;
16285

16386
/// The complete list of modules discovered
164-
depscan_dependency_set_t* module_set;
165-
} depscan_dependency_result_t;
87+
ds_dependency_set_t *module_set;
88+
} ds_dependency_result_t;
16689

16790
typedef struct {
16891
/// The complete list of imports discovered
169-
ds_string_set_t* import_set;
170-
} depscan_prescan_result_t;
92+
ds_string_set_t *import_set;
93+
} ds_prescan_result_t;
17194

17295
//=== Dependency Result Functions -----------------------------------------===//
17396

174-
DEPSCAN_PUBLIC void
175-
depscan_dependency_info_details_dispose(depscan_module_details_t *details);
97+
DEPSCAN_PUBLIC ds_dependency_info_kind_t
98+
ds_get_module_detail_kind(ds_module_details_t details);
17699

177-
DEPSCAN_PUBLIC void
178-
depscan_dependency_info_dispose(depscan_dependency_info_t *info);
100+
//=== Swift Textual Module Details query APIs -----------------------------===//
101+
DEPSCAN_PUBLIC ds_string_t
102+
ds_get_swift_textual_detail_module_interface_path(ds_module_details_t details);
179103

180-
DEPSCAN_PUBLIC void
181-
depscan_dependency_set_dispose(depscan_dependency_set_t *set);
104+
DEPSCAN_PUBLIC ds_string_set_t *
105+
ds_get_swift_textual_detail_compiled_module_candidates(
106+
ds_module_details_t details);
107+
108+
DEPSCAN_PUBLIC ds_string_t
109+
ds_get_swift_textual_detail_bridging_header_path(ds_module_details_t details);
110+
111+
DEPSCAN_PUBLIC ds_string_set_t *
112+
ds_get_swift_textual_detail_bridging_source_files(ds_module_details_t details);
113+
114+
DEPSCAN_PUBLIC ds_string_set_t *
115+
ds_get_swift_textual_detail_bridging_module_dependencies(
116+
ds_module_details_t details);
117+
118+
DEPSCAN_PUBLIC ds_string_set_t *
119+
ds_get_swift_textual_detail_command_line(ds_module_details_t details);
120+
121+
DEPSCAN_PUBLIC ds_string_set_t *
122+
ds_get_swift_textual_detail_extra_pcm_args(ds_module_details_t details);
123+
124+
DEPSCAN_PUBLIC ds_string_t
125+
ds_get_swift_textual_detail_context_hash(ds_module_details_t details);
126+
127+
DEPSCAN_PUBLIC bool
128+
ds_get_swift_textual_detail_is_framework(ds_module_details_t details);
129+
130+
//=== Swift Binary Module Details query APIs ------------------------------===//
131+
132+
DEPSCAN_PUBLIC ds_string_t
133+
ds_get_swift_binary_detail_compiled_module_path(ds_module_details_t details);
134+
135+
DEPSCAN_PUBLIC ds_string_t
136+
ds_get_swift_binary_detail_module_doc_path(ds_module_details_t details);
137+
138+
DEPSCAN_PUBLIC ds_string_t ds_get_swift_binary_detail_module_source_info_path(
139+
ds_module_details_t *details);
140+
141+
//=== Swift Placeholder Module Details query APIs -------------------------===//
142+
143+
DEPSCAN_PUBLIC ds_string_t ds_get_swift_placeholder_detail_compiled_module_path(
144+
ds_module_details_t details);
145+
146+
DEPSCAN_PUBLIC ds_string_t
147+
ds_get_swift_placeholder_detail_module_doc_path(ds_module_details_t details);
148+
149+
DEPSCAN_PUBLIC ds_string_t
150+
ds_get_swift_placeholder_detail_module_source_info_path(
151+
ds_module_details_t details);
152+
153+
//=== Clang Module Details query APIs -------------------------------------===//
154+
155+
DEPSCAN_PUBLIC ds_string_t
156+
ds_get_clang_detail_module_map_path(ds_module_details_t details);
157+
158+
DEPSCAN_PUBLIC ds_string_t
159+
ds_get_clang_detail_context_hash(ds_module_details_t details);
160+
161+
DEPSCAN_PUBLIC ds_string_set_t *
162+
ds_get_clang_detail_command_line(ds_module_details_t details);
163+
164+
//=== Cleanup Functions ---------------------------------------------------===//
182165

183166
DEPSCAN_PUBLIC void
184-
depscan_dependency_result_dispose(depscan_dependency_result_t *result);
167+
ds_dependency_info_details_dispose(ds_module_details_t details);
168+
169+
DEPSCAN_PUBLIC void ds_dependency_info_dispose(ds_dependency_info_t *info);
170+
171+
DEPSCAN_PUBLIC void ds_dependency_set_dispose(ds_dependency_set_t *set);
185172

186173
DEPSCAN_PUBLIC void
187-
depscan_prescan_result_dispose(depscan_prescan_result_t *result);
174+
ds_dependency_result_dispose(ds_dependency_result_t *result);
175+
176+
DEPSCAN_PUBLIC void ds_prescan_result_dispose(ds_prescan_result_t *result);
188177

189178
//=== Scanner Functions ---------------------------------------------------===//
190179

191-
/// Container of the configuration state and shared cache for dependency scanning.
192-
typedef void *depscan_scanner_t;
180+
/// Container of the configuration state and shared cache for dependency
181+
/// scanning.
182+
typedef void *ds_scanner_t;
193183

194-
DEPSCAN_PUBLIC depscan_scanner_t
195-
depscan_scanner_create(void);
184+
DEPSCAN_PUBLIC ds_scanner_t ds_scanner_create(void);
196185

197-
DEPSCAN_PUBLIC void
198-
depscan_scanner_dispose(depscan_scanner_t);
199-
200-
DEPSCAN_PUBLIC depscan_dependency_result_t*
201-
depscan_scan_dependencies(depscan_scanner_t* scanner,
202-
const char *working_directory,
203-
int argc,
204-
const char *const *argv);
205-
206-
DEPSCAN_PUBLIC depscan_prescan_result_t*
207-
depscan_prescan_dependencies(depscan_scanner_t* scanner,
208-
const char *working_directory,
209-
int argc,
210-
const char *const *argv);
186+
DEPSCAN_PUBLIC void ds_scanner_dispose(ds_scanner_t);
187+
188+
DEPSCAN_PUBLIC ds_dependency_result_t *
189+
ds_scan_dependencies(ds_scanner_t *scanner, const char *working_directory,
190+
int argc, const char *const *argv);
191+
192+
DEPSCAN_PUBLIC ds_prescan_result_t *
193+
ds_prescan_dependencies(ds_scanner_t *scanner, const char *working_directory,
194+
int argc, const char *const *argv);
211195

212196
DEPSCAN_END_DECLS
213197

0 commit comments

Comments
 (0)