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

More porting Microsoft.Build to .NET Core #158

Merged
merged 9 commits into from
Aug 21, 2015
13 changes: 13 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<clear/>
<add key="myget.org dotnet-core" value="https://www.myget.org/F/dotnet-core/" />
<add key="myget.org dotnet-corefxtestdata" value="https://www.myget.org/F/dotnet-corefxtestdata/" />
<add key="myget.org dotnet-buildtools" value="https://www.myget.org/F/dotnet-buildtools/" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
24 changes: 20 additions & 4 deletions dir.props
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,45 @@

<PropertyGroup Condition="'$(NetCoreSurface)' != 'true'">
<DefineConstants>$(DefineConstants);FEATURE_APARTMENT_STATE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_APM</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_APPDOMAIN</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_APPDOMAIN_UNHANDLED_EXCEPTION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ASSEMBLY_LOADFROM</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ASSEMBLY_LOCATION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ASSEMBLYNAME_CULTUREINFO</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ASSEMBLYNAME_CLONE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_BINARY_SERIALIZATION</DefineConstants>
<FeatureBinarySerialization>true</FeatureBinarySerialization>
<DefineConstants>$(DefineConstants);FEATURE_CONSOLE_BUFFERWIDTH</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_CONSTRAINED_EXECUTION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_CHARSET_AUTO</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_DOTNETVERSION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ENVIRONMENT_SYSTEMDIRECTORY</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_FILE_TRACKER</DefineConstants>
<FeatureFileTracker>true</FeatureFileTracker>
<DefineConstants>$(DefineConstants);FEATURE_GAC</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_GET_COMMANDLINE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_HANDLE_SAFEWAITHANDLE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_HANDLEREF</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_MEMORYSTREAM_GETBUFFER</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_OSVERSION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_REFLECTION_EMIT_DEBUG_INFO</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_REGISTRYHIVE_DYNDATA</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_RESOURCE_EXPOSURE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_SECURITY_PERMISSIONS</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_SPECIAL_FOLDERS</DefineConstants>
<FeatureSpecialFolders>true</FeatureSpecialFolders>
<DefineConstants>$(DefineConstants);FEATURE_SYSTEM_CONFIGURATION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_THREAD_ABORT</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_THREAD_CULTURE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_THREAD_PRIORITY</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_TYPE_INVOKEMEMBER</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_TYPE_GETINTERFACE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_VARIOUS_EXCEPTIONS</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_XAML_TYPES</DefineConstants>
<FeatureXamlTypes>true</FeatureXamlTypes>
<DefineConstants>$(DefineConstants);FEATURE_XML_SOURCE_URI</DefineConstants>



<DefineConstants>$(DefineConstants);FEATURE_XML_LOADPATH</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_XMLTEXTREADER</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(NetCoreSurface)' == 'true'">

Expand Down
2 changes: 1 addition & 1 deletion src/Shared/CommunicationsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ internal static void Trace(int nodeId, string format, params object[] args)

fileName += ".txt";

