Skip to content

Commit b6380e5

Browse files
committed
FileWatcher race conditions fixed, postbuild skip on build fail
1 parent 9fa4859 commit b6380e5

7 files changed

Lines changed: 85 additions & 32 deletions

File tree

BeefLibs/corlib/src/IO/FileSystemWatcher.bf

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,23 @@ namespace System.IO
6565
using (sMonitor.Enter())
6666
{
6767
sWatcherDict.TryGetValue(id, out fileSysWatcher);
68-
}
6968

70-
if (fileSysWatcher == null)
71-
return;
72-
73-
switch (changeKind)
74-
{
75-
case .BfpFileChangeKind_Added:
76-
fileSysWatcher.OnCreated(scope String(fileName));
77-
case .BfpFileChangeKind_Modified:
78-
fileSysWatcher.OnChanged(scope String(fileName));
79-
case .BfpFileChangeKind_Removed:
80-
fileSysWatcher.OnDeleted(scope String(fileName));
81-
case .BfpFileChangeKind_Renamed:
82-
fileSysWatcher.OnRenamed(scope String(fileName), scope String(newName));
83-
case .BfpFileChangeKind_Failed:
84-
fileSysWatcher.OnError();
69+
if (fileSysWatcher == null)
70+
return;
71+
72+
switch (changeKind)
73+
{
74+
case .BfpFileChangeKind_Added:
75+
fileSysWatcher.OnCreated(scope String(fileName));
76+
case .BfpFileChangeKind_Modified:
77+
fileSysWatcher.OnChanged(scope String(fileName));
78+
case .BfpFileChangeKind_Removed:
79+
fileSysWatcher.OnDeleted(scope String(fileName));
80+
case .BfpFileChangeKind_Renamed:
81+
fileSysWatcher.OnRenamed(scope String(fileName), scope String(newName));
82+
case .BfpFileChangeKind_Failed:
83+
fileSysWatcher.OnError();
84+
}
8585
}
8686
}
8787

IDE/src/BuildContext.bf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace IDE
7979
mPtrSize = Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName);
8080
}
8181

82-
public CustomBuildCommandResult QueueProjectCustomBuildCommands(Project project, String targetPath, Project.BuildCommandTrigger trigger, List<String> cmdList)
82+
public CustomBuildCommandResult QueueProjectCustomBuildCommands(Project project, String targetPath, Project.BuildCommandTrigger trigger, List<String> cmdList, bool isPostBuild = false)
8383
{
8484
if (cmdList.IsEmpty)
8585
return .NoCommands;
@@ -182,6 +182,7 @@ namespace IDE
182182
let scriptCmd = new IDEApp.ScriptCmd();
183183
scriptCmd.mCmd = new String(customCmd);
184184
scriptCmd.mPath = new $"project {project.mProjectName}";
185+
scriptCmd.mSkipIfBuildFailed = (isPostBuild) && (!options.mBuildOptions.mPostBuildOnFailure);
185186
gApp.mExecutionQueue.Add(scriptCmd);
186187
continue;
187188
}
@@ -1768,7 +1769,7 @@ namespace IDE
17681769

