Example #1
0
        private void ProcessResult(LibraryInfo info, Dictionary <string, string> files, bool filter)
        {
            if (info.BuildType == BuildTypes.Source)
            {
                CopySource(info, files, filter);
                return;
            }
            var target = Path.Combine(info.TargetPath, info.Name + ".dll");

            if (info.BuildType == BuildTypes.LegacyDotNet)
            {
                var references =
                    info.ReferencesLegacy
                    .Concat(info.DependenciesExists ? Directory.GetFiles(info.DependenciesPath, "*.dll") : new string[0])
                    .Except(info.DependenciesExists ? new[] { Path.Combine(info.DependenciesPath, info.Name + ".dll") } : new string[0]);
                var sources = files.Select(it => it.Value).ToArray();
                Compiler.GenerateAssembly(target, sources, references);
            }
            else
            {
                var depLen     = info.DependenciesPath.Length - info.Dependencies.Length;
                var references =
                    (info.DependenciesExists ? Directory.GetFiles(info.DependenciesPath, "*.dll").Select(it => it.Substring(depLen)) : new string[0])
                    .Except(info.DependenciesExists ? new[] { Path.Combine(info.Dependencies, info.Name + ".dll") } : new string[0]);
                var file = Compiler.BuildDotnet(info, references.ToArray(), files);
                File.Copy(file, target, true);
            }
        }
Example #2
0
 public void Reset(string compilerPath)
 {
     CompilerPath        = compilerPath;
     oldPocoLibrary      = PocoLibrary.Clone();
     oldClientLibrary    = ClientLibrary.Clone();
     oldPortableLibrary  = PortableLibrary.Clone();
     oldPhpSource        = PhpSource.Clone();
     oldTypescriptSource = TypescriptSource.Clone();
     oldWpfLibrary       = WpfLibrary.Clone();
     oldPostgresLibrary  = PostgresLibrary.Clone();
     oldOracleLibrary    = OracleLibrary.Clone();
 }
Example #3
0
        private void CopySource(LibraryInfo info, Dictionary <string, string> files, bool filter)
        {
            if (!info.Compile)
            {
                return;
            }
            var sources =
                (from f in files
                 let name = filter ? f.Key.Substring(1) : f.Key + info.Extension
                            select new { Key = name, f.Value })
                .ToDictionary(it => it.Key, it => it.Value);

            DumpToDisk(info.TargetPath, sources, info.Extension, 3);
        }
Example #4
0
        private static Version RevenjServerVersion(LibraryInfo library)
        {
            Version version;
            var     nuget = library.Nugets.Find(it => "revenj".Equals(it.Project, StringComparison.InvariantCultureIgnoreCase));

            if (library.BuildType == BuildTypes.DotNetStandard && nuget != null && Version.TryParse(nuget.Version, out version))
            {
                return(version);
            }
            if (!library.DependenciesExists)
            {
                return(null);
            }
            var file = Directory.GetFiles(library.DependenciesPath, "Revenj.Core.dll", SearchOption.TopDirectoryOnly);

            if (file == null || file.Length != 1)
            {
                return(null);
            }
            var fvi = FileVersionInfo.GetVersionInfo(file[0]);

            return(new Version(fvi.FileVersion));
        }
        private void ReadInfo(LibraryInfo info, IPropertyBag pBag)
        {
            info.CompileOption = TryReadBool(info.Type + ".Compile", pBag);
            string buildType = TryReadString(info.Type + ".BuildType", pBag);

            if (!string.IsNullOrEmpty(buildType))
            {
                info.BuildType = (BuildTypes)Enum.Parse(typeof(BuildTypes), buildType);
            }
            if (info.BuildType != BuildTypes.Source)
            {
                info.Name = TryReadString(info.Type + ".Name", pBag) ?? info.Name;
            }
            info.Target       = TryReadString(info.Type + ".Target", pBag) ?? info.Target;
            info.Dependencies = TryReadString(info.Type + ".Dependencies", pBag) ?? info.Dependencies;
            var nugets = TryReadString(info.Type + ".Nugets", pBag);

            if (!string.IsNullOrWhiteSpace(nugets))
            {
                var values = nugets.Split(';');
                info.Nugets = values.Select(it =>
                {
                    var parts = it.Split(':');
                    return(new LibraryInfo.Nuget {
                        Project = parts[0], Version = parts[parts.Length - 1]
                    });
                }).ToList();
            }
            info.Namespace            = TryReadString(info.Type + ".Namespace", pBag) ?? info.Namespace;
            info.WithActiveRecord     = TryReadBool(info.Type + ".ActiveRecord", pBag, info.WithActiveRecord);
            info.WithHelperMethods    = TryReadBool(info.Type + ".HelperMethods", pBag, info.WithHelperMethods);
            info.WithManualJson       = TryReadBool(info.Type + ".WithManualJson", pBag, info.WithManualJson);
            info.UseUtc               = TryReadBool(info.Type + ".UseUtc", pBag, info.UseUtc);
            info.Legacy               = TryReadBool(info.Type + ".Legacy", pBag, info.Legacy);
            info.MinimalSerialization = TryReadBool(info.Type + ".MinimalSerialization", pBag, info.MinimalSerialization);
            info.NoPrepareExecute     = TryReadBool(info.Type + ".NoPrepareExecute", pBag, info.NoPrepareExecute);
        }
