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

Commit af21dc4

Browse files
committed
change logic install binaries for vm\compiler
1 parent e4ef6d7 commit af21dc4

File tree

3 files changed

+62
-80
lines changed

3 files changed

+62
-80
lines changed

src/Rune.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<RootNamespace>Rune.CLI</RootNamespace>
88
<ApplicationIcon>resource\icon.ico</ApplicationIcon>
99
<StartupObject></StartupObject>
10-
<Version>0.70.618-beta</Version>
10+
<Version>0.70.619-beta</Version>
1111
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1212
<PlatformTarget>x64</PlatformTarget>
1313
</PropertyGroup>

src/cmd/InstallCommand.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
using System;
44
using System.Drawing;
55
using System.IO;
6+
using System.IO.Compression;
7+
using System.Linq;
68
using System.Threading.Tasks;
79
using Ancient.ProjectSystem;
810
using cli;
911
using etc;
1012
using Internal;
13+
using MoreLinq;
1114

1215
public class InstallCommand : RuneCommand<InstallCommand>, IWithProject
1316
{
@@ -42,6 +45,11 @@ internal override CommandLineApplication Setup()
4245

4346
public async Task<int> Execute(string package, CommandOption registryOption)
4447
{
48+
if (package == "vm")
49+
return await InstallVMBinaries();
50+
if (package == "acc" || package == "compiler")
51+
return await InstallCompilerBinaries();
52+
4553
var registry =
4654
registryOption.HasValue() ?
4755
registryOption.Value() :
@@ -85,5 +93,52 @@ public async Task<int> Execute(string package, CommandOption registryOption)
8593
}
8694
return await Success();
8795
}
96+
97+
private async Task<int> InstallCompilerBinaries()
98+
{
99+
try
100+
{
101+
if (Dirs.CompilerFolder.EnumerateFiles().Any())
102+
Console.WriteLine($"Detected already installed compiler, reinstall...".Color(Color.Orange));
103+
104+
105+
if (Dirs.CompilerFolder.EnumerateFiles().Any())
106+
_ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();
107+
108+
var result = await Appx.By(AppxType.acc)
109+
.DownloadAsync();
110+
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
111+
await RuneTask.Fire(() =>
112+
ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName));
113+
}
114+
catch (Exception e)
115+
{
116+
Console.WriteLine(e);
117+
}
118+
return await Success();
119+
}
120+
private async Task<int> InstallVMBinaries()
121+
{
122+
try
123+
{
124+
if (Dirs.CompilerFolder.EnumerateFiles().Any())
125+
Console.WriteLine($"Detected already installed vm, reinstall...".Color(Color.Orange));
126+
127+
128+
if (Dirs.CompilerFolder.EnumerateFiles().Any())
129+
_ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();
130+
131+
var result = await Appx.By(AppxType.acc)
132+
.DownloadAsync();
133+
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
134+
await RuneTask.Fire(() =>
135+
ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName));
136+
}
137+
catch (Exception e)
138+
{
139+
Console.WriteLine(e);
140+
}
141+
return await Success();
142+
}
88143
}
89144
}

src/cmd/VMCommand.cs

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
namespace rune.cmd
22
{
3-
using System;
43
using System.Collections.Generic;
54
using System.ComponentModel;
65
using System.IO;
7-
using System.IO.Compression;
86
using System.Linq;
97
using System.Threading.Tasks;
108
using cli;
119
using etc;
1210
using etc.ExternalCommand;
1311
using Internal;
14-
using MoreLinq;
12+
using static System.Console;
1513

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

27-
app.Command("install", InstallVM);
28-
2925
app.HelpOption("-h|--help");
3026
var dotnetBuild = new BuildCommand();
3127
var vm = new VMCommand();
@@ -42,79 +38,15 @@ internal override CommandLineApplication Setup()
4238
});
4339
return app;
4440
}
45-
46-
internal void InstallACC(CommandLineApplication app)
47-
{
48-
app.Description = $"Install latest ancient compiler.";
49-
var force = app.Option("-f|--force", "Force install binaries?", CommandOptionType.BoolValue);
50-
51-
bool isForce() => force.HasValue() && force.BoolValue != null && force.BoolValue.Value;
52-
app.OnExecute(async () =>
53-
{
54-
try
55-
{
56-
if (!isForce() && Dirs.CompilerFolder.EnumerateFiles().Any())
57-
return await Fail($"{":x:".Emoji()} {"Already".Nier(2)} installed. Try rune vm install compiler --force");
58-
59-
60-
if (Dirs.CompilerFolder.EnumerateFiles().Any())
61-
_ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();
62-
63-
var result = await Appx.By(AppxType.acc)
64-
.DownloadAsync();
65-
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
66-
await RuneTask.Fire(() =>
67-
ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName));
68-
}
69-
catch (Exception e)
70-
{
71-
Console.WriteLine(e);
72-
}
73-
return await Success();
74-
});
75-
}
76-
77-
internal void InstallVM(CommandLineApplication app)
78-
{
79-
app.Description = $"Install latest ancient VM.";
80-
var force = app.Option("-f|--force", "Force install binaries?", CommandOptionType.BoolValue);
81-
82-
bool isForce() => force.HasValue() && force.BoolValue != null && force.BoolValue.Value;
83-
app.Command("compiler", InstallACC);
84-
app.OnExecute(async () =>
85-
{
86-
try
87-
{
88-
if (!isForce() && Dirs.VMFolder.EnumerateFiles().Any())
89-
return await Fail($"{":x:".Emoji()} {"Already".Nier(2)} installed. Try rune vm install --force");
90-
91-
92-
if (Dirs.VMFolder.EnumerateFiles().Any())
93-
_ = Dirs.VMFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray();
94-
95-
var result = await Appx.By(AppxType.vm)
96-
.DownloadAsync();
97-
Console.Write($"{":open_file_folder:".Emoji()} Extract files");
98-
await RuneTask.Fire(() =>
99-
ZipFile.ExtractToDirectory(result.FullName, Dirs.VMFolder.FullName));
100-
}
101-
catch (Exception e)
102-
{
103-
Console.WriteLine(e);
104-
}
105-
return await Success();
106-
});
107-
}
108-
109-
41+
11042
internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory, CommandOption fastWrite, CommandOption isInteractive)
11143
{
11244
var dir = Directory.GetCurrentDirectory();
11345
if (!this.Validate(dir))
11446
return await Fail();
11547

11648
if (!Dirs.Bin.VM.Exists)
117-
return await Fail($"VM is not installed. Try 'rune vm install'");
49+
return await Fail($"VM is not installed. Try 'rune install vm'");
11850

11951

12052
var vm_bin = Dirs.Bin.VM.FullName;
@@ -148,16 +80,11 @@ internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory
14880
.Wait()
14981
.ExitCode();
15082
}
151-
catch (Win32Exception e)
83+
catch (Win32Exception e) // AccessDenied on linux
15284
{
153-
Console.WriteLine($"{":x:".Emoji()} {e.Message}");
154-
Console.WriteLine($"{"TODO"} try fix...");
155-
await OS.FireAsync($"chmod +x \"{vm_bin}\"");
85+
WriteLine($"{":x:".Emoji()} {e.Message}");
86+
return await Fail($"Run [chmod +x \"{vm_bin}\"] for resolve this problem.");
15687
}
157-
return result
158-
.Start()
159-
.Wait()
160-
.ExitCode();
16188
}
16289
}
16390
}

0 commit comments

Comments
 (0)