Skip to content

Commit

Permalink
Merge pull request #14 from aosoft/testtool
Browse files Browse the repository at this point in the history
Compiler テストツール その 6
  • Loading branch information
kuma authored May 6, 2020
2 parents 95e0dee + a2fd7c4 commit 015b002
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion PMDDotNETCompilerTestService/DotnetCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@ public static (CompileResult result, string outputFileName) Compile(string mmlFi
var compiler = new Compiler();
compiler.Init();

var includePaths = new List<string>();
includePaths.Add(dir);
var envpmd = Environment.GetEnvironmentVariable("PMD", EnvironmentVariableTarget.User);
if (!string.IsNullOrEmpty(envpmd))
{
var envpmds = envpmd.Split(";");
foreach(var item in envpmds)
{
var path = Path.GetFullPath(item.Trim());
if (Directory.Exists(path))
{
includePaths.Add(path);
}
}
}

Func<string?, Stream?> fnAppendFileReaderCallback = fname =>
{
try
{
if (fname != null)
{
return new FileStream(Path.Combine(dir, fname), FileMode.Open, FileAccess.Read, FileShare.Read);
foreach (var item in includePaths)
{
var path = Path.Combine(item, fname);
if (File.Exists(path))
{
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
}
}
}
}
catch
Expand Down Expand Up @@ -55,6 +78,23 @@ public static (CompileResult result, string outputFileName) Compile(string mmlFi
{
compiler.mcArgs = new string[] { fname };
}

var envs = new List<string>();
void AddEnv(string envname)
{
var env = Environment.GetEnvironmentVariable(envname, EnvironmentVariableTarget.User);
if (!string.IsNullOrEmpty(env))
{
envs.Add(string.Format("{0}={1}", envname, env));
}
}

AddEnv("ARRANGER");
AddEnv("COMPOSER");
AddEnv("USER");
AddEnv("MCOPT");
compiler.env = envs.ToArray();

var r = compiler.Compile(fs, ms, fnAppendFileReaderCallback);
ms.Flush();

Expand Down

0 comments on commit 015b002

Please sign in to comment.