public CompiledProjects Compile()
        {
            var projects = new CompiledProjects();

            Compile(projectFilePath, projects);
            return(projects);
        }
Exemple #2
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();
                }
            }
        }
        private void Compile(string projectFilePath, CompiledProjects projects)
        {
            var projectDirPath = Path.GetFullPath(Path.GetDirectoryName(projectFilePath));
            var projectConfig  = JsonConvert.DeserializeObject <ProjectConfig>(File.ReadAllText(projectFilePath));

            projectConfig.Name = projectConfig.Name ?? Path.GetFileName(projectDirPath);

            CompileDependencies(projectDirPath, projectConfig, projects);
            CompileProject(projectDirPath, projectConfig, projects);
            CompileSubProjects(projectDirPath, projectConfig, 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);
        }
        private void CompileDependencies(string projectDirPath, ProjectConfig projectConfig, CompiledProjects projects)
        {
            var paths = projectConfig.Dependencies
                        .Where(d => !projects.Contains(d.Key))
                        .Select(d => DependencyPath(d.Key, d.Value, projectDirPath, projectConfig.DependencyPaths));

            foreach (var path in paths)
            {
                Compile(Path.Combine(path, ProjectFile.Name), projects);
            }
        }
 private void CompileSubProjects(string projectDirPath, ProjectConfig projectConfig, CompiledProjects packages)
 {
     // Build Projects that weren't already built as dependencies
     foreach (var project in projectConfig.Projects)
     {
         var projectName = project.Key;
         if (packages.Contains(projectName))
         {
             continue;
         }
         Compile(Path.Combine(projectDirPath, project.Value, ProjectFile.Name), packages);
         // TODO copy into target
     }
 }