Example #6
0
        private Either <Dictionary <string, string> > RunCompiler(string dslCompiler, LibraryInfo target, List <string> dsls)
        {
            var sb = new StringBuilder();

            sb.Append("target=").Append(target.CompilerName);
            if (target.WithActiveRecord)
            {
                sb.Append(" settings=active-record");
            }
            if (!target.WithHelperMethods)
            {
                sb.Append(" settings=no-helpers");
            }
            if (target.WithManualJson)
            {
                sb.Append(" settings=manual-json");
            }
            if (target.UseUtc)
            {
                sb.Append(" settings=utc");
            }
            if (target.MinimalSerialization)
            {
                sb.Append(" settings=minimal-serialization");
            }
            if (target.NoPrepareExecute)
            {
                sb.Append(" settings=no-prepare-execute");
            }
            if (target.Legacy)
            {
                sb.Append(" settings=legacy");
            }
            if (target.MutableSnowflake)
            {
                sb.Append(" settings=mutable-snowflake");
            }
            if (!string.IsNullOrWhiteSpace(target.Namespace))
            {
                sb.Append(" namespace=").Append(target.Namespace);
            }
            if (string.IsNullOrEmpty(target.Extension))
            {
                sb.Append(" file-extension");
            }
            var version = target.Version();

            if (version != null)
            {
                sb.Append(" library=" + version.ToString());
            }
            sb.Append(" format=xml");
            var result = Compiler.CompileDsl(sb, dsls, null, cms => XElement.Load(cms));

            if (result.Success)
            {
                var dict =
                    (from x in result.Value.Elements()
                     let elem = x.Elements()
                                select new { key = elem.First().Value, value = elem.Last().Value })
                    .ToDictionary(it => it.key, it => it.value);
                return(Either.Success(dict));
            }
            else
            {
                return(Either <Dictionary <string, string> > .Fail(result.Error));
            }
        }
