Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
change logic install binaries for vm\compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed May 12, 2020
1 parent e4ef6d7 commit af21dc4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/Rune.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RootNamespace>Rune.CLI</RootNamespace>
<ApplicationIcon>resource\icon.ico</ApplicationIcon>
<StartupObject></StartupObject>
<Version>0.70.618-beta</Version>
<Version>0.70.619-beta</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
Expand Down
55 changes: 55 additions & 0 deletions src/cmd/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
using System;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Ancient.ProjectSystem;
using cli;
using etc;
using Internal;
using MoreLinq;

public class InstallCommand : RuneCommand<InstallCommand>, IWithProject
{
Expand Down Expand Up @@ -42,6 +45,11 @@ internal override CommandLineApplication Setup()

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() :
Expand Down Expand Up @@ -85,5 +93,52 @@ public async Task<int> Execute(string package, CommandOption registryOption)
}
return await Success();
}

private async Task<int> InstallCompilerBinaries()
{
try
{
if (Dirs.CompilerFolder.EnumerateFiles().Any())
Console.WriteLine($"Detected already installed compiler, reinstall...".Color(Color.Orange));


if (Dirs.CompilerFolder.EnumerateFiles().Any())
_ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();

var result = await Appx.By(AppxType.acc)
.DownloadAsync();
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
await RuneTask.Fire(() =>
ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName));
}
catch (Exception e)
{
Console.WriteLine(e);
}
return await Success();
}
private async Task<int> InstallVMBinaries()
{
try
{
if (Dirs.CompilerFolder.EnumerateFiles().Any())
Console.WriteLine($"Detected already installed vm, reinstall...".Color(Color.Orange));


if (Dirs.CompilerFolder.EnumerateFiles().Any())
_ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();

var result = await Appx.By(AppxType.acc)
.DownloadAsync();
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
await RuneTask.Fire(() =>
ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName));
}
catch (Exception e)
{
Console.WriteLine(e);
}
return await Success();
}
}
}
85 changes: 6 additions & 79 deletions src/cmd/VMCommand.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
namespace rune.cmd
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using cli;
using etc;
using etc.ExternalCommand;
using Internal;
using MoreLinq;
using static System.Console;

public class VMCommand : RuneCommand<VMCommand>, IWithProject
{
Expand All @@ -24,8 +22,6 @@ internal override CommandLineApplication Setup()
Description = "Execute project in Ancient VM"
};

app.Command("install", InstallVM);

app.HelpOption("-h|--help");
var dotnetBuild = new BuildCommand();
var vm = new VMCommand();
Expand All @@ -42,79 +38,15 @@ internal override CommandLineApplication Setup()
});
return app;
}

internal void InstallACC(CommandLineApplication app)
{
app.Description = $"Install latest ancient compiler.";
var force = app.Option("-f|--force", "Force install binaries?", CommandOptionType.BoolValue);

bool isForce() => force.HasValue() && force.BoolValue != null && force.BoolValue.Value;
app.OnExecute(async () =>
{
try
{
if (!isForce() && Dirs.CompilerFolder.EnumerateFiles().Any())
return await Fail($"{":x:".Emoji()} {"Already".Nier(2)} installed. Try rune vm install compiler --force");
if (Dirs.CompilerFolder.EnumerateFiles().Any())
_ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();
var result = await Appx.By(AppxType.acc)
.DownloadAsync();
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
await RuneTask.Fire(() =>
ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName));
}
catch (Exception e)
{
Console.WriteLine(e);
}
return await Success();
});
}

internal void InstallVM(CommandLineApplication app)
{
app.Description = $"Install latest ancient VM.";
var force = app.Option("-f|--force", "Force install binaries?", CommandOptionType.BoolValue);

bool isForce() => force.HasValue() && force.BoolValue != null && force.BoolValue.Value;
app.Command("compiler", InstallACC);
app.OnExecute(async () =>
{
try
{
if (!isForce() && Dirs.VMFolder.EnumerateFiles().Any())
return await Fail($"{":x:".Emoji()} {"Already".Nier(2)} installed. Try rune vm install --force");
if (Dirs.VMFolder.EnumerateFiles().Any())
_ = Dirs.VMFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();
var result = await Appx.By(AppxType.vm)
.DownloadAsync();
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
await RuneTask.Fire(() =>
ZipFile.ExtractToDirectory(result.FullName, Dirs.VMFolder.FullName));
}
catch (Exception e)
{
Console.WriteLine(e);
}
return await Success();
});
}



internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory, CommandOption fastWrite, CommandOption isInteractive)
{
var dir = Directory.GetCurrentDirectory();
if (!this.Validate(dir))
return await Fail();

if (!Dirs.Bin.VM.Exists)
return await Fail($"VM is not installed. Try 'rune vm install'");
return await Fail($"VM is not installed. Try 'rune install vm'");


var vm_bin = Dirs.Bin.VM.FullName;
Expand Down Expand Up @@ -148,16 +80,11 @@ internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory
.Wait()
.ExitCode();
}
catch (Win32Exception e)
catch (Win32Exception e) // AccessDenied on linux
{
Console.WriteLine($"{":x:".Emoji()} {e.Message}");
Console.WriteLine($"{"TODO"} try fix...");
await OS.FireAsync($"chmod +x \"{vm_bin}\"");
WriteLine($"{":x:".Emoji()} {e.Message}");
return await Fail($"Run [chmod +x \"{vm_bin}\"] for resolve this problem.");
}
return result
.Start()
.Wait()
.ExitCode();
}
}
}

0 comments on commit af21dc4

Please sign in to comment.