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

Commit

Permalink
Call target 'default' if none specified instead of all and allow call…
Browse files Browse the repository at this point in the history
…ing of other targets
  • Loading branch information
Twometer committed Aug 22, 2020
1 parent 2f3d171 commit fc6cded
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
7 changes: 7 additions & 0 deletions nkm/AST/Expression/TargetInvokeExpr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace nkm.AST.Expression
{
public class TargetInvokeExpr : IExpression
{
public string TargetName { get; set; }
}
}
10 changes: 9 additions & 1 deletion nkm/Parser/NekofileParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using nkm.AST;
using nkm.AST.Expression;
using nkm.Logging;
using nkm.Utils;
using System;
Expand Down Expand Up @@ -116,7 +117,14 @@ private void ParseLine(int no, string line)
}
else if (currentToolInvoke == null)
{
currentTarget.Commands.Add(new RawCommandExpr { Value = line });
if (line.StartsWith("%"))
{
currentTarget.Commands.Add(new TargetInvokeExpr { TargetName = line.Substring(1).Trim() });
}
else
{
currentTarget.Commands.Add(new RawCommandExpr { Value = line });
}
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions nkm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ private static void RunBuilder(string target)
return;
}

var targetName = target == string.Empty ? "all targets" : target;
LoggerFactory.Current.Log(LogLevel.Info, $"Building {targetName} in script {buildScript.FullName}...");
if (target == string.Empty)
target = "default";

LoggerFactory.Current.Log(LogLevel.Info, $"Building {target} in script {buildScript.FullName}...");

var runner = new NekofileRunner(parser.Document);
if (!runner.Execute(target))
Expand Down
9 changes: 7 additions & 2 deletions nkm/Runner/NekofileRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using nkm.AST;
using nkm.AST.Expression;
using nkm.Logging;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -28,7 +29,7 @@ public bool Execute(string target)
{
foreach (var expr in nekofile.Expressions)
{
if (expr is TargetDefExpr targetExpr && (target == string.Empty || targetExpr.Name == target))
if (expr is TargetDefExpr targetExpr && targetExpr.Name == target)
{
ExecuteTarget(targetExpr);
}
Expand Down Expand Up @@ -58,6 +59,10 @@ private void ExecuteTarget(TargetDefExpr target)
{
InvokeTool(invokeCmd);
}
else if (cmd is TargetInvokeExpr targetCmd)
{
Execute(targetCmd.TargetName);
}
}
}

Expand Down Expand Up @@ -169,7 +174,7 @@ private void ExecuteCommand(string command)
else
{
startInfo.FileName = "sh";
var escapedArgs = command.Replace("\"", "\\\"");
var escapedArgs = command.Replace("\"", "\\\"");
startInfo.Arguments = $"-c \"{escapedArgs}\"";
}

Expand Down
4 changes: 2 additions & 2 deletions nkm/nkm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>0.1.0</Version>
<Version>0.2.0</Version>
<Authors>Twometer</Authors>
<Product>NekoMake Build System</Product>
<Description>The NekoMake build system is the next-gen and convenient build system used by the nekosys OS</Description>
<PackageProjectUrl>https://github.com/nekosys-os/nkm</PackageProjectUrl>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
<AssemblyVersion>0.2.0.0</AssemblyVersion>
</PropertyGroup>

</Project>

0 comments on commit fc6cded

Please sign in to comment.