Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use project ChecksumAlgorithm in code-behind. #7556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public bool XamlDebuggingInformation
set { _xamlDebuggingInformation = value; }
}

///<summary>Gets or sets the checksum algorithm used in code-behind.</summary>
public string ChecksumAlgorithm { get; set; }

/// <summary>
/// Get/Sets the TaskFileService which is used for abstracting simple
/// files services provided by CLR and the HostObject (IVsMsBuildTaskFileManager)
Expand Down Expand Up @@ -231,90 +234,78 @@ public void Compile(CompilationUnit cu)

private void CompileCore(CompilationUnit cu)
{
try
{
AssemblyName = cu.AssemblyName;
InitCompilerState();
AssemblyName = cu.AssemblyName;
InitCompilerState();

DefaultNamespace = cu.DefaultNamespace;
_compilationUnitSourcePath = cu.SourcePath;

if (!IsLanguageSupported(cu.Language))
{
OnError(new Exception(SR.Format(SR.UnknownLanguage, cu.Language)));
return;
}
DefaultNamespace = cu.DefaultNamespace;
_compilationUnitSourcePath = cu.SourcePath;

if (!cu.Pass2)
{
EnsureLanguageSourceExtension();
}

if (cu.ApplicationFile.Path != null && cu.ApplicationFile.Path.Length > 0)
{
Initialize(cu.ApplicationFile);
ApplicationFile = SourceFileInfo.RelativeSourceFilePath;
if (!IsLanguageSupported(cu.Language))
{
OnError(new Exception(SR.Format(SR.UnknownLanguage, cu.Language)));
return;
}

if (ApplicationFile.Length > 0)
{
IsCompilingEntryPointClass = true;
_Compile(cu.ApplicationFile.Path, cu.Pass2);
IsCompilingEntryPointClass = false;
if (!cu.Pass2)
{
EnsureLanguageSourceExtension();
}

if (_pendingLocalFiles != null && _pendingLocalFiles.Count == 1)
{
Debug.Assert(!cu.Pass2);
_localXamlApplication = (string)_pendingLocalFiles[0];
_pendingLocalFiles.Clear();
}
}
}
if (cu.ApplicationFile.Path != null && cu.ApplicationFile.Path.Length > 0)
{
Initialize(cu.ApplicationFile);
ApplicationFile = SourceFileInfo.RelativeSourceFilePath;

if (cu.FileList != null)
if (ApplicationFile.Length > 0)
{
for (int i = 0; i < cu.FileList.Length; i++)
{
FileUnit sourceFile = cu.FileList[i];

Initialize(sourceFile);
if (SourceFileInfo.RelativeSourceFilePath.Length > 0)
{
_Compile(sourceFile.Path, cu.Pass2);
}
}
IsCompilingEntryPointClass = true;
_Compile(cu.ApplicationFile.Path, cu.Pass2);
IsCompilingEntryPointClass = false;

if (_pendingLocalFiles != null && _pendingLocalFiles.Count > 0)
if (_pendingLocalFiles != null && _pendingLocalFiles.Count == 1)
{
Debug.Assert(!cu.Pass2);
_localXamlPages = (string[])_pendingLocalFiles.ToArray(typeof(string));
_localXamlApplication = (string)_pendingLocalFiles[0];
_pendingLocalFiles.Clear();
}
}
}

if (!cu.Pass2 && ContentList != null && ContentList.Length > 0)
if (cu.FileList != null)
{
for (int i = 0; i < cu.FileList.Length; i++)
{
GenerateLooseContentAttributes();
}
FileUnit sourceFile = cu.FileList[i];

Debug.Assert(!cu.Pass2 || _pendingLocalFiles == null);
Debug.Assert(_pendingLocalFiles == null || _pendingLocalFiles.Count == 0);
_pendingLocalFiles = null;
Initialize(sourceFile);
if (SourceFileInfo.RelativeSourceFilePath.Length > 0)
{
_Compile(sourceFile.Path, cu.Pass2);
}
}

if (cu.Pass2)
if (_pendingLocalFiles != null && _pendingLocalFiles.Count > 0)
{
_localAssembly = null;
_localXamlApplication = null;
_localXamlPages = null;
Debug.Assert(!cu.Pass2);
_localXamlPages = (string[])_pendingLocalFiles.ToArray(typeof(string));
_pendingLocalFiles.Clear();
}
}
finally

if (!cu.Pass2 && ContentList != null && ContentList.Length > 0)
{
GenerateLooseContentAttributes();
}

if (s_hashAlgorithm != null)
{
s_hashAlgorithm.Clear();
s_hashAlgorithm = null;
}
Debug.Assert(!cu.Pass2 || _pendingLocalFiles == null);
Debug.Assert(_pendingLocalFiles == null || _pendingLocalFiles.Count == 0);
_pendingLocalFiles = null;

if (cu.Pass2)
{
_localAssembly = null;
_localXamlApplication = null;
_localXamlPages = null;
}
}