17691770
if (WantsProjectBuild(project, compileKind))
17701771
{
1771-
switch (QueueProjectCustomBuildCommands(project, targetPath, compileKind.WantsRunAfter ? options.mBuildOptions.mBuildCommandsOnRun : options.mBuildOptions.mBuildCommandsOnCompile, options.mBuildOptions.mPostBuildCmds))
1772+
switch (QueueProjectCustomBuildCommands(project, targetPath, compileKind.WantsRunAfter ? options.mBuildOptions.mBuildCommandsOnRun : options.mBuildOptions.mBuildCommandsOnCompile, options.mBuildOptions.mPostBuildCmds, true))
17721773
{
17731774
case .NoCommands:
17741775
case .HadCommands:

IDE/src/FileWatcher.bf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ namespace IDE
387387
});
388388
fileSystemWatcher.OnCreated.Add(new (fileName) =>
389389
{
390-
CheckFileCreated(fileName);
390+
using (mFileChangeMonitor.Enter())
391+
{
392+
CheckFileCreated(fileName);
393+
}
391394
});
392395
fileSystemWatcher.OnDeleted.Add(new (fileName) =>
393396
{

IDE/src/IDEApp.bf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ namespace IDE
507507
{
508508
public String mCmd ~ delete _;
509509
public String mPath ~ delete _;
510+
public bool mSkipIfBuildFailed;
510511
}
511512

512513
public enum ArgsFileKind
@@ -533,6 +534,9 @@ namespace IDE
533534

534535
public class ExecutionInstance
535536
{
537+
public String mFileName ~ delete _;
538+
public String mArgs ~ delete _;
539+
536540
public SpawnedProcess mProcess /*~ delete _*/;
537541
public List<String> mDeferredOutput = new List<String>() ~ DeleteContainerAndItems!(_);
538542
public Stopwatch mStopwatch = new Stopwatch() ~ delete _;
@@ -9550,6 +9554,9 @@ namespace IDE
95509554

95519555
var executionInstance = new ExecutionInstance();
95529556

9557+
executionInstance.mFileName = new .(inFileName);
9558+
executionInstance.mArgs = new .(args);
9559+
95539560
#if BF_PLATFORM_WINDOWS
95549561
if (runFlags.HasFlag(.BatchCommand))
95559562
{
@@ -9809,9 +9816,9 @@ namespace IDE
98099816
}
98109817

98119818
if (executionInstance.mCanceled)
9812-
OutputLine("Execution Canceled");
9819+
OutputLine($"Execution of '{executionInstance.mFileName}' cancelled");
98139820
else if (failed)
9814-
OutputLine("Execution Failed");
9821+
OutputErrorLine($"Execution of '{executionInstance.mFileName}' with args '{executionInstance.mArgs}' exited with code '{executionInstance.mExitCode}'");
98159822
}
98169823

98179824
if (executionInstance.mTempFileName != null)
@@ -9911,7 +9918,12 @@ namespace IDE
99119918

99129919
if (let scriptCmd = next as ScriptCmd)
99139920
{
9914-
if (mBuildContext?.mScriptManager != null)
9921+
if ((buildFailed) && (scriptCmd.mSkipIfBuildFailed))
9922+
{
9923+
// Drop the command rather than running it against a missing or stale target
9924+
DeleteAndNullify!(scriptCmd.mCmd);
9925+
}
9926+
else if (mBuildContext?.mScriptManager != null)
99159927
{
99169928
if (scriptCmd.mCmd != null)
99179929
{

IDE/src/Project.bf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ namespace IDE
282282
if (!added)
283283
success = false;
284284
}
285+
else
286+
{
287+
mName.Set(newName);
288+
}
285289

286290
if ((didNameMatch) && (changePath))
287291
{
@@ -500,8 +504,11 @@ namespace IDE
500504

501505
if (mParentFolder.mParentFolder != null)
502506
{
503-
mParentFolder.mParentFolder.GetFullDisplayName(displayName);
504-
displayName.Append("/");
507+
if ((mParentFolder.mParentFolder.mName != null) && (!mParentFolder.mParentFolder.mName.IsEmpty))
508+
{
509+
mParentFolder.mParentFolder.GetFullDisplayName(displayName);
510+
displayName.Append("/");
511+
}
505512
}
506513
displayName.Append(mName);
507514
}
@@ -1226,6 +1233,8 @@ namespace IDE
12261233
[Reflect]
12271234
public BuildCommandTrigger mBuildCommandsOnRun = .Always;
12281235
[Reflect]
1236+
public bool mPostBuildOnFailure = false;
1237+
[Reflect]
12291238
public List<String> mLibPaths = new List<String>() ~ DeleteContainerAndItems!(_);
12301239
[Reflect]
12311240
public List<String> mLinkDependencies = new List<String>() ~ DeleteContainerAndItems!(_);
@@ -1354,6 +1363,7 @@ namespace IDE
13541363
Set!(newOptions.mBuildOptions.mLinkDependencies, mBuildOptions.mLinkDependencies);
13551364
Set!(newOptions.mBuildOptions.mPreBuildCmds, mBuildOptions.mPreBuildCmds);
13561365
Set!(newOptions.mBuildOptions.mPostBuildCmds, mBuildOptions.mPostBuildCmds);
1366+
Set!(newOptions.mBuildOptions.mPostBuildOnFailure, mBuildOptions.mPostBuildOnFailure);
13571367
Set!(newOptions.mBuildOptions.mCleanCmds, mBuildOptions.mCleanCmds);
13581368

13591369
Set!(newOptions.mBeefOptions.mPreprocessorMacros, mBeefOptions.mPreprocessorMacros);
@@ -1847,6 +1857,7 @@ namespace IDE
18471857
data.ConditionalAdd("StackSize", options.mBuildOptions.mStackSize, 0);
18481858
data.ConditionalAdd("BuildCommandsOnCompile", options.mBuildOptions.mBuildCommandsOnCompile, .Always);
18491859
data.ConditionalAdd("BuildCommandsOnRun", options.mBuildOptions.mBuildCommandsOnRun, .Always);
1860+
data.ConditionalAdd("PostBuildOnFailure", options.mBuildOptions.mPostBuildOnFailure, false);
18501861
WriteStrings("LibPaths", options.mBuildOptions.mLibPaths);
18511862
WriteStrings("LinkDependencies", options.mBuildOptions.mLinkDependencies);
18521863
WriteStrings("PreBuildCmds", options.mBuildOptions.mPreBuildCmds);
@@ -2223,6 +2234,7 @@ namespace IDE
22232234
options.mBuildOptions.mStackSize = data.GetInt("StackSize");
22242235
options.mBuildOptions.mBuildCommandsOnCompile = data.GetEnum<BuildCommandTrigger>("BuildCommandsOnCompile", .Always);
22252236
options.mBuildOptions.mBuildCommandsOnRun = data.GetEnum<BuildCommandTrigger>("BuildCommandsOnRun", .Always);
2237+
options.mBuildOptions.mPostBuildOnFailure = data.GetBool("PostBuildOnFailure", false);
22262238
ReadStrings("LibPaths", options.mBuildOptions.mLibPaths);
22272239
ReadStrings("LinkDependencies", options.mBuildOptions.mLinkDependencies);
22282240
ReadStrings("PreBuildCmds", options.mBuildOptions.mPreBuildCmds);

IDE/src/ui/ProjectPanel.bf

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,24 @@ namespace IDE.ui
472472
targetProjectFolder = targetProjectItem.mParentFolder;
473473
var targetListItem = mProjectToListViewMap[targetProjectFolder];
474474

475+
bool hasLinkMove = false;
476+
bool hasFileMove = false;
477+
475478
int moveCount = 0;
476479
int selectCount = 0;
477480
mListView.GetRoot().WithSelectedItems(scope [&] (selectedItem) =>
478481
{
479482
if (mListViewToProjectMap.GetValue(selectedItem) case .Ok(var sourceProjectItem))
480483
{
481484
if (sourceProjectItem.mParentFolder != targetProjectFolder)
485+
{
486+
if (sourceProjectItem.mIncludeKind == .Manual)
487+
hasLinkMove = true;
488+
else
489+
hasFileMove = true;
490+
482491
moveCount++;
492+
}
483493
}
484494
selectCount++;
485495
});
@@ -494,13 +504,13 @@ namespace IDE.ui
494504
Dialog dialog;
495505
if (selectCount == 1)
496506
{
497-
dialog = ThemeFactory.mDefault.CreateDialog("Move file to a new location?",
498-
scope $"Are you sure you want to move this file to '{targetDisplayName}'?");
507+
dialog = ThemeFactory.mDefault.CreateDialog(scope $"Move {hasFileMove ? "file" : "link"} to a new location?",
508+
scope $"Are you sure you want to move {hasFileMove ? "file" : "link"} file to '{targetDisplayName}'?");
499509
}
500510
else
501511
{
502-
dialog = ThemeFactory.mDefault.CreateDialog("Move files to a new location?",
503-
scope $"Are you sure you want to move these files to '{targetDisplayName}'?");
512+
dialog = ThemeFactory.mDefault.CreateDialog(scope $"Move {hasFileMove ? "files" : "links"} to a new location?",
513+
scope $"Are you sure you want to move these {hasFileMove ? "files" : "links"} to '{targetDisplayName}'?");
504514
}
505515
dialog.AddButton("Yes", new (evt) =>
506516
{
@@ -530,9 +540,12 @@ namespace IDE.ui
530540
}
531541
else
532542
{
533-
if (File.Move(sourcePath, destPath) case .Ok)
543+
bool isLink = sourceProjectFileItem.mIncludeKind == .Manual;
544+
545+
if ((isLink) || (File.Move(sourcePath, destPath) case .Ok))
534546
{
535-
gApp.FileRenamed(sourceProjectFileItem, sourcePath, destPath);
547+
if (!isLink)
548+
gApp.FileRenamed(sourceProjectFileItem, sourcePath, destPath);
536549

537550
if (targetProjectFolder != sourceProjectItem.mParentFolder)
538551
{
@@ -543,7 +556,10 @@ namespace IDE.ui
543556
targetListItem.mOpenButton.Open(true, false);
544557
targetProjectFolder.AddChildAtIndex(0, sourceProjectItem);
545558

546-
sourceProjectFileItem.RecalcPath();
559+
targetProjectFolder.mProject.SetChanged();
560+
561+
if (!isLink)
562+
sourceProjectFileItem.RecalcPath();
547563
}
548564
}
549565
else
@@ -2790,6 +2806,7 @@ namespace IDE.ui
27902806
new (evt) =>
27912807
{
27922808
//FinishRenameFolder(newName, false);
2809+
QueueSortItem(parentLvItem);
27932810
projectFolder.Rename(newName, false);
27942811
Sort();
27952812
}
@@ -2853,7 +2870,8 @@ namespace IDE.ui
28532870

28542871
if (!isWorkspaceFolder)
28552872
QueueSortItem(parentLvItem);
2856-
Sort();
2873+
if (didRename)
2874+
Sort();
28572875
}
28582876

28592877
SetFocus();
@@ -3133,6 +3151,11 @@ namespace IDE.ui
31333151
else
31343152
projectFolder.GetFullImportPath(path);
31353153
}
3154+
else if (var projectFileItem = projectItem as ProjectSource)
3155+
{
3156+
var filePath = projectFileItem.GetFullImportPath(.. scope .());
3157+
Path.GetDirectoryPath(filePath, path);
3158+
}
31363159
else
31373160
projectItem.mParentFolder.GetFullImportPath(path);
31383161

IDE/src/ui/ProjectProperties.bf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ namespace IDE.ui
714714
(listViewItem, propEntry) = AddPropertiesItem(root, "Clean Commands", "mBuildOptions.mCleanCmds");
715715
(listViewItem, propEntry) = AddPropertiesItem(root, "Build Commands on Compile", "mBuildOptions.mBuildCommandsOnCompile");
716716
(listViewItem, propEntry) = AddPropertiesItem(root, "Build Commands on Run", "mBuildOptions.mBuildCommandsOnRun");
717+
AddPropertiesItem(root, "Postbuild On Failure", "mBuildOptions.mPostBuildOnFailure",
718+
scope String[] ( "No", "Yes" ));
717719
}
718720

719721
void PopulateDependencyOptions()

0 commit comments

Comments
 (0)