Skip to content

Commit 523948b

Browse files
committed
feat: remove boost::thread
because it's not header-only
1 parent df46945 commit 523948b

File tree

170 files changed

+78
-38168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+78
-38168
lines changed

jetpack/src/ModuleResolver.cpp

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ namespace jetpack {
4545

4646
static const char* PackageJsonName = "package.json";
4747

48+
bool WorkerErrors::print() {
49+
std::lock_guard<std::mutex> guard(m_);
50+
for (auto& error : errors_) {
51+
std::cerr << fmt::format("File: {}", error.file_path) << std::endl;
52+
std::cerr << fmt::format("Error: {}", error.error_content) << std::endl;
53+
}
54+
return !errors_.empty();
55+
}
56+
57+
void WorkerErrors::clear() {
58+
std::lock_guard<std::mutex> guard(m_);
59+
errors_.clear();
60+
}
61+
62+
void WorkerErrors::throw_collection_if_not_empty() {
63+
std::lock_guard<std::mutex> guard(m_);
64+
if (!errors_.empty()) {
65+
WorkerErrorCollection col;
66+
col.errors = errors_;
67+
throw std::move(col);
68+
}
69+
}
70+
4871
ModuleResolveException::ModuleResolveException(const std::string& path, const std::string& content)
4972
: file_path(path), error_content(content) {
5073

@@ -128,8 +151,7 @@ namespace jetpack {
128151
Sp<ModuleFile> mf) {
129152
WorkerError error;
130153
if (!mf->GetSource(error)) {
131-
auto errors = worker_errors_.synchronize();
132-
errors->push_back(error);
154+
worker_errors_.add(error);
133155
return;
134156
}
135157

@@ -200,9 +222,8 @@ namespace jetpack {
200222

201223
auto match_result = FindProviderByPath(mf, path);
202224
if (match_result.first == nullptr) {
203-
auto errors = worker_errors_.synchronize();
204225
WorkerError err {mf->Path(), std::string("module can't be resolved: ") + path };
205-
errors->push_back(std::move(err));
226+
worker_errors_.add(err);
206227
return nullptr;
207228
}
208229

@@ -234,28 +255,23 @@ namespace jetpack {
234255
try {
235256
ParseFile(config, childMod);
236257
} catch (parser::ParseError& ex) {
237-
auto errors = worker_errors_.synchronize();
238-
errors->push_back({childMod->Path(), ex.ErrorMessage() });
258+
worker_errors_.add({ childMod->Path(), ex.ErrorMessage() });
239259
} catch (VariableExistsError& err) {
240-
auto errors = worker_errors_.synchronize();
241260
std::string message = format("variable '{}' has been defined, location: {}:{}",
242261
err.name,
243262
err.exist_var->location.start.line + 1,
244263
err.exist_var->location.start.column);
245-
errors->push_back({childMod->Path(), std::move(message) });
264+
worker_errors_.add({childMod->Path(), std::move(message) });
246265
} catch (std::exception& ex) {
247-
auto errors = worker_errors_.synchronize();
248-
errors->push_back({childMod->Path(), ex.what() });
266+
worker_errors_.add({childMod->Path(), ex.what() });
249267
}
250268
FinishOne();
251269
});
252270
return childMod;
253271
}
254272

255273
void ModuleResolver::PrintStatistic() {
256-
auto errors = worker_errors_.synchronize();
257-
if (!worker_errors_->empty()) {
258-
PrintErrors(*errors);
274+
if (worker_errors_.print()) {
259275
return;
260276
}
261277

@@ -272,8 +288,7 @@ namespace jetpack {
272288
result["totalFiles"] = finished_files_count_;
273289
result["exports"] = std::move(exports);
274290

275-
if (!errors->empty()) {
276-
PrintErrors(*errors);
291+
if (worker_errors_.print()) {
277292
return;
278293
}
279294

@@ -301,18 +316,15 @@ namespace jetpack {
301316
try {
302317
ParseFileFromPath(rootProvider, config, resolvedPath);
303318
} catch (parser::ParseError& ex) {
304-
auto errors = worker_errors_.synchronize();
305-
errors->push_back({ resolvedPath, ex.ErrorMessage() });
319+
worker_errors_.add({ resolvedPath, ex.ErrorMessage() });
306320
} catch (VariableExistsError& err) {
307-
auto errors = worker_errors_.synchronize();
308321
std::string message = format("variable '{}' has been defined, location: {}:{}",
309322
err.name,
310323
err.exist_var->location.start.line,
311324
err.exist_var->location.start.column);
312-
errors->push_back({ resolvedPath, std::move(message) });
325+
worker_errors_.add({ resolvedPath, std::move(message) });
313326
} catch (std::exception& ex) {
314-
auto errors = worker_errors_.synchronize();
315-
errors->push_back({ resolvedPath, ex.what() });
327+
worker_errors_.add({ resolvedPath, ex.what() });
316328
}
317329
FinishOne();
318330
});
@@ -323,14 +335,7 @@ namespace jetpack {
323335
});
324336
ps.Submit();
325337

326-
{
327-
auto errors = worker_errors_.synchronize();
328-
if (!errors->empty()) {
329-
WorkerErrorCollection col;
330-
col.errors = *errors;
331-
throw std::move(col);
332-
}
333-
}
338+
worker_errors_.throw_collection_if_not_empty();
334339
}
335340

336341
/**
@@ -366,23 +371,21 @@ namespace jetpack {
366371
const auto& u8relative_path = info.relative_path;
367372
auto resolved_path = mod->resolved_map.find(u8relative_path);
368373
if (resolved_path == mod->resolved_map.end()) {
369-
auto errors = worker_errors_.synchronize();
370374
WorkerError err {
371375
mod->Path(),
372376
format("resolve path failed: {}", u8relative_path)
373377
};
374-
errors->emplace_back(std::move(err));
378+
worker_errors_.add(err);
375379
return;
376380
}
377381

378382
auto iter = modules_table_.FindModuleByPath(resolved_path->second);
379383
if (iter == nullptr) {
380-
auto errors = worker_errors_.synchronize();
381384
WorkerError err {
382385
mod->Path(),
383386
format("module not found: {}", resolved_path->second)
384387
};
385-
errors->emplace_back(std::move(err));
388+
worker_errors_.add(err);
386389
return;
387390
}
388391
if (info.is_export_all) {
@@ -625,14 +628,7 @@ namespace jetpack {
625628
fut.get();
626629
}
627630

628-
{
629-
auto errors = worker_errors_.synchronize();
630-
if (!errors->empty()) {
631-
WorkerErrorCollection col;
632-
col.errors = *errors;
633-
throw std::move(col);
634-
}
635-
}
631+
worker_errors_.throw_collection_if_not_empty();
636632
name_generator = MinifyNameGenerator::Merge(collection.content, id_logger_);
637633
}
638634

@@ -1168,12 +1164,11 @@ namespace jetpack {
11681164

11691165
auto iter = mf->GetExportManager().local_exports_name.find(export_name);
11701166
if (iter == mf->GetExportManager().local_exports_name.end()) {
1171-
auto errors = worker_errors_.synchronize();
11721167
WorkerError err {
11731168
mf->Path(),
11741169
format("symbol not found failed: {}", export_name)
11751170
};
1176-
errors->emplace_back(std::move(err));
1171+
worker_errors_.add(err);
11771172
break;
11781173
}
11791174
auto info = iter->second;

jetpack/src/ModuleResolver.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <tsl/ordered_map.h>
99
#include <ThreadPool.h>
1010
#include <filesystem.hpp>
11-
#include <boost/thread/synchronized_value.hpp>
1211
#include <condition_variable>
1312
#include <vector>
1413
#include <memory>
@@ -28,6 +27,27 @@
2827

2928
namespace jetpack {
3029

30+
struct WorkerErrors {
31+
public:
32+
WorkerErrors() = default;
33+
34+
inline void add(const WorkerError& err) {
35+
std::lock_guard<std::mutex> guard(m_);
36+
errors_.push_back(err);
37+
}
38+
39+
bool print();
40+
41+
void clear();
42+
43+
void throw_collection_if_not_empty();
44+
45+
private:
46+
Vec<WorkerError> errors_;
47+
std::mutex m_;
48+
49+
};
50+
3151
class ModuleCompositor;
3252

3353
class ModuleResolveException : std::exception {
@@ -207,7 +227,7 @@ namespace jetpack {
207227

208228
Vec<Sp<ModuleProvider>> providers_;
209229

210-
boost::synchronized_value<Vec<WorkerError>> worker_errors_;
230+
WorkerErrors worker_errors_;
211231

212232
int32_t enqueued_files_count_ = 0;
213233
int32_t finished_files_count_ = 0;

jetpack/src/UniqueNameGenerator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <mutex>
1212
#include <robin_hood.h>
1313
#include <parser/SyntaxNodes.h>
14-
#include <boost/thread/synchronized_value.hpp>
1514

1615
namespace jetpack {
1716

jetpack/tests/common_js.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
#include <iostream>
66
#include <gtest/gtest.h>
7+
#include <filesystem.hpp>
78
#include "parser/Parser.hpp"
89
#include "parser/ParserContext.h"
910
#include "parser/NodesMaker.h"
1011
#include "codegen/CodeGen.h"
1112
#include "CodeGenFragment.h"
1213
#include "SimpleAPI.h"
13-
#include "utils/Path.h"
1414

1515
#include "ModuleResolver.h"
1616

@@ -110,20 +110,20 @@ TEST(CommonJS, CodeGen) {
110110
}
111111

112112
TEST(CommonJS, Complex) {
113-
Path path(JETPACK_TEST_RUNNING_DIR);
114-
path.Join("tests/fixtures/cjs/index.js");
113+
ghc::filesystem::path path(JETPACK_TEST_RUNNING_DIR);
114+
path.append("tests/fixtures/cjs/index.js");
115115

116-
auto entryPath = path.ToString();
116+
auto entryPath = path.string();
117117
std::cout << "dir: " << entryPath << std::endl;
118118

119-
Path outputPath(JETPACK_BUILD_DIR);
120-
outputPath.Join("cjs_bundle_test.js");
119+
ghc::filesystem::path outputPath(JETPACK_BUILD_DIR);
120+
outputPath.append("cjs_bundle_test.js");
121121

122-
std::cout << "output dir: " << outputPath.ToString() << std::endl;
122+
std::cout << "output dir: " << outputPath.string() << std::endl;
123123

124124
JetpackFlags flags;
125125
flags |= JETPACK_JSX;
126126
flags |= JETPACK_SOURCEMAP;
127127
flags |= JETPACK_TRACE_FILE;
128-
EXPECT_EQ(jetpack_bundle_module(entryPath.c_str(), outputPath.ToString().c_str(), static_cast<int>(flags), nullptr), 0);
128+
EXPECT_EQ(jetpack_bundle_module(entryPath.c_str(), outputPath.string().c_str(), static_cast<int>(flags), nullptr), 0);
129129
}

jetpack/tests/sourcemap.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#include <gtest/gtest.h>
66
#include <parser/ParserContext.h>
77
#include <ThreadPool.h>
8+
#include <filesystem.hpp>
89
#include "sourcemap/SourceMapGenerator.h"
910
#include "sourcemap/SourceMapDecoder.h"
1011
#include "codegen/CodeGen.h"
1112
#include "ModuleResolver.h"
1213
#include "ModuleCompositor.h"
1314
#include "SimpleAPI.h"
14-
#include "utils/Path.h"
1515
#include "utils/io/FileIO.h"
1616

1717
using namespace jetpack;
@@ -134,28 +134,28 @@ TEST(SourceMap, Simple) {
134134
}
135135

136136
TEST(SourceMap, Complex) {
137-
Path path(JETPACK_TEST_RUNNING_DIR);
138-
path.Join("tests/fixtures/sourcemap/index.js");
137+
ghc::filesystem::path path(JETPACK_TEST_RUNNING_DIR);
138+
path.append("tests/fixtures/sourcemap/index.js");
139139

140-
auto entryPath = path.ToString();
140+
auto entryPath = path.string();
141141
std::cout << "dir: " << entryPath << std::endl;
142142

143-
EXPECT_TRUE(io::IsFileExist(entryPath));
143+
EXPECT_TRUE(ghc::filesystem::exists(entryPath));
144144

145-
Path outputPath(JETPACK_BUILD_DIR);
146-
outputPath.Join("sourcemap_bundle_test.js");
145+
ghc::filesystem::path outputPath(JETPACK_BUILD_DIR);
146+
outputPath.append("sourcemap_bundle_test.js");
147147

148-
std::cout << "output dir: " << outputPath.ToString() << std::endl;
148+
std::cout << "output dir: " << outputPath.string() << std::endl;
149149

150150
JetpackFlags flags;
151151
flags |= JETPACK_JSX;
152152
flags |= JETPACK_SOURCEMAP;
153153
flags |= JETPACK_TRACE_FILE;
154-
std::string output_str = outputPath.ToString();
154+
std::string output_str = outputPath.string();
155155
EXPECT_EQ(jetpack_bundle_module(entryPath.c_str(), output_str.c_str(), static_cast<int>(flags), nullptr), 0);
156156

157157
std::string sourcemapContent;
158-
EXPECT_EQ(io::ReadFileToStdString(outputPath.ToString() + ".map", sourcemapContent), io::IOError::Ok);
158+
EXPECT_EQ(io::ReadFileToStdString(outputPath.string() + ".map", sourcemapContent), io::IOError::Ok);
159159

160160
auto sourcemapJson = nlohmann::json::parse(sourcemapContent);
161161
std::string mapping = sourcemapJson["mappings"];

third_party/boost/boost/thread.hpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)