Example #7
0
 private static Version NoVersion(LibraryInfo library)
 {
     return(null);
 }
        private void WriteInfo(LibraryInfo info, LibraryInfo reference, IPropertyBag pBag)
        {
            object val;

            if (reference.CompileOption != info.CompileOption)
            {
                val = info.CompileOption.ToString();
                pBag.Write(info.Type + ".Compile", ref val);
            }
            if (reference.BuildType != info.BuildType)
            {
                val = info.BuildType.ToString();
                pBag.Write(info.Type + ".BuildType", ref val);
            }
            if (reference.Name != info.Name)
            {
                val = info.Name;
                pBag.Write(info.Type + ".Name", ref val);
            }
            if (reference.Target != info.Target)
            {
                val = info.Target;
                pBag.Write(info.Type + ".Target", ref val);
            }
            if (reference.Dependencies != info.Dependencies)
            {
                val = info.Dependencies;
                pBag.Write(info.Type + ".Dependencies", ref val);
            }
            if (!LibraryInfo.Nuget.Equal(info.Nugets, reference.Nugets))
            {
                val = string.Join(";", info.Nugets.Select(it => it.Project + ":" + it.Version));
                pBag.Write(info.Type + ".Nugets", ref val);
            }
            if (reference.Namespace != info.Namespace)
            {
                val = info.Namespace;
                pBag.Write(info.Type + ".Namespace", ref val);
            }
            if (reference.WithActiveRecord != info.WithActiveRecord)
            {
                val = info.WithActiveRecord.ToString();
                pBag.Write(info.Type + ".ActiveRecord", ref val);
            }
            if (reference.WithHelperMethods != info.WithHelperMethods)
            {
                val = info.WithHelperMethods.ToString();
                pBag.Write(info.Type + ".HelperMethods", ref val);
            }
            if (reference.WithManualJson != info.WithManualJson)
            {
                val = info.WithManualJson.ToString();
                pBag.Write(info.Type + ".WithManualJson", ref val);
            }
            if (reference.UseUtc != info.UseUtc)
            {
                val = info.UseUtc.ToString();
                pBag.Write(info.Type + ".UseUtc", ref val);
            }
            if (reference.Legacy != info.Legacy)
            {
                val = info.Legacy.ToString();
                pBag.Write(info.Type + ".Legacy", ref val);
            }
            if (reference.MinimalSerialization != info.MinimalSerialization)
            {
                val = info.MinimalSerialization.ToString();
                pBag.Write(info.Type + ".MinimalSerialization", ref val);
            }
            if (reference.NoPrepareExecute != info.NoPrepareExecute)
            {
                val = info.NoPrepareExecute.ToString();
                pBag.Write(info.Type + ".NoPrepareExecute", ref val);
            }
            if (reference.MutableSnowflake != info.MutableSnowflake)
            {
                val = info.MutableSnowflake.ToString();
                pBag.Write(info.Type + ".MutableSnowflake", ref val);
            }
        }
Example #9
0
        public static string BuildDotnet(LibraryInfo library, string[] customDlls, Dictionary <string, string> files)
        {
            var folder = Path.Combine(TempPath, library.Type);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            else
            {
                foreach (var f in Directory.GetFiles(folder, "*.cs"))
                {
                    File.Delete(f);
                }
            }
            var outputName = library.Name.IndexOf('/') == -1 ? library.Name : library.Name.Substring(library.Name.LastIndexOf('/'));
            var csproj     = new StringBuilder(@"<Project Sdk=""Microsoft.NET.Sdk"">
  <PropertyGroup>
	<TargetFramework>netstandard2.0</TargetFramework>
	<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
	<AssemblyName>"    );

            csproj.Append(outputName);
            csproj.Append(@"</AssemblyName>
	<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
  </PropertyGroup>");
            if (library.Nugets.Count != 0 || customDlls.Length != 0)
            {
                csproj.Append(@"  
  <ItemGroup>");
                foreach (var n in library.Nugets)
                {
                    csproj.AppendFormat(@"
	<PackageReference Include=""{0}"" Version=""{1}"" />"    , n.Project, n.Version);
                }
                foreach (var dll in customDlls)
                {
                    var fullPath = Path.Combine(LibraryInfo.BasePath, dll);
                    csproj.AppendFormat(@"
	<Reference Include=""{0}"">
		<HintPath>{1}</HintPath>
	</Reference>"    , Path.GetFileNameWithoutExtension(dll), fullPath);
                }
                csproj.Append(@"  
  </ItemGroup>
");
            }
            csproj.Append(@"
</Project>");
            File.WriteAllText(Path.Combine(folder, library.Type + ".csproj"), csproj.ToString());
            foreach (var kv in files)
            {
                var name = kv.Key;
                if (name.IndexOfAny(InvalidFileChars) != -1)
                {
                    foreach (var ch in InvalidFileChars)
                    {
                        name = name.Replace(ch, '_');
                    }
                }
                File.WriteAllText(Path.Combine(folder, name + ".cs"), kv.Value);
            }
            var si = new ProcessStartInfo
            {
                FileName         = "dotnet",
                WorkingDirectory = folder,
                Arguments        = "build -c Release",
                UseShellExecute  = false
            };

            si.EnvironmentVariables["DOTNET_CLI_TELEMETRY_OPTOUT"] = "1";
            var process = Process.Start(si);

            try
            {
                process.WaitForExit();
                if (process.ExitCode == 0)
                {
                    return(Path.Combine(Path.Combine(Path.Combine(folder, "bin"), "Release"), outputName + ".dll"));
                }
                Process.Start(folder);
                throw new ApplicationException(string.Format(@"Error during compilation. Try running the project manually: 
dotnet build ""{0}.csproj""", Path.Combine(folder, library.Type)));
            }
            finally
            {
                process.Dispose();
            }
        }