Skip to content

Commit

Permalink
Add defensive checks to deps.json and runtimeconfig.json predictions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm authored Oct 25, 2024
1 parent 58b6802 commit 20f0e97
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ public void PredictInputsAndOutputs(
return;
}

predictionReporter.ReportInputFile(projectInstance.GetPropertyValue(ProjectAssetsFilePropertyName));
predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(ProjectDepsFilePathPropertyName));
string projectAssetsFilePropertyName = projectInstance.GetPropertyValue(ProjectAssetsFilePropertyName);
if (!string.IsNullOrEmpty(projectAssetsFilePropertyName))
{
predictionReporter.ReportInputFile(projectAssetsFilePropertyName);
}

string projectDepsFilePath = projectInstance.GetPropertyValue(ProjectDepsFilePathPropertyName);
if (!string.IsNullOrEmpty(projectDepsFilePath))
{
predictionReporter.ReportOutputFile(projectDepsFilePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ public void PredictInputsAndOutputs(
return;
}

predictionReporter.ReportInputFile(projectInstance.GetPropertyValue(GenerateBuildDependencyFilePredictor.ProjectAssetsFilePropertyName));
string projectAssetsFilePropertyName = projectInstance.GetPropertyValue(GenerateBuildDependencyFilePredictor.ProjectAssetsFilePropertyName);
if (!string.IsNullOrEmpty(projectAssetsFilePropertyName))
{
predictionReporter.ReportInputFile(projectAssetsFilePropertyName);
}

string publishDepsFilePath = GetEffectivePublishDepsFilePath(projectInstance);
string intermediateDepsFilePath = publishDepsFilePath is not null
string intermediateDepsFilePath = !string.IsNullOrEmpty(publishDepsFilePath)
? publishDepsFilePath
: projectInstance.GetPropertyValue(IntermediateOutputPathPropertyName) + projectInstance.GetPropertyValue(ProjectDepsFileNamePropertyName);
predictionReporter.ReportOutputFile(intermediateDepsFilePath);
if (!string.IsNullOrEmpty(intermediateDepsFilePath))
{
predictionReporter.ReportOutputFile(intermediateDepsFilePath);
}

// Note: GetCopyToPublishDirectoryItemsGraphPredictor will predict the final (published) location for the publish deps file since that's the target which does that copy.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,25 @@ public void PredictInputsAndOutputs(
}

string userRuntimeConfig = projectInstance.GetPropertyValue(UserRuntimeConfigPropertyName);
string userRuntimeConfigFullPath = Path.Combine(projectInstance.Directory, userRuntimeConfig);
if (File.Exists(userRuntimeConfigFullPath))
if (!string.IsNullOrEmpty(userRuntimeConfig))
{
predictionReporter.ReportInputFile(userRuntimeConfigFullPath);
string userRuntimeConfigFullPath = Path.Combine(projectInstance.Directory, userRuntimeConfig);
if (File.Exists(userRuntimeConfigFullPath))
{
predictionReporter.ReportInputFile(userRuntimeConfigFullPath);
}
}

predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(ProjectRuntimeConfigFilePathPropertyName));
predictionReporter.ReportOutputFile(projectInstance.GetPropertyValue(ProjectRuntimeConfigDevFilePathPropertyName));
string projectRuntimeConfigFilePath = projectInstance.GetPropertyValue(ProjectRuntimeConfigFilePathPropertyName);
if (!string.IsNullOrEmpty(projectRuntimeConfigFilePath))
{
predictionReporter.ReportOutputFile(projectRuntimeConfigFilePath);
}

string projectRuntimeConfigDevFilePath = projectInstance.GetPropertyValue(ProjectRuntimeConfigDevFilePathPropertyName);
if (!string.IsNullOrEmpty(projectRuntimeConfigDevFilePath))
{
predictionReporter.ReportOutputFile(projectRuntimeConfigDevFilePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,28 @@ private static void PredictInputsAndOutputs(
if (dependency.ProjectInstance.GetPropertyValue(GenerateBuildDependencyFilePredictor.GenerateDependencyFilePropertyName).Equals("true", StringComparison.OrdinalIgnoreCase))
{
string projectDepsFilePath = dependency.ProjectInstance.GetPropertyValue(GenerateBuildDependencyFilePredictor.ProjectDepsFilePathPropertyName);
predictionReporter.ReportInputFile(projectDepsFilePath);
predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(projectDepsFilePath)));
if (!string.IsNullOrEmpty(projectDepsFilePath))
{
predictionReporter.ReportInputFile(projectDepsFilePath);
predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(projectDepsFilePath)));
}
}