using (StreamWriter file = FileUtilities.OpenFileForAppend(String.Format(CultureInfo.CurrentCulture, Path.Combine(s_debugDumpPath, fileName), Process.GetCurrentProcess().Id, nodeId)))
using (StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(s_debugDumpPath, fileName), Process.GetCurrentProcess().Id, nodeId), append: true))
{
string message = String.Format(CultureInfo.CurrentCulture, format, args);
long now = DateTime.UtcNow.Ticks;
Expand Down
125 changes: 125 additions & 0 deletions src/Shared/Compat/Base64Encoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

//------------------------------------------------------------------------------
// <copyright file="Base64Encoder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------

using System.Text;
using System.Diagnostics;

namespace System.Xml {

internal abstract partial class Base64Encoder {

byte[] leftOverBytes;
int leftOverBytesCount;
char[] charsLine;

internal const int Base64LineSize = 76;
internal const int LineSizeInBytes = Base64LineSize/4*3;

internal Base64Encoder() {
charsLine = new char[Base64LineSize];
}

internal abstract void WriteChars( char[] chars, int index, int count );

internal void Encode( byte[] buffer, int index, int count ) {
if ( buffer == null ) {
throw new ArgumentNullException( "buffer" );
}
if ( index < 0 ) {
throw new ArgumentOutOfRangeException( "index" );
}
if ( count < 0 ) {
throw new ArgumentOutOfRangeException( "count" );
}
if ( count > buffer.Length - index ) {
throw new ArgumentOutOfRangeException( "count" );
}

// encode left-over buffer
if( leftOverBytesCount > 0 ) {
int i = leftOverBytesCount;
while ( i < 3 && count > 0 ) {
leftOverBytes[i++] = buffer[index++];
count--;
}

// the total number of buffer we have is less than 3 -> return
if ( count == 0 && i < 3 ) {
leftOverBytesCount = i;
return;
}

// encode the left-over buffer and write out
int leftOverChars = Convert.ToBase64CharArray( leftOverBytes, 0, 3, charsLine, 0 );
WriteChars( charsLine, 0, leftOverChars );
}

// store new left-over buffer
leftOverBytesCount = count % 3;
if ( leftOverBytesCount > 0 ) {
count -= leftOverBytesCount;
if ( leftOverBytes == null ) {
leftOverBytes = new byte[3];
}
for( int i = 0; i < leftOverBytesCount; i++ ) {
leftOverBytes[i] = buffer[ index + count + i ];
}
}

// encode buffer in 76 character long chunks
int endIndex = index + count;
int chunkSize = LineSizeInBytes;
while( index < endIndex ) {
if ( index + chunkSize > endIndex ) {
chunkSize = endIndex - index;
}
int charCount = Convert.ToBase64CharArray( buffer, index, chunkSize, charsLine, 0 );
WriteChars( charsLine, 0, charCount );

index += chunkSize;
}
}

internal void Flush() {
if ( leftOverBytesCount > 0 ) {
int leftOverChars = Convert.ToBase64CharArray( leftOverBytes, 0, leftOverBytesCount, charsLine, 0 );
WriteChars( charsLine, 0, leftOverChars );
leftOverBytesCount = 0;
}
}
}

//internal partial class XmlRawWriterBase64Encoder : Base64Encoder {

// XmlRawWriter rawWriter;

// internal XmlRawWriterBase64Encoder( XmlRawWriter rawWriter ) {
// this.rawWriter = rawWriter;
// }

// internal override void WriteChars( char[] chars, int index, int count ) {
// rawWriter.WriteRaw( chars, index, count );
// }
//}

#if !SILVERLIGHT || FEATURE_NETCORE
internal partial class XmlTextWriterBase64Encoder : Base64Encoder {

XmlTextEncoder xmlTextEncoder;

internal XmlTextWriterBase64Encoder( XmlTextEncoder xmlTextEncoder ) {
this.xmlTextEncoder = xmlTextEncoder;
}

internal override void WriteChars( char[] chars, int index, int count ) {
xmlTextEncoder.WriteRaw( chars, index, count );
}
}
#endif

}
79 changes: 79 additions & 0 deletions src/Shared/Compat/BinHexEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

//------------------------------------------------------------------------------
// <copyright file="BinHexEncoder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------

namespace System.Xml {
internal static partial class BinHexEncoder {

private const string s_hexDigits = "0123456789ABCDEF";
private const int CharsChunkSize = 128;

internal static void Encode( byte[] buffer, int index, int count, XmlWriter writer ) {
if ( buffer == null ) {
throw new ArgumentNullException( "buffer" );
}
if ( index < 0 ) {
throw new ArgumentOutOfRangeException( "index" );
}
if ( count < 0 ) {
throw new ArgumentOutOfRangeException( "count" );
}
if ( count > buffer.Length - index ) {
throw new ArgumentOutOfRangeException( "count" );
}

char[] chars = new char[ ( count * 2 ) < CharsChunkSize ? ( count * 2 ) : CharsChunkSize ];
int endIndex = index + count;
while ( index < endIndex ) {
int cnt = ( count < CharsChunkSize/2 ) ? count : CharsChunkSize/2;
int charCount = Encode( buffer, index, cnt, chars );
writer.WriteRaw( chars, 0, charCount );
index += cnt;
count -= cnt;
}
}

internal static string Encode(byte[] inArray, int offsetIn, int count) {
if (null == inArray) {
throw new ArgumentNullException("inArray");
}
if (0 > offsetIn) {
throw new ArgumentOutOfRangeException("offsetIn");
}
if (0 > count) {
throw new ArgumentOutOfRangeException("count");
}
if (count > inArray.Length - offsetIn) {
throw new ArgumentOutOfRangeException("count");
}

char[] outArray = new char[2 * count];
int lenOut = Encode(inArray, offsetIn, count, outArray);
return new String(outArray, 0, lenOut);
}

private static int Encode(byte[] inArray, int offsetIn, int count, char[] outArray) {
int curOffsetOut =0, offsetOut = 0;
byte b;
int lengthOut = outArray.Length;

for (int j=0; j<count; j++) {
b = inArray[offsetIn ++];
outArray[curOffsetOut ++] = s_hexDigits[b >> 4];
if (curOffsetOut == lengthOut) {
break;
}
outArray[curOffsetOut ++] = s_hexDigits[b & 0xF];
if (curOffsetOut == lengthOut) {
break;
}
}
return curOffsetOut - offsetOut;
} // function

} // class
} // namespace
18 changes: 18 additions & 0 deletions src/Shared/Compat/SafeHandleZeroOrMinusOneIsInvalid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Microsoft.Win32.SafeHandles
{
using System;
using System.Runtime.InteropServices;

public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
{
protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
{
}

public override bool IsInvalid
{
get
{ return handle == IntPtr.Zero || handle == new IntPtr(-1); }
}
}
}
47 changes: 47 additions & 0 deletions src/Shared/Compat/SecureStringHasher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
// <copyright file="SecureStringHasher.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;

namespace System.Xml {

// SecureStringHasher is a hash code provider for strings. The hash codes calculation starts with a seed (hasCodeRandomizer) which is usually
// different for each instance of SecureStringHasher. Since the hash code depend on the seed, the chance of hashtable DoS attack in case when
// someone passes in lots of strings that hash to the same hash code is greatly reduced.
// The SecureStringHasher implements IEqualityComparer for strings and therefore can be used in generic IDictionary.
internal class SecureStringHasher : IEqualityComparer<String> {
int hashCodeRandomizer;

public SecureStringHasher() {
this.hashCodeRandomizer = Environment.TickCount;
}

#if false // This is here only for debugging of hashing issues
public SecureStringHasher( int hashCodeRandomizer ) {
this.hashCodeRandomizer = hashCodeRandomizer;
}
#endif

public bool Equals( String x, String y ) {
return String.Equals( x, y, StringComparison.Ordinal );
}

public int GetHashCode( String key ) {
int hashCode = hashCodeRandomizer;
// use key.Length to eliminate the rangecheck
for ( int i = 0; i < key.Length; i++ ) {
hashCode += ( hashCode << 7 ) ^ key[i];
}
// mix it a bit more
hashCode -= hashCode >> 17;
hashCode -= hashCode >> 11;
hashCode -= hashCode >> 5;
return hashCode;
}
}
}
12 changes: 12 additions & 0 deletions src/Shared/Compat/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Runtime.InteropServices;

namespace System.Reflection
{
public static class TypeExtensions
{
public static bool IsEquivalentTo(this Type type, Type other)
{
return type.Equals(other);
}
}
}
6 changes: 6 additions & 0 deletions src/Shared/Compat/TypeFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Runtime.InteropServices;

namespace System.Reflection
{
public delegate bool TypeFilter(Type m, object filterCriteria);
}
Loading