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

Commit 9b207c7

Browse files
committed
add support multiple files for compile and run
1 parent c935090 commit 9b207c7

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
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.621-beta</Version>
10+
<Version>0.70.643-beta</Version>
1111
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1212
<PlatformTarget>x64</PlatformTarget>
1313
</PropertyGroup>

src/cmd/BuildCommand.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
using System;
44
using System.Collections.Generic;
55
using System.ComponentModel;
6+
using System.Drawing;
67
using System.IO;
78
using System.Linq;
89
using System.Threading.Tasks;
910
using Ancient.ProjectSystem;
11+
using ancient.runtime;
1012
using cli;
1113
using etc;
1214
using Internal;
@@ -41,36 +43,46 @@ public async Task<int> Execute(bool isTemp)
4143

4244

4345
var acc_bin = Dirs.Bin.ACC.FullName;
44-
45-
46-
var argBuilder = new List<string>();
47-
4846
var files = Directory.GetFiles(directory, "*.asm");
4947

5048
if (!files.Any())
5149
return await Fail($"'*.asm' sources code in '{directory}' for compile not found.");
5250

51+
if(!files.Any(x => x.Contains("entry")))
52+
Console.WriteLine($"{":warning:".Emoji()} {"'entry.asm' file not found, maybe VM cannot start executing files.".Color(Color.Orange)}");
53+
54+
try
55+
{
56+
foreach (var file in files) Compile(file, isTemp);
57+
return await Success();
58+
}
59+
catch (Win32Exception e) // AccessDenied on linux
60+
{
61+
Console.WriteLine($"{":x:".Emoji()} {e.Message}");
62+
return await Fail($"Run [chmod +x \"{acc_bin}\"] for resolve this problem.");
63+
}
64+
}
65+
66+
private void Compile(string file, bool isTemp)
67+
{
68+
var directory = Directory.GetCurrentDirectory();
69+
var acc_bin = Dirs.Bin.ACC.FullName;
70+
var argBuilder = new List<string>();
5371
var outputDir = "bin";
5472

5573
if (isTemp)
5674
outputDir = "obj";
5775
var Project = AncientProject.FromLocal();
58-
argBuilder.Add($"-o ./{outputDir}/{Project.Name}");
76+
var fileName = Path.GetFileNameWithoutExtension(file);
77+
argBuilder.Add($"-o ./{outputDir}/{fileName}");
5978
if (Project.Extension != null)
6079
argBuilder.Add($"-e {Project.Extension}");
61-
argBuilder.Add($"-s \"{files.First()}\"");
80+
argBuilder.Add($"-s \"{file}\"");
6281

6382
var external = new ExternalTools(acc_bin, string.Join(" ", argBuilder));
6483
Directory.CreateDirectory(Path.Combine(directory, outputDir));
65-
try
66-
{
67-
return external.Start().Wait().ExitCode();
68-
}
69-
catch (Win32Exception e) // AccessDenied on linux
70-
{
71-
Console.WriteLine($"{":x:".Emoji()} {e.Message}");
72-
return await Fail($"Run [chmod +x \"{acc_bin}\"] for resolve this problem.");
73-
}
84+
external.Start().Wait().ExitCode();
85+
7486
}
7587
}
7688
}

src/cmd/VMCommand.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace rune.cmd
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
56
using System.IO;
@@ -60,8 +61,19 @@ internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory
6061
var files = Directory.GetFiles(Path.Combine("obj"), "*.*")
6162
.Where(x => x.EndsWith(".dlx") || x.EndsWith(".bios")).ToArray();
6263

63-
if (files.Any())
64-
argBuilder.Add($"\"{Path.Combine("obj", Path.GetFileNameWithoutExtension(files.First()))}\"");
64+
if (files.Length > 1 && !files.Any(x => x.Contains("entry")))
65+
return await Fail($"Cannot find 'entry.dlx'");
66+
67+
string GetRunArg(Func<string, bool> predicate)
68+
{
69+
var target = files.First(predicate);
70+
var formatted = Path.GetFileNameWithoutExtension(target);
71+
return $"\"{Path.Combine("obj", formatted)}\"";
72+
}
73+
74+
argBuilder.Add(files.Length == 1 ?
75+
GetRunArg(_ => true) :
76+
GetRunArg(x => x.Contains("entry")));
6577

6678
var external = new ExternalTools(vm_bin, string.Join(" ", argBuilder));
6779

0 commit comments

Comments
 (0)