Example #1
0
        public void Emit(CompiledProject project, CompiledProjects projects)
        {
            Console.WriteLine($"Emitting {project.Name} ...");

            var compileDirPath = Path.Combine(project.ProjectDirectory, ".forge-cache");

            DirectoryUtil.SafeDelete(compileDirPath);

            var targetDirPath = Path.Combine(project.ProjectDirectory, "targets", "debug");

            DirectoryUtil.SafeDelete(targetDirPath);

            Directory.CreateDirectory(compileDirPath);
            var cppSource     = compiler.EmitCpp(project.Package);
            var cppSourceName = project.Name + ".cpp";

            CreateFile(compileDirPath, cppSourceName, cppSource);
            if (project.Package.IsApp)
            {
                // write out the runtime
                CreateFile(compileDirPath, CppRuntime.FileName, CppRuntime.Source);
                foreach (var dependency in projects)
                {
                    var dependencyCppFileName = dependency.Name + ".cpp";
                    var dependencyCppFilePath = Path.Combine(dependency.ProjectDirectory, ".forge-cache", dependencyCppFileName);
                    File.Copy(dependencyCppFilePath, Path.Combine(compileDirPath, dependencyCppFileName));
                }
                Directory.CreateDirectory(targetDirPath);
                var result = CppCompiler.Invoke(Path.Combine(compileDirPath, cppSourceName), Path.Combine(targetDirPath, project.Name + ".exe"));
                if (result.ExitCode != 0)
                {
                    result.WriteOutputToConsole();
                }
            }
        }
        public void Emit(CompiledProject project, CompiledProjects projects)
        {
            Console.WriteLine($"Emitting {project.Name} ...");

            var compileDirPath = Path.Combine(project.ProjectDirectory, ".forge-cache");
            DirectoryUtil.SafeDelete(compileDirPath);

            var targetDirPath = Path.Combine(project.ProjectDirectory, "targets", "debug");
            DirectoryUtil.SafeDelete(targetDirPath);

            Directory.CreateDirectory(compileDirPath);
            var cppSource = compiler.EmitCpp(project.Package);
            var cppSourceName = project.Name + ".cpp";

            CreateFile(compileDirPath, cppSourceName, cppSource);
            if(project.Package.IsApp)
            {
                // write out the runtime
                CreateFile(compileDirPath, CppRuntime.FileName, CppRuntime.Source);
                foreach(var dependency in projects)
                {
                    var dependencyCppFileName = dependency.Name + ".cpp";
                    var dependencyCppFilePath = Path.Combine(dependency.ProjectDirectory, ".forge-cache", dependencyCppFileName);
                    File.Copy(dependencyCppFilePath, Path.Combine(compileDirPath, dependencyCppFileName));
                }
                Directory.CreateDirectory(targetDirPath);
                var result = CppCompiler.Invoke(Path.Combine(compileDirPath, cppSourceName), Path.Combine(targetDirPath, project.Name + ".exe"));
                if(result.ExitCode != 0)
                    result.WriteOutputToConsole();
            }
        }
        private void CompileProject(string projectDirPath, ProjectConfig projectConfig, CompiledProjects projects)
        {
            Console.WriteLine($"Compiling {projectConfig.Name} ...");

            var sourceFiles = new DirectoryInfo(Path.Combine(projectDirPath, "src")).GetFiles("*.adam", SearchOption.AllDirectories);
            var isApp       = projectConfig.Template == "app";
            // TODO read trusted from config
            var package = new PackageSyntax(projectConfig.Name, isApp, projectConfig.Dependencies.Select(d => new PackageReferenceSyntax(d.Key, null, true)));

            package = package.With(sourceFiles.Select(fileInfo => compiler.Parse(package, new SourceFile(fileInfo))));
            if (package.Diagnostics.Count > 0)
            {
                PrintDiagnostics(package);
                return;
            }
            var compiledPackage = compiler.Compile(package, projects.Select(p => p.Package));
            var compiledProject = new CompiledProject(projectDirPath, compiledPackage);

            projects.Add(compiledProject);
            OnProjectCompiled(compiledProject, projects);
        }
 protected void OnProjectCompiled(CompiledProject project, CompiledProjects projects)
 {
     ProjectCompiled?.Invoke(project, projects);
 }
        private void CompileProject(string projectDirPath, ProjectConfig projectConfig, CompiledProjects projects)
        {
            Console.WriteLine($"Compiling {projectConfig.Name} ...");

            var sourceFiles = new DirectoryInfo(Path.Combine(projectDirPath, "src")).GetFiles("*.adam", SearchOption.AllDirectories);
            var isApp = projectConfig.Template == "app";
            // TODO read trusted from config
            var package = new PackageSyntax(projectConfig.Name, isApp, projectConfig.Dependencies.Select(d => new PackageReferenceSyntax(d.Key, null, true)));
            package = package.With(sourceFiles.Select(fileInfo => compiler.Parse(package, new SourceFile(fileInfo))));
            if(package.Diagnostics.Count > 0)
            {
                PrintDiagnostics(package);
                return;
            }
            var compiledPackage = compiler.Compile(package, projects.Select(p => p.Package));
            var compiledProject = new CompiledProject(projectDirPath, compiledPackage);
            projects.Add(compiledProject);
            OnProjectCompiled(compiledProject, projects);
        }
 protected void OnProjectCompiled(CompiledProject project, CompiledProjects projects)
 {
     ProjectCompiled?.Invoke(project, projects);
 }