Skip to content

Commit c88f9bf

Browse files
committed
Swift: Use absl::StrJoin to dump arguments for logging.
This also removes the TODO about using `absl::StrJoin` to dump the environment because we can't easily get a range from a null-terminated `envp`. It also doesn't suffer from the usual awkwardness around inserting a separator *between* elements but not after the last one, so a for loop is clear enough.
1 parent 621761b commit c88f9bf

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

swift/extractor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ swift_cc_binary(
1616
"//swift/extractor/remapping",
1717
"//swift/extractor/translators",
1818
"//swift/third_party/swift-llvm-support",
19+
"@absl//absl/strings",
1920
],
2021
)
2122

swift/extractor/main.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <swift/FrontendTool/FrontendTool.h>
1010
#include <swift/Basic/InitializeSwiftModules.h>
1111

12+
#include "absl/strings/str_join.h"
13+
1214
#include "swift/extractor/SwiftExtractor.h"
1315
#include "swift/extractor/infra/TargetDomains.h"
1416
#include "swift/extractor/remapping/SwiftFileInterception.h"
@@ -184,18 +186,13 @@ codeql::SwiftExtractorConfiguration configure(int argc, char** argv) {
184186
return configuration;
185187
}
186188

187-
// TODO: use `absl::StrJoin` or `boost::algorithm::join`
188189
static auto argDump(int argc, char** argv) {
189-
std::string ret;
190-
for (auto arg = argv + 1; arg < argv + argc; ++arg) {
191-
ret += *arg;
192-
ret += ' ';
190+
if (argc < 2) {
191+
return ""s;
193192
}
194-
ret.pop_back();
195-
return ret;
193+
return absl::StrJoin(argv + 1, argv + argc, " ");
196194
}
197195

198-
// TODO: use `absl::StrJoin` or `boost::algorithm::join`
199196
static auto envDump(char** envp) {
200197
std::string ret;
201198
for (auto env = envp; *env; ++env) {

0 commit comments

Comments
 (0)