Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 53571ca

Browse files
committedSep 29, 2020
avoid 2 Builder instance issues
- the first builder is used for bootstrapping, it is not useful to us, however the clean up may get running twice
1 parent 61216ee commit 53571ca

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed
 

‎src/build.cc

+14-10
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
191191
#ifdef _WIN32
192192
_setmode(_fileno(stdout), _O_TEXT); // End Windows extra CR fix
193193
#endif
194-
fputs(stripped.c_str(),compiler_log);
195-
fflush(compiler_log);
194+
if (compiler_log) {
195+
fputs(stripped.c_str(), compiler_log);
196+
fflush(compiler_log);
197+
}
196198
}
197199
}
198200

@@ -751,15 +753,14 @@ bool RealCommandRunner::WaitForCommand(Result* result) {
751753

752754
Builder::Builder(State* state, const BuildConfig& config,
753755
BuildLog* build_log, DepsLog* deps_log,
754-
DiskInterface* disk_interface)
756+
DiskInterface* disk_interface,
757+
FILE* compiler_log)
755758
: state_(state), config_(config),
759+
compiler_log_(compiler_log),
756760
plan_(this), disk_interface_(disk_interface),
757761
scan_(state, build_log, deps_log, disk_interface,
758762
&config_.depfile_parser_options) {
759-
status_ = new BuildStatus(config);
760-
compiler_log_ = fopen(".compiler.log","w");
761-
setvbuf(compiler_log_,NULL,_IOLBF,BUFSIZ);
762-
SetCloseOnExec(fileno(compiler_log_));
763+
status_ = new BuildStatus(config);
763764
}
764765

765766
Builder::~Builder() {
@@ -794,9 +795,12 @@ void Builder::Cleanup() {
794795
disk_interface_->RemoveFile(depfile);
795796
}
796797
}
797-
fputs("# Done",compiler_log_);
798-
fclose(compiler_log_);
799-
compiler_log_ = NULL;
798+
799+
if (compiler_log_) {
800+
fputs("# Done", compiler_log_);
801+
fclose(compiler_log_);
802+
compiler_log_ = NULL;
803+
}
800804
}
801805

802806
Node* Builder::AddTarget(const string& name, string* err) {

‎src/build.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct BuildConfig {
180180
struct Builder {
181181
Builder(State* state, const BuildConfig& config,
182182
BuildLog* build_log, DepsLog* deps_log,
183-
DiskInterface* disk_interface);
183+
DiskInterface* disk_interface, FILE* compiler_log);
184184
~Builder();
185185

186186
/// Clean up after interrupted commands by deleting output files.
@@ -214,8 +214,8 @@ struct Builder {
214214
bool LoadDyndeps(Node* node, string* err);
215215

216216
State* state_;
217-
FILE* compiler_log_;
218217
const BuildConfig& config_;
218+
FILE* compiler_log_;
219219
Plan plan_;
220220
#if __cplusplus < 201703L
221221
auto_ptr<CommandRunner> command_runner_;

‎src/ninja.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool NinjaMain::RebuildManifest(const char* input_file, string* err) {
251251
if (!node)
252252
return false;
253253

254-
Builder builder(&state_, config_, &build_log_, &deps_log_, &disk_interface_);
254+
Builder builder(&state_, config_, &build_log_, &deps_log_, &disk_interface_, NULL);
255255
if (!builder.AddTarget(node, err))
256256
return false;
257257

@@ -1131,7 +1131,11 @@ int NinjaMain::RunBuild(int argc, char** argv) {
11311131

11321132
disk_interface_.AllowStatCache(g_experimental_statcache);
11331133

1134-
Builder builder(&state_, config_, &build_log_, &deps_log_, &disk_interface_);
1134+
FILE* compiler_log_ = fopen(".compiler.log","w");
1135+
setvbuf(compiler_log_,NULL,_IOLBF,BUFSIZ);
1136+
SetCloseOnExec(fileno(compiler_log_));
1137+
Builder builder(&state_, config_, &build_log_, &deps_log_, &disk_interface_,compiler_log_);
1138+
11351139
for (size_t i = 0; i < targets.size(); ++i) {
11361140
if (!builder.AddTarget(targets[i], &err)) {
11371141
if (!err.empty()) {
@@ -1363,7 +1367,7 @@ NORETURN void real_main(int argc, char** argv) {
13631367
ninja.ToolCleanDead(&options,argc,argv);
13641368

13651369
// Attempt to rebuild the manifest before building anything else
1366-
if (ninja.RebuildManifest(options.input_file, &err)) {
1370+
if (false && ninja.RebuildManifest(options.input_file, &err)) {
13671371
// In dry_run mode the regeneration will succeed without changing the
13681372
// manifest forever. Better to return immediately.
13691373
if (config.dry_run)

0 commit comments

Comments
 (0)
This repository has been archived.