Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from itn3000/update-buildalyzer-2.1-pr
Browse files Browse the repository at this point in the history
update to buildalyzer-2.1.0
  • Loading branch information
itn3000 authored Oct 23, 2018
2 parents 39cd006 + f24c74a commit 24935b4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 65 deletions.
16 changes: 0 additions & 16 deletions appveyor-release.yml

This file was deleted.

25 changes: 23 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 1.0.{build}
skip_tags: true
init:
- git config --global core.autocrlf input
configuration: Release
Expand All @@ -8,5 +7,27 @@ build:
project: mo-gen.sln
publish_nuget: true
publish_nuget_symbols: true
after_build:
pwsh: dotnet pack src/mo-gen/mo-gen.csproj
artifacts:
- path: "**/*.nupkg"
name: NuGetPackages
install:
- dotnet restore
- dotnet restore
deploy:
- provider: NuGet
api_key:
secure: F67S4wlZEdRiowy0DR25bnfszCdcNsO3R6ykHeGTWEsl6iqXUJEx+W4M6tk6+iVP
on:
APPVEYOR_REPO_TAG: true
branch: master
artifact: NuGetPackages
- provider: GitHub
auth_token:
secure: MFZg3Ryx8cZ9XWIf8qvSE+48pmQc2LPAcPiRQ7bUtPRKj4mXvn+mtZVzPV7tQyX1
on:
APPVEYOR_REPO_TAG: true
branch: master
artifact: NuGetPackages
prerelease: false
draft: true
5 changes: 4 additions & 1 deletion src/mo-gen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CommandlineArguments(string[] args)
{ "n|namespace=", "[optional, default=MagicOnion]Set namespace root name", x => { NamespaceRoot = x; } },
{ "a|asyncsuffix", "[optional, default=false]Use methodName to async suffix", _ => { IsAsyncSuffix = true; } },
{ "c|conditionalsymbol=", "[optional, default=empty]conditional compiler symbol list separated by ','", x => ConditionalSymbols.AddRange(x.Split(",")) },
{ "v|verbose=", "[optional, default=None]project compilation output verbosity level(None,Minimal,Normal,Detailed)", level => {
{ "v|verbose=", "[optional, default=None]project compilation output verbosity level(None,Minimal,Normal,Detailed,Diagnostic)", level => {
switch(level.ToLower())
{
case "none":
Expand All @@ -57,6 +57,9 @@ public CommandlineArguments(string[] args)
case "detailed":
VerbosityLevel = 3;
break;
case "diagnostic":
VerbosityLevel = 4;
break;
default:
break;
}
Expand Down
66 changes: 32 additions & 34 deletions src/mo-gen/Utils/RoslynExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using System.Xml.Linq;
using MagicOnion.Utils;
using Buildalyzer;
using Buildalyzer.Environment;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using MsLogging = Microsoft.Extensions.Logging;

namespace MagicOnion
{
Expand All @@ -29,6 +31,8 @@ static LoggerVerbosity ToLoggerVerbosity(this int value)
return LoggerVerbosity.Normal;
case 3:
return LoggerVerbosity.Detailed;
case 4:
return LoggerVerbosity.Diagnostic;
case 0:
default:
return LoggerVerbosity.Quiet;
Expand Down Expand Up @@ -77,10 +81,16 @@ static LanguageVersion ConvertLanguageVersion(string versionString)
return LanguageVersion.Default;
}
}

public static async Task<Compilation> GetCompilationFromProject(string csprojPath, int verbosityLevel,
Dictionary<string, string> additionalProperties,
IEnumerable<string> conditionalSymbols)
{
conditionalSymbols = conditionalSymbols != null ?
conditionalSymbols.Where(x => !string.IsNullOrEmpty(x)).ToArray()
:
Enumerable.Empty<string>();

// fucking workaround of resolve reference...
var externalReferences = new List<PortableExecutableReference>();
{
Expand Down Expand Up @@ -119,57 +129,45 @@ public static async Task<Compilation> GetCompilationFromProject(string csprojPat

EnvironmentHelper.Setup();
var analyzerOptions = new AnalyzerManagerOptions();
analyzerOptions.LoggerVerbosity = verbosityLevel.ToLoggerVerbosity();
if (verbosityLevel > 0)
{
analyzerOptions.LogWriter = Console.Out;
}
var manager = new AnalyzerManager(analyzerOptions);
var projectAnalyzer = manager.GetProject(csprojPath);
projectAnalyzer.AddBuildLogger(new Microsoft.Build.Logging.ConsoleLogger(verbosityLevel.ToLoggerVerbosity()));
var buildopts = new EnvironmentOptions();
if (additionalProperties != null)
{
foreach (var kv in additionalProperties)
{
buildopts.GlobalProperties[kv.Key] = kv.Value;
projectAnalyzer.SetGlobalProperty(kv.Key, kv.Value);
}
}
var compiledProject = projectAnalyzer.Build().Project;
var ws = new AdhocWorkspace();
if (compiledProject == null)
if (conditionalSymbols.Any())
{
throw new Exception("project compilation failed");
buildopts.GlobalProperties["DefineConstants"] = string.Join("%3b", conditionalSymbols);
}

var workspace = projectAnalyzer.GetWorkspace();
workspace.WorkspaceFailed += WorkSpaceFailed;
var project = workspace.CurrentSolution.Projects.First();
project = project.AddMetadataReferences(externalReferences);
var opt = project.ParseOptions as CSharpParseOptions;
if (opt != null)
var analyzerResults = projectAnalyzer.Build(buildopts);
var analyzerResult = analyzerResults.FirstOrDefault(x => x.Succeeded);
if (analyzerResult == null)
{
var defineconstants = compiledProject.GetPropertyValue("DefineConstants").Split(';');
var langVersion = compiledProject.GetPropertyValue("LangVersion");
var features = compiledProject.GetPropertyValue("Features").Split(';').Select(x =>
{
var kv = x.Split('=', 2);
if (kv.Length == 1)
{
return new KeyValuePair<string, string>(kv[0], "true");
}
else if (kv.Length > 1)
{
return new KeyValuePair<string, string>(kv[0], kv[1]);
}
else
{
return new KeyValuePair<string, string>(null, null);
}
}).Where(x => x.Key != null).ToArray();
opt = opt.WithLanguageVersion(ConvertLanguageVersion(langVersion))
.WithPreprocessorSymbols(defineconstants.Concat(conditionalSymbols))
.WithFeatures(features)
throw new Exception("no succeeded analyzer result found");
}
var ws = new AdhocWorkspace();
var project = analyzerResult.AddToWorkspace(ws);
var parseopts = project.ParseOptions as CSharpParseOptions;
if (parseopts != null)
{
var symbols = analyzerResult.Properties.ContainsKey("DefineConstants") ?
conditionalSymbols.Concat(
analyzerResult.Properties["DefineConstants"].Split(';')
).OrderBy(x => x).Distinct()
:
conditionalSymbols
;
project = project.WithParseOptions(opt);
project = project.WithParseOptions(parseopts.WithPreprocessorSymbols(symbols));
}
var compilation = await project.GetCompilationAsync().ConfigureAwait(false);
return compilation;
Expand Down
17 changes: 6 additions & 11 deletions src/mo-gen/mo-gen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<AssemblyName>dotnet-mo-gen</AssemblyName>
<VersionPrefix>0.1.1</VersionPrefix>
<VersionPrefix>0.2.0</VersionPrefix>
</PropertyGroup>
<PropertyGroup>
<PackageVersion>0.1.1</PackageVersion>
<PackageVersion>0.2.0</PackageVersion>
<PackageId>dotnet-mo-gen</PackageId>
<Title>Unity client code generator for MagicOnion</Title>
<Authors>skitoy4321</Authors>
Expand All @@ -23,15 +23,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Buildalyzer" Version="1.0.0" />
<PackageReference Include="Buildalyzer.Workspaces" Version="1.0.0" />
<PackageReference Include="Microsoft.Build" Version="15.8.166" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.8.166" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.8.166" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.2" />
<PackageReference Include="Nuget.Frameworks" Version="4.8.0" />
<PackageReference Include="NuGet.Common" Version="4.8.0" />
<PackageReference Include="NuGet.ProjectModel" Version="4.8.0" />
<PackageReference Include="Buildalyzer" Version="2.1.0" />
<PackageReference Include="Buildalyzer.Workspaces" Version="2.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.9.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="System.CodeDom" Version="4.5.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/mo_gen_test_project/mo_gen_test_project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MagicOnion" Version="0.5.2" />
<PackageReference Include="MagicOnion" Version="0.5.3" />
</ItemGroup>

</Project>

0 comments on commit 24935b4

Please sign in to comment.