Ejemplo n.º 1
0
        private void Compile(string file, bool isTemp)
        {
            var directory  = Directory.GetCurrentDirectory();
            var acc_bin    = Dirs.Bin.ACC.FullName;
            var argBuilder = new List <string>();
            var outputDir  = "bin";

            if (isTemp)
            {
                outputDir = "obj";
            }
            var Project  = AncientProject.FromLocal();
            var fileName = Path.GetFileNameWithoutExtension(file);

            argBuilder.Add($"-o ./{outputDir}/{fileName}");
            if (Project.Extension != null)
            {
                argBuilder.Add($"-e {Project.Extension}");
            }
            argBuilder.Add($"-s \"{file}\"");

            var external = new ExternalTools(acc_bin, string.Join(" ", argBuilder));

            Directory.CreateDirectory(Path.Combine(directory, outputDir));
            external.Start().Wait().ExitCode();
        }
Ejemplo n.º 2
0
        public async Task <int> Execute(string package, CommandOption registryOption)
        {
            if (package == "vm")
            {
                return(await InstallVMBinaries());
            }
            if (package == "acc" || package == "compiler")
            {
                return(await InstallCompilerBinaries());
            }

            var registry =
                registryOption.HasValue() ?
                registryOption.Value() :
                Config.Get("core", "registry", "runic");

            var dir = Directory.GetCurrentDirectory();

            if (!this.Validate(dir))
            {
                return(await Fail());
            }

            if (Indexer.FromLocal().UseLock().Exist(package))
            {
                Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is already {"found".Nier(0).Color(Color.Red)} in project.");
                return(await Fail());
            }


            if (!await Registry.By(registry).Exist(package))
            {
                Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is {"not".Nier(0).Color(Color.Red)} found in '{registry}' registry.");
                return(await Fail());
            }

            try
            {
                var(asm, bytes, spec) = await Registry.By(registry).Fetch(package);

                if (asm is null)
                {
                    return(await Fail());
                }

                Indexer.FromLocal()
                .UseLock()
                .SaveDep(asm, bytes, spec);
                AncientProject.FromLocal().AddDep(package, $"{spec.Version}", DepVersionKind.Fixed);
                Console.WriteLine($"{":movie_camera:".Emoji()} '{package}-{spec.Version}' save to deps is {"success".Nier(0).Color(Color.GreenYellow)}.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString().Color(Color.Red));
                return(await Fail(2));
            }
            return(await Success());
        }
Ejemplo n.º 3
0
        public int Execute(string value)
        {
            var directory = Directory.GetCurrentDirectory();

            if (!Validate(directory))
            {
                return(1);
            }
            var script = AncientProject.FromLocal().scripts.FirstOrDefault(x => x.Key.Equals(value, StringComparison.InvariantCultureIgnoreCase)).Value;

            if (script is null)
            {
                throw new InvalidOperationException($"Command '{value}' not found.");
            }
            Console.WriteLine($"trace :: call :> cmd /c '{script}'".Color(Color.DimGray));
            var proc = default(Process);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                proc = new Process
                {
                    StartInfo = new ProcessStartInfo("cmd.exe", $"/c \"{script}\"")
                    {
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true
                    }
                };
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                proc = new Process
                {
                    StartInfo = new ProcessStartInfo("bash", $"-c \"{script}\"")
                    {
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true
                    }
                };
            }

            proc.Start();
            proc.WaitForExit();

            var err  = proc.StandardError.ReadToEnd();
            var @out = proc.StandardOutput.ReadToEnd();

            if (!string.IsNullOrEmpty(err))
            {
                Console.WriteLine($"{err}".Color(Color.Red));
            }
            if (!string.IsNullOrEmpty(@out))
            {
                Console.WriteLine($"{@out}".Color(Color.DarkGray));
            }

            return(proc.ExitCode);
        }
Ejemplo n.º 4
0
        public int Execute(bool isTemp)
        {
            var directory = Directory.GetCurrentDirectory();

            if (!Validate(directory))
            {
                return(1);
            }

            var ancient_home = Environment.GetEnvironmentVariable("ANCIENT_HOME", EnvironmentVariableTarget.User);

            if (ancient_home is null)
            {
                throw new InvalidOperationException($"env variable 'ANCIENT_HOME' is not set.");
            }
            if (!new DirectoryInfo(ancient_home).Exists)
            {
                throw new InvalidOperationException($"Env variable 'ANCIENT_HOME' is invalid.");
            }

            var acc_home = Path.Combine(ancient_home, "compiler");
            var acc_bin  = Path.Combine(acc_home, "acc.exe");

            if (!new DirectoryInfo(acc_home).Exists || !new FileInfo(acc_bin).Exists)
            {
                throw new InvalidOperationException($"Ancient compiler is not installed.");
            }

            var argBuilder = new List <string>();

            var files = Directory.GetFiles(directory, "*.asm");

            var outputDir = "bin";

            if (isTemp)
            {
                outputDir = "obj";
            }
            var Project = AncientProject.FromLocal();

            argBuilder.Add($"-o ./{outputDir}/{Project.Name}");
            if (Project.Extension != null)
            {
                argBuilder.Add($"-e {Project.Extension}");
            }
            argBuilder.Add($"-s \"{files.First()}\"");

            var external = new ExternalTools(acc_bin, string.Join(" ", argBuilder));

            Directory.CreateDirectory(Path.Combine(directory, outputDir));
            return(external.Start().Wait().ExitCode());
        }
Ejemplo n.º 5
0
        public int Execute(CommandOption registryOption)
        {
            var registry = registryOption.HasValue() ? registryOption.Value() : "github+https://github.com/ancientproject";
            var dir      = Directory.GetCurrentDirectory();

            if (!Validate(dir))
            {
                return(1);
            }
            var indexer = Indexer.FromLocal().UseLock();

            foreach (var(package, _) in AncientProject.FromLocal().deps)
            {
                if (!indexer.Exist(package))
                {
                    if (!Registry.By(registry).Exist(package))
                    {
                        Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is {"not".Nier(0).Color(Color.Red)} found in '{registry}' registry.");
                        continue;
                    }

                    try
                    {
                        var asm = Registry.By(registry).Put(package, out var bytes);

                        if (asm is null)
                        {
                            Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' restore {"fail".Nier(0).Color(Color.Red)}.");
                            continue;
                        }

                        Indexer.FromLocal()
                        .UseLock()
                        .SaveDep(asm, bytes, registry);
                        Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' restore {"success".Nier(0).Color(Color.GreenYellow)}.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' restore {"fail".Nier(0).Color(Color.Red)}.");
                        Trace.WriteLine(e.ToString());
                        continue;
                    }
                }
            }
            return(0);
        }
Ejemplo n.º 6
0
        public int Execute(string package, CommandOption registryOption)
        {
            var registry = registryOption.HasValue() ? registryOption.Value() : "github+https://github.com/ancientproject";
            var dir      = Directory.GetCurrentDirectory();

            if (!Validate(dir))
            {
                return(1);
            }

            if (Indexer.FromLocal().UseLock().Exist(package))
            {
                Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is already {"found".Nier(0).Color(Color.Red)} in project.");
                return(1);
            }


            if (!Registry.By(registry).Exist(package))
            {
                Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is {"not".Nier(0).Color(Color.Red)} found in '{registry}' registry.");
                return(1);
            }

            try
            {
                var asm = Registry.By(registry).Put(package, out var bytes);

                if (asm is null)
                {
                    return(1);
                }

                Indexer.FromLocal()
                .UseLock()
                .SaveDep(asm, bytes, registry);
                AncientProject.FromLocal().AddDep(package, asm.GetName().Version.ToString(), DepVersionKind.Fixed);
                Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' save to deps is {"success".Nier(0).Color(Color.GreenYellow)}.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString().Color(Color.Red));
                return(2);
            }
            return(0);
        }
Ejemplo n.º 7
0
        public async Task <int> Execute(CommandOption registryOption)
        {
            var registry = registryOption.HasValue() ? registryOption.Value() : "runic";
            var dir      = Directory.GetCurrentDirectory();

            if (!this.Validate(dir))
            {
                return(1);
            }
            var indexer = Indexer.FromLocal().UseLock();

            foreach (var package in AncientProject.FromLocal().deps.Select(x => x.Key).Where(package => !indexer.Exist(package)))
            {
                if (!await Registry.By(registry).Exist(package))
                {
                    Console.WriteLine($"{":page_with_curl:".Emoji()} '{package}' is {"not".Nier(0).Color(Color.Red)} found in '{registry}' registry.");
                    continue;
                }

                try
                {
                    var(asm, bytes, spec) = await Registry.By(registry).Fetch(package);

                    if (asm is null)
                    {
                        Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' restore {"fail".Nier(0).Color(Color.Red)}.");
                        continue;
                    }

                    Indexer.FromLocal()
                    .UseLock()
                    .SaveDep(asm, bytes, spec);
                    Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' restore {"success".Nier(0).Color(Color.GreenYellow)}.");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"{":movie_camera:".Emoji()} '{package}' restore {"fail".Nier(0).Color(Color.Red)}.");
                    Trace.WriteLine(e.ToString());
                    continue;
                }
            }
            return(await Success());
        }