Expand Down Expand Up @@ -639,18 +630,15 @@ private void GenerateSource()
// } end namespace
CodeCompileUnit ccu = new CodeCompileUnit();

// Use SHA1 if compat flag is set
// generate pragma checksum data
if (s_hashAlgorithm == null)
{
s_hashAlgorithm = SHA1.Create();
s_hashGuid = s_hashSHA1Guid;
}
Guid hashGuid = ChecksumAlgorithm.Equals("SHA256", StringComparison.OrdinalIgnoreCase)
? s_hashSHA256Guid
: s_hashSHA1Guid;

CodeChecksumPragma csPragma = new CodeChecksumPragma();
csPragma.FileName = ParentFolderPrefix + SourceFileInfo.RelativeSourceFilePath + XAML;
csPragma.ChecksumAlgorithmId = s_hashGuid;
csPragma.ChecksumData = TaskFileService.GetChecksum(SourceFileInfo.OriginalFilePath, s_hashGuid);
csPragma.ChecksumAlgorithmId = hashGuid;
csPragma.ChecksumData = TaskFileService.GetChecksum(SourceFileInfo.OriginalFilePath, hashGuid);
ccu.StartDirectives.Add(csPragma);

if (cnsImports != _ccRoot.CodeNS)
Expand Down Expand Up @@ -3600,9 +3588,6 @@ internal string SubClass
private const string PARENTFOLDER = @"..\";

// For generating pragma checksum data
private static HashAlgorithm s_hashAlgorithm;
private static Guid s_hashGuid;

private static readonly Guid s_hashSHA256Guid = new Guid(0x8829d00f, 0x11b8, 0x4213, 0x87, 0x8b, 0x77, 0x0e, 0x85, 0x97, 0xac, 0x16);
private static readonly Guid s_hashSHA1Guid = new Guid(0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ internal bool XamlDebuggingInformation
set { _mc.XamlDebuggingInformation = value; }
}

/// <summary>
/// Sets the checksum algorithm used in code-behind.
/// </summary>
internal string ChecksumAlgorithm
{
set => _mc.ChecksumAlgorithm = value;
}

// <summary>
// Controls how to generate localization information for each xaml file.
// Valid values: None, CommentsOnly, All.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
DefineConstants="$(DefineConstants)"
ExtraBuildControlFiles="@(ExtraBuildControlFiles)"
XamlDebuggingInformation="$(XamlDebuggingInformation)"
ChecksumAlgorithm="$(ChecksumAlgorithm)"
IsRunningInVisualStudio="$(BuildingInsideVisualStudio)"
OutputPath="$(IntermediateOutputPath)"
SupportCustomOutputPaths="$(IncludePackageReferencesDuringMarkupCompilation)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ public bool XamlDebuggingInformation
set { _xamlDebuggingInformation = value; }
}

/// <summary>
/// Gets or sets the checksum algorithm used in code-behind.
/// </summary>
public string ChecksumAlgorithm { get; set; }

/// <summary>
/// Keep a list of Build control files.
/// If one of them is changed since last build, it would trigger recompilation of all the xaml files.
Expand Down Expand Up @@ -1234,6 +1239,7 @@ private void DoMarkupCompilation()
compilerWrapper.TaskLogger = Log;
compilerWrapper.UnknownErrorID = UnknownErrorID;
compilerWrapper.XamlDebuggingInformation = XamlDebuggingInformation;
compilerWrapper.ChecksumAlgorithm = ChecksumAlgorithm;

compilerWrapper.TaskFileService = TaskFileService;

Expand Down