From 84f35cab5e6f21a706ffb53cdfdb7398cdae1949 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 25 Jan 2014 05:31:46 -0800 Subject: [PATCH] Handle defines and unsafe code. --- build/_k-generate-projects.shade | 17 +++++++++++++++-- build/k10.txt | 8 ++++---- build/net45.txt | 8 ++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/build/_k-generate-projects.shade b/build/_k-generate-projects.shade index 100205073a..533ce7265d 100644 --- a/build/_k-generate-projects.shade +++ b/build/_k-generate-projects.shade @@ -150,6 +150,7 @@ functions var d = serializer.DeserializeObject(jsonText) as IDictionary; var configs = GetObject(d, "configurations") ?? new Dictionary(); var dependencies = GetObject(d, "dependencies") ?? new Dictionary(); + var compilationOptions = GetObject(d, "compilationOptions") ?? new Dictionary(); if(configs.Count == 0) { @@ -173,6 +174,11 @@ functions .Select(r => r.Key) .ToList(); + var defines = Get>(compilationOptions, "define") ?? new object[0]; + object unsafeValue = Get(compilationOptions, "allowUnsafe"); + bool allowUnsafeCode = unsafeValue == null ? false : (bool)unsafeValue; + + string extraProperties = allowUnsafeCode ? "\ntrue" : ""; // HACK: Assume the packages folder is 2 up from the projectDir string packagesDir = Path.GetFullPath(Path.Combine(projectDir, "..", "..", "packages")); @@ -205,6 +211,8 @@ functions var template = templates[targetFramework] .Replace("{ProjectGuid}", id) .Replace("{Name}", projectName) + .Replace("{Defines}", String.Join(";", defines.Select(def => def.ToString()))) + .Replace("{ExtraProperties}", extraProperties) .Replace("{Files}", filesString) .Replace("{ProjectReferences}", BuildProjectReferences(projectReferences, targetFramework, projectMapping)) .Replace("{References}", BuildReferences(packageReferences, gacReferences, packagesDir, targetFramework, GetCandidates(targetFramework))); @@ -340,15 +348,20 @@ functions return sb.ToString(); } - private static IDictionary GetObject(IDictionary obj, string key) + private static T Get(IDictionary obj, string key) where T : class { object value; if (obj.TryGetValue(key, out value)) { - return value as IDictionary; + return value as T; } return null; } + + private static IDictionary GetObject(IDictionary obj, string key) + { + return Get>(obj, key); + } } } diff --git a/build/k10.txt b/build/k10.txt index 98924c1a4a..060f9f89e6 100644 --- a/build/k10.txt +++ b/build/k10.txt @@ -19,18 +19,18 @@ full false bin\Debug\K - DEBUG;TRACE;K10 + DEBUG;TRACE;K10;{Defines} prompt - 4 + 4{ExtraProperties} AnyCPU pdbonly true bin\Release\K - TRACE;K10 + TRACE;K10;{Defines} prompt - 4 + 4{ExtraProperties} {Files} diff --git a/build/net45.txt b/build/net45.txt index 8d2e271f7b..c24abbc2d8 100644 --- a/build/net45.txt +++ b/build/net45.txt @@ -19,18 +19,18 @@ full false bin\Debug\net45 - DEBUG;TRACE;NET45 + DEBUG;TRACE;NET45;{Defines} prompt - 4 + 4{ExtraProperties} AnyCPU pdbonly true bin\Release\net45 - TRACE;NET45 + TRACE;NET45;{Defines} prompt - 4 + 4{ExtraProperties}