if (dependency.ProjectInstance.GetPropertyValue(GenerateRuntimeConfigurationFilesPredictor.GenerateRuntimeConfigurationFilesPropertyName).Equals("true", StringComparison.OrdinalIgnoreCase))
{
string projectRuntimeConfigFilePath = dependency.ProjectInstance.GetPropertyValue(GenerateRuntimeConfigurationFilesPredictor.ProjectRuntimeConfigFilePathPropertyName);
predictionReporter.ReportInputFile(projectRuntimeConfigFilePath);
predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(projectRuntimeConfigFilePath)));
if (!string.IsNullOrEmpty(projectRuntimeConfigFilePath))
{
predictionReporter.ReportInputFile(projectRuntimeConfigFilePath);
predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(projectRuntimeConfigFilePath)));
}

string projectRuntimeConfigDevFilePath = dependency.ProjectInstance.GetPropertyValue(GenerateRuntimeConfigurationFilesPredictor.ProjectRuntimeConfigDevFilePathPropertyName);
predictionReporter.ReportInputFile(projectRuntimeConfigDevFilePath);
predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(projectRuntimeConfigDevFilePath)));
if (!string.IsNullOrEmpty(projectRuntimeConfigDevFilePath))
{
predictionReporter.ReportInputFile(projectRuntimeConfigDevFilePath);
predictionReporter.ReportOutputFile(Path.Combine(outDir, Path.GetFileName(projectRuntimeConfigDevFilePath)));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ private static void ReportCopyToPublishDirectoryItems(
if (GeneratePublishDependencyFilePredictor.ShouldUseBuildDependencyFile(projectInstance))
{
string projectDepsFilePath = projectInstance.GetPropertyValue(GenerateBuildDependencyFilePredictor.ProjectDepsFilePathPropertyName);
predictionReporter.ReportInputFile(projectDepsFilePath);
predictionReporter.ReportOutputFile(Path.Combine(publishDir, Path.GetFileName(projectDepsFilePath)));
if (!string.IsNullOrEmpty(projectDepsFilePath))
{
predictionReporter.ReportInputFile(projectDepsFilePath);
predictionReporter.ReportOutputFile(Path.Combine(publishDir, Path.GetFileName(projectDepsFilePath)));
}
}
else
{
string publishDepsFilePath = GeneratePublishDependencyFilePredictor.GetEffectivePublishDepsFilePath(projectInstance);
if (publishDepsFilePath is not null)
if (!string.IsNullOrEmpty(publishDepsFilePath))
{
predictionReporter.ReportInputFile(publishDepsFilePath);
predictionReporter.ReportOutputFile(Path.Combine(publishDir, Path.GetFileName(publishDepsFilePath)));
Expand All @@ -106,8 +109,11 @@ private static void ReportCopyToPublishDirectoryItems(
if (projectInstance.GetPropertyValue(GenerateRuntimeConfigurationFilesPredictor.GenerateRuntimeConfigurationFilesPropertyName).Equals("true", StringComparison.OrdinalIgnoreCase))
{
string projectRuntimeConfigFilePath = projectInstance.GetPropertyValue(GenerateRuntimeConfigurationFilesPredictor.ProjectRuntimeConfigFilePathPropertyName);
predictionReporter.ReportInputFile(projectRuntimeConfigFilePath);
predictionReporter.ReportOutputFile(Path.Combine(publishDir, Path.GetFileName(projectRuntimeConfigFilePath)));
if (!string.IsNullOrEmpty(projectRuntimeConfigFilePath))
{
predictionReporter.ReportInputFile(projectRuntimeConfigFilePath);
predictionReporter.ReportOutputFile(Path.Combine(publishDir, Path.GetFileName(projectRuntimeConfigFilePath)));
}
}
}
}
Expand Down

0 comments on commit 20f0e97

Please sign in to comment.