Skip to content

Commit

Permalink
Set intermediate path sooner (#74229)
Browse files Browse the repository at this point in the history
Pulled from #70913 (thanks @davidwengier!)

Razor uses the intermediate path for project key. Now that we're removing the file system from being involved in communicating project data, we need to make sure we're communicating the right data.

This fixes issues found in dotnet/vscode-csharp#7273 and will unblock that insertion
  • Loading branch information
ryzngard authored Jul 2, 2024
1 parent 8814b23 commit 863962d
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core/Interactive/InteractiveSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private Project CreateSubmissionProjectNoLock(Solution solution, ProjectId newSu
name: name,
assemblyName: name,
language: languageName,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: SourceHashAlgorithms.Default,
isSubmission: true),
compilationOptions: compilationOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public MetadataAsSourceGeneratedFileInfo(string rootPath, Workspace sourceWorksp
name: AssemblyIdentity.Name,
assemblyName: AssemblyIdentity.Name,
language: LanguageName,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: ChecksumAlgorithm),
compilationOptions: compilationOptions,
parseOptions: _parseOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ internal sealed class PdbSourceDocumentMetadataAsSourceFileProvider(
name: $"{assemblyName} ({assemblyVersion})",
assemblyName: assemblyName,
language: languageName,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: checksumAlgorithm),
compilationOptions: compilationOptions,
parseOptions: parseOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static ProjectInfo CreateMiscellaneousProjectInfoForDocument(
name: FeaturesResources.Miscellaneous_Files,
assemblyName: assemblyName,
language: languageInformation.LanguageName,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: checksumAlgorithm,
// Miscellaneous files projects are never fully loaded since, by definition, it won't know
// what the full set of information is except when the file is script code.
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Lsif/Generator/CompilerInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static async Task<Project> CreateFromInvocationInfoAsync(CompilerInvocati
name: Path.GetFileNameWithoutExtension(invocationInfo.ProjectFilePath),
assemblyName: parsedCommandLine.CompilationName!,
language: languageName,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: parsedCommandLine.ChecksumAlgorithm,
filePath: invocationInfo.ProjectFilePath,
outputFilePath: parsedCommandLine.OutputFileName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void CreateProjects(EditScript<SyntaxNode>[] editScripts, AdhocWorkspace
name: "project",
assemblyName: "project",
language: LanguageName,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
filePath: Path.Combine(TempRoot.Root, "project" + ProjectFileExtension),
checksumAlgorithm: SourceHashAlgorithms.Default));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ private async Task<bool> LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, T
else
{
var projectSystemName = $"{projectPath} (${loadedProjectInfo.TargetFramework})";
var projectCreationInfo = new ProjectSystemProjectCreationInfo { AssemblyName = projectSystemName, FilePath = projectPath };
var projectCreationInfo = new ProjectSystemProjectCreationInfo
{
AssemblyName = projectSystemName,
FilePath = projectPath,
CompilationOutputAssemblyFilePath = loadedProjectInfo.IntermediateOutputFilePath
};

var projectSystemProject = await _workspaceFactory.ProjectSystemProjectFactory.CreateAndAddToWorkspaceAsync(
projectSystemName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void Dispose()
_projectSystemProject.DisplayName = projectDisplayName;
_projectSystemProject.OutputFilePath = newProjectInfo.OutputFilePath;
_projectSystemProject.OutputRefFilePath = newProjectInfo.OutputRefFilePath;
_projectSystemProject.CompilationOutputAssemblyFilePath = newProjectInfo.IntermediateOutputFilePath;

if (newProjectInfo.TargetFrameworkIdentifier != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ public async Task SetBuildSystemPropertiesAsync(IReadOnlyDictionary<string, stri
var disposableBatchScope = await _project.CreateBatchScopeAsync(cancellationToken).ConfigureAwait(false);
await using var _ = disposableBatchScope.ConfigureAwait(false);

string? fileDirectory = null;

foreach (var (name, value) in properties)
{
var valueOrNull = string.IsNullOrEmpty(value) ? null : value;

switch (name)
{
case "AssemblyName": _project.AssemblyName = value; break;
case "IntermediateAssembly": _project.CompilationOutputAssemblyFilePath = GetFullyQualifiedPath(valueOrNull); break;
case "MaxSupportedLangVersion": _project.MaxLangVersion = value; break;
case "RootNamespace": _project.DefaultNamespace = valueOrNull; break;
case "RunAnalyzers": _project.RunAnalyzers = bool.Parse(valueOrNull ?? bool.TrueString); break;
Expand All @@ -170,15 +173,18 @@ public async Task SetBuildSystemPropertiesAsync(IReadOnlyDictionary<string, stri
}
}

// Workaround for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1830960
_project.CompilationOutputAssemblyFilePath = _project.OutputFilePath;

string? GetFullyQualifiedPath(string? propertyValue)
{
Contract.ThrowIfNull(_project.FilePath, "We don't have a project path at this point.");

// Path.Combine doesn't check if the first parameter is an absolute path to a file instead of a directory,
// so make sure to use the directory from the _project.FilePath. If the propertyValue is an absolute
// path that will still be used, but if it's a relative path it will correctly construct the full path.
fileDirectory ??= Path.GetDirectoryName(_project.FilePath);
Contract.ThrowIfNull(fileDirectory);

if (propertyValue is not null)
return Path.Combine(_project.FilePath, propertyValue);
return Path.Combine(fileDirectory, propertyValue);
else
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static ProjectInfo CreateProjectInfo(string projectName, string language
name: projectName,
assemblyName: projectName,
language,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm),
documents: docInfos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private Document AddDocumentToProject(string filePath, string language, string p
name: projectName,
assemblyName: projectName,
language,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: SourceHashAlgorithms.Default));

OnProjectAdded(projectInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private Task<ProjectInfo> CreateProjectInfoAsync(ProjectFileInfo projectFileInfo
name: projectName,
assemblyName: assemblyName,
language: language,
compilationOutputFilePaths: new CompilationOutputInfo(projectFileInfo.IntermediateOutputFilePath),
compilationOutputInfo: new CompilationOutputInfo(projectFileInfo.IntermediateOutputFilePath),
checksumAlgorithm: SourceHashAlgorithms.Default,
filePath: projectPath),
compilationOptions: compilationOptions,
Expand Down Expand Up @@ -370,7 +370,7 @@ private Task<ProjectInfo> CreateProjectInfoAsync(ProjectFileInfo projectFileInfo
projectName,
assemblyName,
language,
compilationOutputFilePaths: new CompilationOutputInfo(projectFileInfo.IntermediateOutputFilePath),
compilationOutputInfo: new CompilationOutputInfo(projectFileInfo.IntermediateOutputFilePath),
checksumAlgorithm: commandLineArgs.ChecksumAlgorithm,
filePath: projectPath,
outputFilePath: projectFileInfo.OutputFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static ProjectInfo CreateProjectInfo(string projectName, string language,
name: projectName,
assemblyName: assemblyName,
language: language,
compilationOutputFilePaths: new CompilationOutputInfo(commandLineArguments.OutputFileName != null ? commandLineArguments.GetOutputFilePath(commandLineArguments.OutputFileName) : null),
compilationOutputInfo: new CompilationOutputInfo(commandLineArguments.OutputFileName != null ? commandLineArguments.GetOutputFilePath(commandLineArguments.OutputFileName) : null),
checksumAlgorithm: commandLineArguments.ChecksumAlgorithm),
compilationOptions: commandLineArguments.CompilationOptions
.WithXmlReferenceResolver(xmlFileResolver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ internal ProjectSystemProject(
string assemblyName,
CompilationOptions? compilationOptions,
string? filePath,
ParseOptions? parseOptions)
ParseOptions? parseOptions,
string? compilationOutputAssemblyFilePath)
{
_projectSystemProjectFactory = projectSystemProjectFactory;
_hostInfo = hostInfo;
Expand Down Expand Up @@ -196,6 +197,7 @@ internal ProjectSystemProject(
_compilationOptions = compilationOptions;
_filePath = filePath;
_parseOptions = parseOptions;
_compilationOutputAssemblyFilePath = compilationOutputAssemblyFilePath;

var watchedDirectories = GetWatchedDirectories(language, filePath);
_documentFileChangeContext = _projectSystemProjectFactory.FileChangeWatcher.CreateContext(watchedDirectories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class ProjectSystemProjectCreationInfo
public CompilationOptions? CompilationOptions { get; set; }
public string? FilePath { get; set; }
public ParseOptions? ParseOptions { get; set; }
public string? CompilationOutputAssemblyFilePath { get; set; }

public Guid TelemetryId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public async Task<ProjectSystemProject> CreateAndAddToWorkspaceAsync(string proj
assemblyName,
creationInfo.CompilationOptions,
creationInfo.FilePath,
creationInfo.ParseOptions);
creationInfo.ParseOptions,
creationInfo.CompilationOutputAssemblyFilePath);

var versionStamp = creationInfo.FilePath != null
? VersionStamp.Create(File.GetLastWriteTimeUtc(creationInfo.FilePath))
Expand All @@ -107,7 +108,7 @@ public async Task<ProjectSystemProject> CreateAndAddToWorkspaceAsync(string proj
name: projectSystemName,
assemblyName,
language,
compilationOutputFilePaths: default, // will be updated when command line is set
compilationOutputInfo: new(creationInfo.CompilationOutputAssemblyFilePath),
SourceHashAlgorithms.Default, // will be updated when command line is set
filePath: creationInfo.FilePath,
telemetryId: creationInfo.TelemetryId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static ProjectInfo Create(
name ?? throw new ArgumentNullException(nameof(name)),
assemblyName ?? throw new ArgumentNullException(nameof(assemblyName)),
language ?? throw new ArgumentNullException(nameof(language)),
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: SourceHashAlgorithm.Sha1,
defaultNamespace: null,
filePath: filePath,
Expand Down Expand Up @@ -401,7 +401,7 @@ internal sealed class ProjectAttributes(
string name,
string assemblyName,
string language,
CompilationOutputInfo compilationOutputFilePaths,
CompilationOutputInfo compilationOutputInfo,
SourceHashAlgorithm checksumAlgorithm,
string? defaultNamespace = null,
string? filePath = null,
Expand Down Expand Up @@ -460,7 +460,7 @@ internal sealed class ProjectAttributes(
/// <summary>
/// Paths to the compiler output files.
/// </summary>
public CompilationOutputInfo CompilationOutputInfo { get; } = compilationOutputFilePaths;
public CompilationOutputInfo CompilationOutputInfo { get; } = compilationOutputInfo;

/// <summary>
/// The default namespace of the project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public ProjectInfo ToProjectInfo()
name: Name,
assemblyName: AssemblyName,
language: Language,
compilationOutputFilePaths: default,
compilationOutputInfo: default,
checksumAlgorithm: Text.SourceHashAlgorithms.Default,
defaultNamespace: DefaultNamespace,
filePath: FilePath,
Expand Down

0 comments on commit 863962d

Please sign in to comment.