public void SaveIntermediateModel(IncrementalBuildContext incrementalContext)
{
if (!ShouldTraceIncrementalInfo)
{
return;
}
var processor = (ISupportIncrementalDocumentProcessor)Processor;
var mi = incrementalContext.GetModelLoadInfo(this);
var lmm = incrementalContext.GetLastIntermediateModelManifest(this);
var cmm = incrementalContext.GetCurrentIntermediateModelManifest(this);
foreach (var pair in mi)
{
IncrementalUtility.RetryIO(() =>
{
string fileName = IncrementalUtility.GetRandomEntry(incrementalContext.BaseDir);
if (pair.Value == null)
{
if (lmm == null)
{
throw new BuildCacheException($"Full build hasn't loaded model {pair.Key}");
}
string lfn;
if (!lmm.Models.TryGetValue(pair.Key, out lfn))
{
throw new BuildCacheException($"Last build hasn't loaded model {pair.Key}");
}
File.Move(Path.Combine(incrementalContext.LastBaseDir, lfn), Path.Combine(incrementalContext.BaseDir, fileName));
}
else
{
var key = TypeForwardedToRelativePath.NormalizedWorkingFolder + pair.Key;
var model = Models.Find(m => m.Key == key);
using (var stream = File.Create(Path.Combine(incrementalContext.BaseDir, fileName)))
{
processor.SaveIntermediateModel(model, stream);
}
}
cmm.Models.Add(pair.Key, fileName);
});
}
}