mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-30 05:15:59 +02:00
Improved comptime rebuilds when files and directories change
This commit is contained in:
parent
af8bd5a813
commit
915a8df50e
10 changed files with 236 additions and 70 deletions
|
@ -55,6 +55,12 @@ namespace IDE.Compiler
|
|||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern char8* BfCompiler_GetAutocompleteInfo(void* bfCompiler);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern char8* BfCompiler_GetRebuildFileSet(void* bfCompiler);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern void BfCompiler_FileChanged(void* bfCompiler, char8* str);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
static extern char8* BfCompiler_GetSymbolReferences(void* bfCompiler, void* bfPassInstance, void* bfResolvePassData);
|
||||
|
||||
|
@ -200,10 +206,17 @@ namespace IDE.Compiler
|
|||
public int32 mHotIdx;
|
||||
}
|
||||
|
||||
class RebuildFileChangedCommand : Command
|
||||
{
|
||||
public String mDir = new .() ~ delete _;
|
||||
}
|
||||
|
||||
|
||||
public void* mNativeBfCompiler;
|
||||
public bool mIsResolveOnly;
|
||||
public BfSystem mBfSystem;
|
||||
bool mWantsRemoveOldData;
|
||||
public Dictionary<String, String> mRebuildWatchingFiles = new .() ~ delete _;
|
||||
|
||||
public this(void* nativeBfCompiler)
|
||||
{
|
||||
|
@ -214,6 +227,13 @@ namespace IDE.Compiler
|
|||
{
|
||||
BfCompiler_Delete(mNativeBfCompiler);
|
||||
mNativeBfCompiler = null;
|
||||
|
||||
for (var kv in mRebuildWatchingFiles)
|
||||
{
|
||||
gApp.mFileWatcher.RemoveWatch(kv.key, kv.value);
|
||||
delete kv.key;
|
||||
delete kv.value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Compile(BfPassInstance passInstance, String outputDirectory)
|
||||
|
@ -249,6 +269,12 @@ namespace IDE.Compiler
|
|||
outAutocompleteInfo.Append(StringView(result));
|
||||
}
|
||||
|
||||
public void GetRebuildFileSet(String outDirInfo)
|
||||
{
|
||||
char8* result = BfCompiler_GetRebuildFileSet(mNativeBfCompiler);
|
||||
outDirInfo.Append(StringView(result));
|
||||
}
|
||||
|
||||
public void GetSymbolReferences(BfPassInstance passInstance, BfResolvePassData resolvePassData, String outSymbolReferences)
|
||||
{
|
||||
char8* result = BfCompiler_GetSymbolReferences(mNativeBfCompiler, passInstance.mNativeBfPassInstance, resolvePassData.mNativeResolvePassData);
|
||||
|
@ -531,6 +557,7 @@ namespace IDE.Compiler
|
|||
{
|
||||
var compileCommand = (CompileCommand)command;
|
||||
Compile(passInstance, compileCommand.mOutputDirectory);
|
||||
UpdateRebuildFileWatches();
|
||||
mBfSystem.RemoveOldParsers();
|
||||
mBfSystem.RemoveOldData();
|
||||
}
|
||||
|
@ -547,7 +574,8 @@ namespace IDE.Compiler
|
|||
// If we get canceled then try again after waiting a couple updates
|
||||
if (!ClassifySource(passInstance, null, resolvePassData, null))
|
||||
QueueDeferredResolveAll();
|
||||
|
||||
UpdateRebuildFileWatches();
|
||||
|
||||
delete resolvePassData;
|
||||
wantsRemoveOldData = true;
|
||||
passKind = .Classify;
|
||||
|
@ -570,6 +598,11 @@ namespace IDE.Compiler
|
|||
{
|
||||
mWantsActiveViewRefresh = true;
|
||||
}
|
||||
|
||||
if (var dirChangedCommand = command as RebuildFileChangedCommand)
|
||||
{
|
||||
BfCompiler_FileChanged(mNativeBfCompiler, dirChangedCommand.mDir);
|
||||
}
|
||||
}
|
||||
|
||||
mBfSystem.Unlock();
|
||||
|
@ -842,5 +875,54 @@ namespace IDE.Compiler
|
|||
{
|
||||
return BfCompiler_GetLastHadComptimeRebuilds(mNativeBfCompiler);
|
||||
}
|
||||
|
||||
void UpdateRebuildFileWatches()
|
||||
{
|
||||
HashSet<StringView> curWatches = scope .();
|
||||
|
||||
var rebuildDirStr = GetRebuildFileSet(.. scope .());
|
||||
for (var dir in rebuildDirStr.Split('\n', .RemoveEmptyEntries))
|
||||
{
|
||||
curWatches.Add(dir);
|
||||
if (mRebuildWatchingFiles.TryAddAlt(dir, var keyPtr, var valuePtr))
|
||||
{
|
||||
*keyPtr = new String(dir);
|
||||
String watchFile = *valuePtr = new .();
|
||||
watchFile.Append(dir);
|
||||
if ((watchFile.EndsWith(Path.DirectorySeparatorChar)) || (watchFile.EndsWith(Path.AltDirectorySeparatorChar)))
|
||||
watchFile.Append("*");
|
||||
gApp.mFileWatcher.WatchFile(watchFile, watchFile);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> oldKeys = scope .();
|
||||
for (var kv in mRebuildWatchingFiles)
|
||||
{
|
||||
if (!curWatches.Contains(kv.key))
|
||||
{
|
||||
gApp.mFileWatcher.RemoveWatch(kv.key, kv.value);
|
||||
oldKeys.Add(kv.key);
|
||||
}
|
||||
}
|
||||
|
||||
for (var key in oldKeys)
|
||||
{
|
||||
var kv = mRebuildWatchingFiles.GetAndRemove(key).Value;
|
||||
delete kv.key;
|
||||
delete kv.value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasRebuildFileWatches()
|
||||
{
|
||||
return !mRebuildWatchingFiles.IsEmpty;
|
||||
}
|
||||
|
||||
public void AddChangedDirectory(StringView str)
|
||||
{
|
||||
var dirChangedCommand = new RebuildFileChangedCommand();
|
||||
dirChangedCommand.mDir.Set(str);
|
||||
QueueCommand(dirChangedCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ namespace IDE
|
|||
Dictionary<String, DepInfo> mWatchedFiles = new Dictionary<String, DepInfo>() ~ DeleteDictionaryAndKeysAndValues!(_); // Including ref count
|
||||
List<ChangeRecord> mChangeList = new .() ~ DeleteContainerAndItems!(_);
|
||||
Dictionary<String, ChangeRecord> mChangeMap = new .() ~ delete _;
|
||||
List<Object> mDependencyChangeList = new List<Object>() ~ delete _;
|
||||
HashSet<Object> mDependencyChangeSet = new .() ~ delete _;
|
||||
List<Object> mDependencyChangeList = new .() ~ delete _;
|
||||
List<QueuedRefreshEntry> mQueuedRefreshWatcherEntries = new List<QueuedRefreshEntry>() ~ delete _;
|
||||
public Monitor mMonitor = new Monitor() ~ delete _;
|
||||
List<QueuedFileChange> mQueuedFileChanges = new List<QueuedFileChange>() ~ DeleteContainerAndItems!(_);
|
||||
|
@ -86,6 +87,14 @@ namespace IDE
|
|||
{
|
||||
bool isDirectory = filePath.EndsWith(Path.DirectorySeparatorChar);
|
||||
|
||||
if (!filePath.EndsWith('*'))
|
||||
{
|
||||
String starPath = Path.GetDirectoryPath(filePath, .. scope .());
|
||||
starPath.Append(Path.DirectorySeparatorChar);
|
||||
starPath.Append('*');
|
||||
FileChanged(starPath, null, .Changed);
|
||||
}
|
||||
|
||||
var newPath;
|
||||
if (isDirectory)
|
||||
{
|
||||
|
@ -194,9 +203,10 @@ namespace IDE
|
|||
{
|
||||
if (var tryProjectItem = dep as ProjectItem)
|
||||
projectItem = tryProjectItem;
|
||||
if ((dep != null) && (!mDependencyChangeList.Contains(dep)))
|
||||
{
|
||||
mDependencyChangeList.Add(dep);
|
||||
if (dep != null)
|
||||
{
|
||||
if (mDependencyChangeSet.Add(dep))
|
||||
mDependencyChangeList.Add(dep);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -535,7 +545,8 @@ namespace IDE
|
|||
String outKey;
|
||||
if (!mWatchedFiles.TryGet(fixedFilePath, out outKey, out depInfo))
|
||||
return;
|
||||
depInfo.mDependentObjects.Remove(dependentObject);
|
||||
if (dependentObject != null)
|
||||
depInfo.mDependentObjects.Remove(dependentObject);
|
||||
|
||||
if (depInfo.mDependentObjects.Count == 0)
|
||||
{
|
||||
|
@ -553,7 +564,8 @@ namespace IDE
|
|||
delete depInfo;
|
||||
}
|
||||
|
||||
mDependencyChangeList.Remove(dependentObject);
|
||||
if (dependentObject != null)
|
||||
mDependencyChangeSet.Remove(dependentObject);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -644,10 +656,10 @@ namespace IDE
|
|||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
if (mDependencyChangeList.Count == 0)
|
||||
if (mDependencyChangeList.IsEmpty)
|
||||
return null;
|
||||
Object dep = mDependencyChangeList[0];
|
||||
mDependencyChangeList.RemoveAt(0);
|
||||
Object dep = mDependencyChangeList.PopFront();
|
||||
mDependencyChangeSet.Remove(dep);
|
||||
return dep;
|
||||
}
|
||||
}
|
||||
|
@ -656,7 +668,7 @@ namespace IDE
|
|||
{
|
||||
using (mMonitor.Enter())
|
||||
{
|
||||
mDependencyChangeList.Add(obj);
|
||||
mDependencyChangeSet.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13032,6 +13032,14 @@ namespace IDE
|
|||
}
|
||||
else if (changeType == .Failed)
|
||||
{
|
||||
if (mBfResolveCompiler?.HasRebuildFileWatches() == true)
|
||||
{
|
||||
mBfResolveCompiler.AddChangedDirectory("*");
|
||||
mBfResolveCompiler.QueueDeferredResolveAll();
|
||||
}
|
||||
if (mBfBuildCompiler?.HasRebuildFileWatches() == true)
|
||||
mBfBuildCompiler.AddChangedDirectory("*");
|
||||
|
||||
if (mProjectPanel != null)
|
||||
{
|
||||
if (let projectFolder = projectItem as ProjectFolder)
|
||||
|
@ -13115,13 +13123,29 @@ namespace IDE
|
|||
|
||||
while (true)
|
||||
{
|
||||
var dep = mFileWatcher.PopChangedDependency();
|
||||
if (dep == null)
|
||||
break;
|
||||
var projectSourceDep = dep as ProjectSource;
|
||||
if (projectSourceDep != null)
|
||||
using (mFileWatcher.mMonitor.Enter())
|
||||
{
|
||||
// We process these projectSources directly from the filename below
|
||||
var dep = mFileWatcher.PopChangedDependency();
|
||||
if (dep == null)
|
||||
break;
|
||||
var projectSourceDep = dep as ProjectSource;
|
||||
if (projectSourceDep != null)
|
||||
{
|
||||
// We process these projectSources directly from the filename below
|
||||
}
|
||||
if (var path = dep as String)
|
||||
{
|
||||
StringView usePath = path;
|
||||
if (usePath.EndsWith('*'))
|
||||
usePath.RemoveFromEnd(1);
|
||||
if (mBfResolveCompiler != null)
|
||||
{
|
||||
mBfResolveCompiler.AddChangedDirectory(usePath);
|
||||
mBfResolveCompiler.QueueDeferredResolveAll();
|
||||
}
|
||||
if (mBfBuildCompiler != null)
|
||||
mBfBuildCompiler.AddChangedDirectory(usePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue