2015-11-16 11:21:57 -08:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
2015-10-13 14:31:29 -07:00
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2016-04-11 19:25:28 -07:00
|
|
|
using Microsoft.DotNet.ProjectModel.Files;
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2015-11-27 16:19:54 -08:00
|
|
|
namespace Microsoft.DotNet.ProjectModel
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2015-10-20 13:27:56 -07:00
|
|
|
public class CommonCompilerOptions
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
public IEnumerable<string> Defines { get; set; }
|
|
|
|
|
|
|
|
public string LanguageVersion { get; set; }
|
|
|
|
|
|
|
|
public string Platform { get; set; }
|
|
|
|
|
|
|
|
public bool? AllowUnsafe { get; set; }
|
|
|
|
|
|
|
|
public bool? WarningsAsErrors { get; set; }
|
|
|
|
|
|
|
|
public bool? Optimize { get; set; }
|
|
|
|
|
|
|
|
public string KeyFile { get; set; }
|
|
|
|
|
|
|
|
public bool? DelaySign { get; set; }
|
|
|
|
|
2015-11-17 23:37:39 -08:00
|
|
|
public bool? PublicSign { get; set; }
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2016-03-02 15:53:59 -08:00
|
|
|
public string DebugType { get; set; }
|
|
|
|
|
2015-10-13 14:31:29 -07:00
|
|
|
public bool? EmitEntryPoint { get; set; }
|
|
|
|
|
2015-12-17 15:04:18 -08:00
|
|
|
public bool? PreserveCompilationContext { get; set; }
|
|
|
|
|
2016-01-08 11:03:14 -08:00
|
|
|
public bool? GenerateXmlDocumentation { get; set; }
|
|
|
|
|
2016-01-13 15:56:02 -08:00
|
|
|
public IEnumerable<string> SuppressWarnings { get; set; }
|
|
|
|
|
2016-01-31 01:25:01 -08:00
|
|
|
public IEnumerable<string> AdditionalArguments { get; set; }
|
|
|
|
|
2016-04-11 19:25:28 -07:00
|
|
|
public string OutputName { get; set; }
|
|
|
|
|
|
|
|
public string CompilerName { get; set; }
|
|
|
|
|
|
|
|
public IncludeContext CompileInclude { get; set; }
|
|
|
|
|
|
|
|
public IncludeContext EmbedInclude { get; set; }
|
|
|
|
|
|
|
|
public IncludeContext CopyToOutputInclude { get; set; }
|
2016-03-10 15:49:11 -08:00
|
|
|
|
2015-12-09 09:57:45 -08:00
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
|
|
|
var other = obj as CommonCompilerOptions;
|
|
|
|
return other != null &&
|
|
|
|
LanguageVersion == other.LanguageVersion &&
|
|
|
|
Platform == other.Platform &&
|
|
|
|
AllowUnsafe == other.AllowUnsafe &&
|
|
|
|
WarningsAsErrors == other.WarningsAsErrors &&
|
|
|
|
Optimize == other.Optimize &&
|
|
|
|
KeyFile == other.KeyFile &&
|
|
|
|
DelaySign == other.DelaySign &&
|
|
|
|
PublicSign == other.PublicSign &&
|
2016-03-02 15:53:59 -08:00
|
|
|
DebugType == other.DebugType &&
|
2015-12-09 09:57:45 -08:00
|
|
|
EmitEntryPoint == other.EmitEntryPoint &&
|
2016-01-08 11:03:14 -08:00
|
|
|
GenerateXmlDocumentation == other.GenerateXmlDocumentation &&
|
2015-12-09 09:57:45 -08:00
|
|
|
PreserveCompilationContext == other.PreserveCompilationContext &&
|
2016-01-31 01:25:01 -08:00
|
|
|
EnumerableEquals(Defines, other.Defines) &&
|
|
|
|
EnumerableEquals(SuppressWarnings, other.SuppressWarnings) &&
|
2016-03-10 15:49:11 -08:00
|
|
|
EnumerableEquals(AdditionalArguments, other.AdditionalArguments) &&
|
2016-04-11 19:25:28 -07:00
|
|
|
OutputName == other.OutputName &&
|
|
|
|
CompilerName == other.CompilerName &&
|
|
|
|
IsEqual(CompileInclude, other.CompileInclude) &&
|
|
|
|
IsEqual(EmbedInclude, other.EmbedInclude) &&
|
|
|
|
IsEqual(CopyToOutputInclude, other.CopyToOutputInclude);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsEqual(IncludeContext first, IncludeContext second)
|
|
|
|
{
|
|
|
|
if (first == null || second == null)
|
|
|
|
{
|
|
|
|
return first == second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return first.Equals(second);
|
2015-12-09 09:57:45 -08:00
|
|
|
}
|
|
|
|
|
2016-01-31 01:25:01 -08:00
|
|
|
private static bool EnumerableEquals(IEnumerable<string> left, IEnumerable<string> right)
|
2016-02-10 15:10:17 -08:00
|
|
|
=> Enumerable.SequenceEqual(left ?? EmptyArray<string>.Value, right ?? EmptyArray<string>.Value);
|
2016-01-31 01:25:01 -08:00
|
|
|
|
2015-12-09 09:57:45 -08:00
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return base.GetHashCode();
|
|
|
|
}
|
|
|
|
|
2016-01-31 01:25:01 -08:00
|
|
|
private static IEnumerable<string> Combine(IEnumerable<string> @new, IEnumerable<string> old)
|
|
|
|
{
|
|
|
|
if (@new != null)
|
|
|
|
{
|
2016-02-10 15:10:17 -08:00
|
|
|
old = old ?? EmptyArray<string>.Value;
|
2016-01-31 01:25:01 -08:00
|
|
|
return old.Concat(@new).Distinct().ToArray();
|
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:27:56 -07:00
|
|
|
public static CommonCompilerOptions Combine(params CommonCompilerOptions[] options)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2015-10-20 13:27:56 -07:00
|
|
|
var result = new CommonCompilerOptions();
|
2015-10-13 14:31:29 -07:00
|
|
|
foreach (var option in options)
|
|
|
|
{
|
|
|
|
// Skip null options
|
|
|
|
if (option == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-31 01:25:01 -08:00
|
|
|
// Defines, suppressions, and additional arguments are always combined
|
|
|
|
result.Defines = Combine(option.Defines, result.Defines);
|
|
|
|
result.SuppressWarnings = Combine(option.SuppressWarnings, result.SuppressWarnings);
|
|
|
|
result.AdditionalArguments = Combine(option.AdditionalArguments, result.AdditionalArguments);
|
2016-01-13 15:56:02 -08:00
|
|
|
|
2015-10-13 14:31:29 -07:00
|
|
|
if (option.LanguageVersion != null)
|
|
|
|
{
|
|
|
|
result.LanguageVersion = option.LanguageVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.Platform != null)
|
|
|
|
{
|
|
|
|
result.Platform = option.Platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.AllowUnsafe != null)
|
|
|
|
{
|
|
|
|
result.AllowUnsafe = option.AllowUnsafe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.WarningsAsErrors != null)
|
|
|
|
{
|
|
|
|
result.WarningsAsErrors = option.WarningsAsErrors;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.Optimize != null)
|
|
|
|
{
|
|
|
|
result.Optimize = option.Optimize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.KeyFile != null)
|
|
|
|
{
|
|
|
|
result.KeyFile = option.KeyFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.DelaySign != null)
|
|
|
|
{
|
|
|
|
result.DelaySign = option.DelaySign;
|
|
|
|
}
|
|
|
|
|
2015-11-17 23:37:39 -08:00
|
|
|
if (option.PublicSign != null)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2015-11-17 23:37:39 -08:00
|
|
|
result.PublicSign = option.PublicSign;
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
2016-03-02 15:53:59 -08:00
|
|
|
if (option.DebugType != null)
|
|
|
|
{
|
|
|
|
result.DebugType = option.DebugType;
|
|
|
|
}
|
|
|
|
|
2015-10-13 14:31:29 -07:00
|
|
|
if (option.EmitEntryPoint != null)
|
|
|
|
{
|
|
|
|
result.EmitEntryPoint = option.EmitEntryPoint;
|
|
|
|
}
|
2015-12-17 15:04:18 -08:00
|
|
|
|
|
|
|
if (option.PreserveCompilationContext != null)
|
|
|
|
{
|
|
|
|
result.PreserveCompilationContext = option.PreserveCompilationContext;
|
|
|
|
}
|
2016-01-08 11:03:14 -08:00
|
|
|
|
|
|
|
if (option.GenerateXmlDocumentation != null)
|
|
|
|
{
|
|
|
|
result.GenerateXmlDocumentation = option.GenerateXmlDocumentation;
|
|
|
|
}
|
2016-03-10 15:49:11 -08:00
|
|
|
|
|
|
|
if (option.OutputName != null)
|
|
|
|
{
|
|
|
|
result.OutputName = option.OutputName;
|
|
|
|
}
|
2016-04-11 19:25:28 -07:00
|
|
|
|
|
|
|
if (option.CompileInclude != null)
|
|
|
|
{
|
|
|
|
result.CompileInclude = option.CompileInclude;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.EmbedInclude != null)
|
|
|
|
{
|
|
|
|
result.EmbedInclude = option.EmbedInclude;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.CopyToOutputInclude != null)
|
|
|
|
{
|
|
|
|
result.CopyToOutputInclude = option.CopyToOutputInclude;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compilerName set in the root cannot be overriden.
|
|
|
|
if (result.CompilerName == null)
|
|
|
|
{
|
|
|
|
result.CompilerName = option.CompilerName;
|
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 13:27:56 -07:00
|
|
|
}
|