Skip to content

Commit d0220e5

Browse files
committed
[Dependency Scanning] Add entry-point to DependencyScanningTool and the corresponding C API for a batch scan operation
1 parent 2ad9600 commit d0220e5

File tree

7 files changed

+87
-5
lines changed

7 files changed

+87
-5
lines changed

include/swift-c/DependencyScan/DSString.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,3 @@ DEPSCAN_PUBLIC void ds_string_set_dispose(ds_string_set_t *set);
4848
DEPSCAN_END_DECLS
4949

5050
#endif // SWIFT_C_DSSTRING_H
51-
52-

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ typedef struct {
9292
ds_string_set_t *import_set;
9393
} ds_prescan_result_t;
9494

95+
//=== Batch Scan Input Specification --------------------------------------===//
96+
97+
typedef struct {
98+
ds_string_t module_name;
99+
ds_string_t arguments;
100+
bool is_swift;
101+
} ds_batch_scan_entry_t;
102+
103+
typedef struct {
104+
int count;
105+
ds_batch_scan_entry_t *modules;
106+
} ds_batch_scan_input_t;
107+
108+
typedef struct {
109+
int count;
110+
ds_dependency_result_t **results;
111+
} ds_batch_scan_result_t;
112+
95113
//=== Dependency Result Functions -----------------------------------------===//
96114

97115
DEPSCAN_PUBLIC ds_dependency_info_kind_t
@@ -175,6 +193,13 @@ ds_dependency_result_dispose(ds_dependency_result_t *result);
175193

176194
DEPSCAN_PUBLIC void ds_prescan_result_dispose(ds_prescan_result_t *result);
177195

196+
DEPSCAN_PUBLIC void ds_batch_scan_entry_dispose(ds_batch_scan_entry_t *entry);
197+
198+
DEPSCAN_PUBLIC void ds_batch_scan_input_dispose(ds_batch_scan_input_t *input);
199+
200+
DEPSCAN_PUBLIC void
201+
ds_batch_scan_result_dispose(ds_batch_scan_result_t *result);
202+
178203
//=== Scanner Functions ---------------------------------------------------===//
179204

180205
/// Container of the configuration state and shared cache for dependency
@@ -189,6 +214,11 @@ DEPSCAN_PUBLIC ds_dependency_result_t *
189214
ds_scan_dependencies(ds_scanner_t *scanner, const char *working_directory,
190215
int argc, const char *const *argv);
191216

217+
DEPSCAN_PUBLIC ds_batch_scan_result_t *
218+
ds_batch_scan_dependencies(ds_scanner_t *scanner, const char *working_directory,
219+
ds_batch_scan_input_t *batch_input,
220+
int argc, const char *const *argv);
221+
192222
DEPSCAN_PUBLIC ds_prescan_result_t *
193223
ds_prescan_dependencies(ds_scanner_t *scanner, const char *working_directory,
194224
int argc, const char *const *argv);

lib/DependencyScan/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_swift_host_library(SwiftScan STATIC
33
DependencyScanImpl.cpp
44
DependencyScanningTool.cpp
55
ScanDependencies.cpp
6-
DSString.cpp
6+
DSStringImpl.cpp
77
c-include-check.c)
88

99
add_dependencies(SwiftScan

lib/DependencyScan/DSString.cpp renamed to lib/DependencyScan/DSStringImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/DependencyScan/DSString.h"
13+
#include "swift/DependencyScan/DSStringImpl.h"
1414

1515
/// Describes the kind of underlying data in ds_string_t.
1616
enum ds_string_management {

lib/DependencyScan/DependencyScanImpl.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,41 @@ ds_dependency_result_t *ds_scan_dependencies(ds_scanner_t *scanner,
4545
return DependencyGraph;
4646
}
4747

48+
ds_batch_scan_result_t *
49+
ds_batch_scan_dependencies(ds_scanner_t *scanner, const char *working_directory,
50+
ds_batch_scan_input_t *batch_input,
51+
int argc, const char *const *argv) {
52+
DependencyScanningTool *ScanningTool = unwrap_scanner(scanner);
53+
std::vector<const char *> Compilation;
54+
for (int i = 0; i < argc; ++i)
55+
Compilation.push_back(argv[i]);
56+
57+
std::vector<BatchScanInput> BatchInput;
58+
for (int i = 0; i < batch_input->count; ++i) {
59+
ds_batch_scan_entry_t &Entry = batch_input->modules[i];
60+
BatchInput.push_back({ds_get_C_string(Entry.module_name),
61+
ds_get_C_string(Entry.arguments),
62+
/*outputPath*/ "", Entry.is_swift});
63+
}
64+
65+
66+
// Execute the scan and bridge the result
67+
auto BatchScanResult =
68+
ScanningTool->getDependencies(Compilation, BatchInput, {});
69+
ds_batch_scan_result_t *Result = new ds_batch_scan_result_t;
70+
Result->results = new ds_dependency_result_t*[BatchScanResult.size()];
71+
72+
for (size_t i = 0; i < BatchScanResult.size(); ++i) {
73+
auto &ResultOrErr = BatchScanResult[i];
74+
if (ResultOrErr.getError())
75+
Result->results[i] = nullptr;
76+
77+
Result->results[i] = ResultOrErr.get();
78+
}
79+
80+
return Result;
81+
}
82+
4883
ds_prescan_result_t *ds_prescan_dependencies(ds_scanner_t *scanner,
4984
const char *working_directory,
5085
int argc,
@@ -233,3 +268,22 @@ void ds_prescan_result_dispose(ds_prescan_result_t *result) {
233268
ds_string_set_dispose(result->import_set);
234269
delete result;
235270
}
271+
272+
void ds_batch_scan_entry_dispose(ds_batch_scan_entry_t *entry) {
273+
ds_string_dispose(entry->module_name);
274+
ds_string_dispose(entry->arguments);
275+
delete entry;
276+
}
277+
278+
void ds_batch_scan_input_dispose(ds_batch_scan_input_t *input) {
279+
for (int i = 0; i < input->count; ++i) {
280+
ds_batch_scan_entry_dispose(&input->modules[i]);
281+
}
282+
}
283+
284+
void
285+
ds_batch_scan_result_dispose(ds_batch_scan_result_t *result) {
286+
for (int i = 0; i < result->count; ++i) {
287+
ds_dependency_result_dispose(result->results[i]);
288+
}
289+
}

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "swift/Basic/LLVM.h"
2525
#include "swift/Basic/STLExtras.h"
2626
#include "swift/ClangImporter/ClangImporter.h"
27-
#include "swift/DependencyScan/DSString.h"
27+
#include "swift/DependencyScan/DSStringImpl.h"
2828
#include "swift/Frontend/Frontend.h"
2929
#include "swift/Frontend/FrontendOptions.h"
3030
#include "swift/Frontend/ModuleInterfaceLoader.h"

0 commit comments

Comments
 (0)