@@ -165,6 +165,9 @@ class BuildSystemImpl : public BuildSystemCommandInterface {
165
165
// / Flag indicating if the build has been aborted.
166
166
bool buildWasAborted = false ;
167
167
168
+ // / Flag indicating if the build has been cancelled.
169
+ std::atomic<bool > isCancelled_{ false };
170
+
168
171
// / @name BuildSystemCommandInterface Implementation
169
172
// / @{
170
173
@@ -297,7 +300,18 @@ class BuildSystemImpl : public BuildSystemCommandInterface {
297
300
void setBuildWasAborted (bool value) {
298
301
buildWasAborted = value;
299
302
}
300
-
303
+
304
+ // / Cancel the running build.
305
+ void cancel () {
306
+ isCancelled_ = true ;
307
+ getExecutionQueue ().cancelAllJobs ();
308
+ }
309
+
310
+ // / Check if the build has been cancelled.
311
+ bool isCancelled () {
312
+ return isCancelled_;
313
+ }
314
+
301
315
// / @}
302
316
};
303
317
@@ -309,10 +323,6 @@ static BuildSystemImpl& getBuildSystem(BuildEngine& engine) {
309
323
return static_cast <BuildSystemEngineDelegate*>(
310
324
engine.getDelegate ())->getBuildSystem ();
311
325
}
312
-
313
- static bool isCancelled (BuildEngine& engine) {
314
- return getBuildSystem (engine).getCommandInterface ().getDelegate ().isCancelled ();
315
- }
316
326
317
327
// / This is the task used to "build" a target, it translates between the request
318
328
// / for building a target key and the requests for all of its nodes.
@@ -361,7 +371,7 @@ class TargetTask : public Task {
361
371
362
372
virtual void inputsAvailable (BuildEngine& engine) override {
363
373
// If the build should cancel, do nothing.
364
- if (isCancelled (engine)) {
374
+ if (getBuildSystem (engine). isCancelled ( )) {
365
375
engine.taskIsComplete (this , BuildValue::makeSkippedCommand ().toData ());
366
376
return ;
367
377
}
@@ -835,6 +845,9 @@ class CommandTask : public Task {
835
845
Command& command;
836
846
837
847
virtual void start (BuildEngine& engine) override {
848
+ // Notify the client the command is preparing to run.
849
+ getBuildSystem (engine).getDelegate ().commandPreparing (&command);
850
+
838
851
command.start (getBuildSystem (engine).getCommandInterface (), this );
839
852
}
840
853
@@ -853,28 +866,33 @@ class CommandTask : public Task {
853
866
}
854
867
855
868
virtual void inputsAvailable (BuildEngine& engine) override {
856
- // If the build should cancel, do nothing.
857
- if (isCancelled (engine)) {
858
- engine.taskIsComplete (this , BuildValue::makeSkippedCommand ().toData ());
859
- return ;
860
- }
861
-
862
869
auto & bsci = getBuildSystem (engine).getCommandInterface ();
863
870
auto fn = [this , &bsci=bsci](QueueJobContext* context) {
864
- bool shouldSkip = !bsci.getDelegate ().shouldCommandStart (&command);
871
+ // If the build should cancel, do nothing.
872
+ if (getBuildSystem (bsci.getBuildEngine ()).isCancelled ()) {
873
+ bsci.taskIsComplete (this , BuildValue::makeCancelledCommand ());
874
+ return ;
875
+ }
865
876
866
- if (shouldSkip) {
877
+ // Check if the command should be skipped.
878
+ if (!bsci.getDelegate ().shouldCommandStart (&command)) {
867
879
// We need to call commandFinished here because commandPreparing and
868
880
// shouldCommandStart guarantee that they're followed by
869
881
// commandFinished.
870
882
bsci.getDelegate ().commandFinished (&command);
871
-
872
883
bsci.taskIsComplete (this , BuildValue::makeSkippedCommand ());
873
- } else {
874
- command.inputsAvailable (bsci, this );
884
+ return ;
885
+ }
886
+
887
+ // Execute the command, with notifications to the delegate.
888
+ auto result = command.execute (bsci, this , context);
889
+
890
+ // Inform the engine of the result.
891
+ if (result.isFailedCommand ()) {
892
+ bsci.getDelegate ().hadCommandFailure ();
875
893
}
894
+ bsci.taskIsComplete (this , std::move (result));
876
895
};
877
-
878
896
bsci.addJob ({ &command, std::move (fn) });
879
897
}
880
898
@@ -2064,9 +2082,6 @@ class SymlinkCommand : public Command {
2064
2082
2065
2083
virtual void start (BuildSystemCommandInterface& bsci,
2066
2084
core::Task* task) override {
2067
- // Notify the client the command is preparing to run.
2068
- bsci.getDelegate ().commandPreparing (this );
2069
-
2070
2085
// The command itself takes no inputs, so just treat any declared inputs as
2071
2086
// "must follow" directives.
2072
2087
//
@@ -2088,70 +2103,53 @@ class SymlinkCommand : public Command {
2088
2103
assert (0 && " unexpected API call" );
2089
2104
}
2090
2105
2091
- virtual void inputsAvailable (BuildSystemCommandInterface& bsci,
2092
- core::Task* task) override {
2093
- // If the build should cancel, do nothing.
2094
- if (bsci.getDelegate ().isCancelled ()) {
2095
- bsci.taskIsComplete (task, BuildValue::makeCancelledCommand ());
2096
- return ;
2097
- }
2098
-
2106
+ virtual BuildValue execute (BuildSystemCommandInterface& bsci,
2107
+ core::Task* task,
2108
+ QueueJobContext* context) override {
2099
2109
// It is an error if this command isn't configured properly.
2100
2110
if (!output) {
2101
- bsci.getDelegate ().hadCommandFailure ();
2102
- bsci.taskIsComplete (task, BuildValue::makeFailedCommand ());
2103
- return ;
2111
+ return BuildValue::makeFailedCommand ();
2104
2112
}
2105
-
2106
- auto fn = [this , &bsci=bsci, task](QueueJobContext* context) {
2107
- // Notify the client the actual command body is going to run.
2108
- bsci.getDelegate ().commandStarted (this );
2109
-
2110
- // Create the directory containing the symlink, if necessary.
2111
- //
2112
- // FIXME: Shared behavior with ExternalCommand.
2113
- {
2114
- auto parent = llvm::sys::path::parent_path (output->getName ());
2115
- if (!parent.empty ()) {
2116
- (void ) bsci.getDelegate ().getFileSystem ().createDirectories (parent);
2117
- }
2113
+
2114
+ // Create the directory containing the symlink, if necessary.
2115
+ //
2116
+ // FIXME: Shared behavior with ExternalCommand.
2117
+ {
2118
+ auto parent = llvm::sys::path::parent_path (output->getName ());
2119
+ if (!parent.empty ()) {
2120
+ (void ) bsci.getDelegate ().getFileSystem ().createDirectories (parent);
2118
2121
}
2122
+ }
2119
2123
2120
- // Create the symbolic link (note that despite the poorly chosen LLVM
2121
- // name, this is a symlink).
2122
- //
2123
- // FIXME: Need to use the filesystem interfaces.
2124
- auto success = true ;
2125
- if (llvm::sys::fs::create_link (contents, output->getName ())) {
2126
- // On failure, we attempt to unlink the file and retry.
2127
- basic::sys::unlink (output->getName ().str ().c_str ());
2124
+ // Create the symbolic link (note that despite the poorly chosen LLVM
2125
+ // name, this is a symlink).
2126
+ //
2127
+ // FIXME: Need to use the filesystem interfaces.
2128
+ bsci.getDelegate ().commandStarted (this );
2129
+ auto success = true ;
2130
+ if (llvm::sys::fs::create_link (contents, output->getName ())) {
2131
+ // On failure, we attempt to unlink the file and retry.
2132
+ basic::sys::unlink (output->getName ().str ().c_str ());
2128
2133
2129
- if (llvm::sys::fs::create_link (contents, output->getName ())) {
2130
- getBuildSystem (bsci.getBuildEngine ()).error (
2131
- " " , " unable to create symlink at '" + output->getName () + " '" );
2132
- success = false ;
2133
- }
2134
+ if (llvm::sys::fs::create_link (contents, output->getName ())) {
2135
+ getBuildSystem (bsci.getBuildEngine ()).error (
2136
+ " " , " unable to create symlink at '" + output->getName () + " '" );
2137
+ success = false ;
2134
2138
}
2135
-
2136
- // Notify the client the command is complete.
2137
- bsci.getDelegate ().commandFinished (this );
2139
+ }
2140
+ bsci.getDelegate ().commandFinished (this );
2138
2141
2139
- // Process the result.
2140
- if (!success) {
2141
- bsci.getDelegate ().hadCommandFailure ();
2142
- bsci.taskIsComplete (task, BuildValue::makeFailedCommand ());
2143
- return ;
2144
- }
2142
+ // Process the result.
2143
+ if (!success) {
2144
+ return BuildValue::makeFailedCommand ();
2145
+ }
2145
2146
2146
- // Capture the *link* information of the output.
2147
- FileInfo outputInfo = output->getLinkInfo (
2148
- bsci.getDelegate ().getFileSystem ());
2147
+ // Capture the *link* information of the output.
2148
+ FileInfo outputInfo = output->getLinkInfo (
2149
+ bsci.getDelegate ().getFileSystem ());
2149
2150
2150
- // Complete with a successful result.
2151
- bsci.taskIsComplete (
2152
- task, BuildValue::makeSuccessfulCommand (outputInfo, getSignature ()));
2153
- };
2154
- bsci.addJob ({ this , std::move (fn) });
2151
+ // Complete with a successful result.
2152
+ return BuildValue::makeSuccessfulCommand (outputInfo, getSignature ());
2155
2153
}
2156
2154
2157
2155
public:
@@ -2428,7 +2426,6 @@ bool BuildSystem::build(StringRef name) {
2428
2426
2429
2427
void BuildSystem::cancel () {
2430
2428
if (impl) {
2431
- auto buildSystemImpl = static_cast <BuildSystemImpl*>(impl);
2432
- buildSystemImpl->getCommandInterface ().getExecutionQueue ().cancelAllJobs ();
2429
+ static_cast <BuildSystemImpl*>(impl)->cancel ();
2433
2430
}
2434
2431
}
0 commit comments