Updated ProjectModel

- Added PackOptions, RuntimeOptions, PublishOptions and updated CompilationOptions
 - Added IncludeFilesResolver to parse include, exclude patterns
 - Added compile, embed and copyToOutput to compilationOptions
 - Renamed compilationOptions to buildOptions
 - Moved compilerName into buildOptions
 - This change is backwards compatible
 - Added warnings to be shown when the old schema is used
 - Handled diagnostic messages in ProjectReader
 - Added unit and end to end tests
This commit is contained in:
Ajay Bhargav Baaskaran 2016-04-11 19:25:28 -07:00
parent 1f0910ebcc
commit 44fd8bc2de
49 changed files with 1600 additions and 277 deletions

View file

@ -9,6 +9,7 @@ using System.Linq;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.DotNet.ProjectModel.Resources;
using Microsoft.DotNet.Tools.Common;
@ -49,11 +50,29 @@ namespace Microsoft.DotNet.Tools.Compiler
// used in incremental compilation
public static List<NonCultureResgenIO> GetNonCultureResources(Project project, string intermediateOutputPath)
{
return
return
(from resourceFile in project.Files.ResourceFiles
let inputFile = resourceFile.Key
let inputFile = resourceFile.Key
where string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(inputFile))
let metadataName = GetResourceFileMetadataName(project, resourceFile.Key, resourceFile.Value)
let outputFile = ResourceUtility.IsResxFile(inputFile) ? Path.Combine(intermediateOutputPath, metadataName) : null
select new NonCultureResgenIO(inputFile, outputFile, metadataName)
).ToList();
}
// used in incremental compilation
public static List<NonCultureResgenIO> GetNonCultureResourcesFromIncludeEntries(
Project project,
string intermediateOutputPath,
CommonCompilerOptions compilationOptions)
{
var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilationOptions.EmbedInclude, "/", diagnostics: null);
return
(from resourceFile in includeFiles
let inputFile = resourceFile.SourcePath
where string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(inputFile))
let metadataName = GetResourceFileMetadataName(project, resourceFile)
let target = resourceFile.IsCustomTarget ? resourceFile.TargetPath : null
let metadataName = GetResourceFileMetadataName(project, resourceFile.SourcePath, target)
let outputFile = ResourceUtility.IsResxFile(inputFile) ? Path.Combine(intermediateOutputPath, metadataName) : null
select new NonCultureResgenIO(inputFile, outputFile, metadataName)
).ToList();
@ -78,9 +97,29 @@ namespace Microsoft.DotNet.Tools.Compiler
{
return
(from resourceFileGroup in project.Files.ResourceFiles.GroupBy(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.Key))
let culture = resourceFileGroup.Key
where !string.IsNullOrEmpty(culture)
let inputFileToMetadata = resourceFileGroup.ToDictionary(r => r.Key, r => GetResourceFileMetadataName(project, r.Key, r.Value))
let resourceOutputPath = Path.Combine(outputPath, culture)
let outputFile = Path.Combine(resourceOutputPath, project.Name + ".resources.dll")
select new CultureResgenIO(culture, inputFileToMetadata, outputFile)
).ToList();
}
// used in incremental compilation
public static List<CultureResgenIO> GetCultureResourcesFromIncludeEntries(
Project project,
string outputPath,
CommonCompilerOptions compilationOptions)
{
var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilationOptions.EmbedInclude, "/", diagnostics: null);
return
(from resourceFileGroup in includeFiles
.GroupBy(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.SourcePath))
let culture = resourceFileGroup.Key
where !string.IsNullOrEmpty(culture)
let inputFileToMetadata = resourceFileGroup.ToDictionary(r => r.Key, r => GetResourceFileMetadataName(project, r))
let inputFileToMetadata = resourceFileGroup.ToDictionary(
r => r.SourcePath, r => GetResourceFileMetadataName(project, r.SourcePath, r.IsCustomTarget ? r.TargetPath : null))
let resourceOutputPath = Path.Combine(outputPath, culture)
let outputFile = Path.Combine(resourceOutputPath, project.Name + ".resources.dll")
select new CultureResgenIO(culture, inputFileToMetadata, outputFile)
@ -93,14 +132,14 @@ namespace Microsoft.DotNet.Tools.Compiler
return dependencies.SelectMany(libraryExport => libraryExport.CompilationAssemblies).Select(r => r.ResolvedPath).ToList();
}
public static string GetResourceFileMetadataName(Project project, KeyValuePair<string, string> resourceFile)
public static string GetResourceFileMetadataName(Project project, string resourceFileSource, string resourceFileTarget)
{
string resourceName = null;
string rootNamespace = null;
string root = PathUtility.EnsureTrailingSlash(project.ProjectDirectory);
string resourcePath = resourceFile.Key;
if (string.IsNullOrEmpty(resourceFile.Value))
string resourcePath = resourceFileSource;
if (string.IsNullOrEmpty(resourceFileTarget))
{
// No logical name, so use the file name
resourceName = ResourceUtility.GetResourceName(root, resourcePath);
@ -108,7 +147,7 @@ namespace Microsoft.DotNet.Tools.Compiler
}
else
{
resourceName = ResourceManifestName.EnsureResourceExtension(resourceFile.Value, resourcePath);
resourceName = ResourceManifestName.EnsureResourceExtension(resourceFileTarget, resourcePath);
rootNamespace = null;
}
@ -117,12 +156,23 @@ namespace Microsoft.DotNet.Tools.Compiler
}
// used in incremental compilation
public static IEnumerable<string> GetCompilationSources(ProjectContext project) => project.ProjectFile.Files.SourceFiles;
public static IEnumerable<string> GetCompilationSources(ProjectContext project, CommonCompilerOptions compilerOptions)
{
if (compilerOptions.CompileInclude == null)
{
return project.ProjectFile.Files.SourceFiles;
}
var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilerOptions.CompileInclude, "/", diagnostics: null);
return includeFiles.Select(f => f.SourcePath);
}
//used in incremental precondition checks
public static IEnumerable<string> GetCommandsInvokedByCompile(ProjectContext project)
{
return new List<string> {project.ProjectFile?.CompilerName, "compile"};
var compilerOptions = project.ProjectFile.GetCompilerOptions(project.TargetFramework, configurationName: null);
return new List<string> { compilerOptions.CompilerName, "compile" };
}
}
}