Exemple #1
0
        public static void ActionBuild(string projectDir)
        {
            ActionGenerate(projectDir);
            var projectYaml = ParseYaml(projectDir);

            string ninjaName = CommandInterface.IsWindows ? "ninja.exe" : "ninja";

            // Download ninja if running for the first time
            if (!File.Exists(Path.Combine(projectDir, "dist", "bin", ninjaName)))
            {
                Console.WriteLine("Downloading ninja... (this only happens once)");

                var url = CommandInterface.IsWindows ? "https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-win.zip"
                        : CommandInterface.IsOSX ? "https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-mac.zip"
                        : "https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-linux.zip";

                using var client = new HttpClient();
                var ninja = client.GetStreamAsync(url);
                ninja.Wait();

                using (var archive = File.Open(Path.Combine(projectDir, "dist", "bin", "ninja.zip"), FileMode.OpenOrCreate, FileAccess.Write))
                {
                    ninja.Result.CopyTo(archive);
                }

                // Extract the archive
                ZipFile.ExtractToDirectory(Path.Combine(projectDir, "dist", "bin", "ninja.zip"), Path.Combine(projectDir, "dist", "bin"));
                // Remove the archive
                File.Delete(Path.Combine(projectDir, "dist", "bin", "ninja.zip"));

                // On Linux, the file must be set as executable
                if (CommandInterface.IsLinux)
                {
                    CommandInterface.RunCommand("chmod", new string[] { "+x", Path.Combine(projectDir, "dist", "bin", ninjaName) }, ".");
                }
            }

            // If RebuildFC is true, regenerate the compiler
            if (projectYaml.RebuildFC == "always")
            {
                if (!Directory.Exists(Path.Combine(projectDir, "dist", "functional")))
                {
                    ErrorReporter.Error("regenerate-fc set to true, but dist/functional does not exist");
                }

                Console.WriteLine("Rebuilding the compiler...");

                // here we use build instead of release because it is faster
                CommandInterface.RunCommand("dotnet", new string[] { "build" }, Path.Combine(projectDir, "dist", "functional"));

                foreach (var file in
                         Directory.EnumerateFiles(Path.Combine(projectDir, "dist", "functional", "bin", "Debug", "netcoreapp3.1")))
                {
                    File.Copy(file, Path.Combine(projectDir, "dist", "bin", new FileInfo(file).Name), true);
                }
            }

            CommandInterface.RunCommand(Path.Combine(projectDir, "dist", "bin", ninjaName), new string[0], projectDir, true);
        }
Exemple #2
0
        public static void ActionUpdate(string projectDir)
        {
            var projectYaml = ParseYaml(projectDir);

            Console.WriteLine("Downloading the Functional compiler...");

            // clone the compiler
            CommandInterface.RunCommand("git", new string[] { "clone", "https://github.com/iqbigbang/functional.git" }, Path.Combine(projectDir, "dist"));

            Console.WriteLine("Building the Functional compiler...");

            CommandInterface.RunCommand("dotnet", new string[] { "publish", "-c", "release" }, Path.Combine(projectDir, "dist", "functional"));

            Console.WriteLine("Building the garbage collector...");

            CommandInterface.RunCommand(GetCommand(projectYaml.CToolChain), new string[] { "-c", "-o", "../gc.o", "-O2", "-std=gnu99", "-DNODEBUG", "gc.c" }, Path.Combine(projectDir, "dist", "functional", "std", "gc"));

            Console.WriteLine("Copying files...");

            // copy the compiler files into dist/bin
            foreach (var file in
                     Directory.EnumerateFiles(Path.Combine(projectDir, "dist", "functional", "bin", "release", "netcoreapp3.1", "publish")))
            {
                File.Copy(file, Path.Combine(projectDir, "dist", "bin", new FileInfo(file).Name), true);
            }

            // copy standard library files into dist/std
            foreach (var file in
                     Directory.EnumerateFiles(Path.Combine(projectDir, "dist", "functional", "std")))
            {
                File.Copy(file, Path.Combine(projectDir, "dist", "std", new FileInfo(file).Name), true);
            }

            Console.WriteLine("Cleaning up...");

            // On Windows, the files in folders in .git/objects are set as readonly and the system won't let us delete them
            // so we have to manually change the attribute before deletion
            if (CommandInterface.IsWindows)
            {
                foreach (var folder in Directory.EnumerateDirectories(Path.Combine(projectDir, "dist", "functional", ".git", "objects")))
                {
                    foreach (var file in Directory.EnumerateFiles(folder))
                    {
                        var attributes = File.GetAttributes(file);
                        if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            attributes &= ~FileAttributes.ReadOnly;
                            File.SetAttributes(file, attributes);
                        }
                    }
                }
            }

            // remove dist/functional
            Directory.Delete(Path.Combine(projectDir, "dist", "functional"), true);
        }
Exemple #3
0
        public static void ActionRun(string projectDir)
        {
            ActionBuild(projectDir);
            var projectYaml = ParseYaml(projectDir);

            var projectExecutable = Path.Combine(projectDir, projectYaml.Name);

            if (CommandInterface.IsWindows)
            {
                projectExecutable += ".exe";
            }

            CommandInterface.RunCommand(projectExecutable, new string[] { }, ".", true);
        }