Skip to content

Commit

Permalink
move example code out of the directory
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Jan 13, 2023
1 parent e81032a commit 72f284d
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Test Build - build.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="Test Build - build" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/kscr-build/bin/net6.0/kbuild.exe" />
<option name="PROGRAM_PARAMETERS" value="build -r" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/modular/testing" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand Down
2 changes: 1 addition & 1 deletion Test Build - dependencies.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="Test Build - dependencies" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/kscr-build/bin/net6.0/kbuild.exe" />
<option name="PROGRAM_PARAMETERS" value="dependencies" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/modular/" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand Down
2 changes: 1 addition & 1 deletion Test Build - info.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="Test Build - info" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/kscr-build/bin/net6.0/kbuild.exe" />
<option name="PROGRAM_PARAMETERS" value="info" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/modular" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand Down
2 changes: 1 addition & 1 deletion Test Build - run.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="Test Build - run" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/kscr-build/bin/net6.0/kbuild.exe" />
<option name="PROGRAM_PARAMETERS" value="run -r" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/modular/testing/" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/testing" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
},
"build": {
"pre": "runBeforeBuild",
"post": "runAfterBuild"
"post": "runAfterBuild",
"mainClassName": "org.comroid.kscr.test.Program"
},
"dependencies": [
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 23 additions & 10 deletions kscr-build/KScrBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ static KScrBuild()

public static void Main(string[] args)
{
Log<KScrBuild>.Get().RunWithExceptionLogger(() => Parser.Default.ParseArguments<CmdInfo, CmdDependencies, RebuildCmdBuild, CmdPublish, RebuildCmdRun>(args)
.WithParsed<CmdInfo>(PrintInfo)
.WithParsed<CmdDependencies>(PrintDependencies)
.WithParsed<RebuildCmdBuild>(RunBuild)
.WithParsed<CmdPublish>(RunPublish)
.WithParsed<RebuildCmdRun>(RunRun)
, "Build failed with unhandled exception");
Parser.Default.ParseArguments<CmdInfo, CmdDependencies, RebuildCmdBuild, CmdPublish, RebuildCmdRun>(args)
.WithParsed<CmdInfo>(cmd => Log<KScrBuild>.Get()
.WrapWithExceptionLogger<CmdInfo>(PrintInfo, "Info failed with unhandled Exception")(cmd))
.WithParsed<CmdDependencies>(cmd => Log<KScrBuild>.Get()
.WrapWithExceptionLogger<CmdDependencies>(PrintDependencies,
"Dependencies failed with unhandled Exception")(cmd))
.WithParsed<RebuildCmdBuild>(cmd => Log<KScrBuild>.Get()
.WrapWithExceptionLogger<RebuildCmdBuild>(RunBuild, "Build failed with unhandled Exception")(cmd))
.WithParsed<CmdPublish>(cmd => Log<KScrBuild>.Get()
.WrapWithExceptionLogger<CmdPublish>(RunPublish, "Publish failed with unhandled Exception")(cmd))
.WithParsed<RebuildCmdRun>(cmd => Log<KScrBuild>.Get()
.WrapWithExceptionLogger<RebuildCmdRun>(RunRun, "Run failed with unhandled Exception")(cmd));
}

private static void RunRun(RebuildCmdRun rebuildCmd)
Expand All @@ -39,10 +44,18 @@ private static void RunRun(RebuildCmdRun rebuildCmd)
foreach (var module in exported)
module.RunBuild();

if (exported.Select(mod => mod.ModuleInfo).Append(baseModule)
if (new[] { baseModule }.Concat(exported.Select(mod => mod.ModuleInfo))
.FirstOrDefault(mod => mod?.MainClassName != null) is { } mod)
{
Log<Module>.At(LogLevel.Info, $"Executing module {mod.Notation}...");
KScrStarter.Execute(out _, mod.MainClassName);
else Package.FindEntrypoint()?.Invoke(KScrStarter.VM, RuntimeBase.MainStack);
}
else
{
var findEntrypoint = Package.FindEntrypoint(baseModule?.MainClassName);
Log<Module>.At(LogLevel.Info, $"Executing module {baseModule!.Notation}...");
findEntrypoint.Invoke(KScrStarter.VM, RuntimeBase.MainStack);
}
}

private static void RunPublish(CmdPublish cmd)
Expand Down Expand Up @@ -74,7 +87,7 @@ private static (ModuleInfo? baseModule, List<Module> exported) ExtractModules(Cm
Log<KScrBuild>.At(LogLevel.Config, $"Found Module root {dir.FullName} as Project {modulesInfo.Project}");
List<Module> exported = new();
foreach (var moduleFile in dir.EnumerateFiles(RuntimeBase.ModuleFile, SearchOption.AllDirectories)
.Where(file => !Path.GetRelativePath(dir.FullName, file.FullName).StartsWith("build" + Path.DirectorySeparatorChar)))
.Where(file => !file.FullName.Contains(Path.Combine("build","classes"))))
{
var moduleInfo = JsonSerializer.Deserialize<ModuleInfo>(File.ReadAllText(moduleFile.FullName)) ??
throw new Exception($"Unable to parse {RuntimeBase.ModuleFile} in module {moduleFile.Directory!.FullName}");
Expand Down
6 changes: 3 additions & 3 deletions kscr-build/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void RunBuild()
{
Args = ArraySegment<string>.Empty,
Classpath = Dependencies.Select(dep => DependencyManager.Resolve(this, dep)).Where(x => x != null)!,
Output = new DirectoryInfo(ModulesInfo?.Build.Output ?? Build.Output ?? "build/classes/"),
Output = new DirectoryInfo(Path.Combine(ModulesInfo?.Build.Output ?? Build.Output ?? Path.Combine(Environment.CurrentDirectory, "build"), "classes")),
PkgBase = ModulesInfo?.Build.BasePackage ?? Build.BasePackage,
Source = ModulesInfo?.Build.Sources ?? Build.Sources ?? "src/main/",
System = (ModulesInfo?.Build.BasePackage ?? Build.BasePackage) == "org.comroid.kscr"
Expand Down Expand Up @@ -72,12 +72,12 @@ public void RunBuild()
cmd.Output.UpdateMd5(KScrBuild.Md5Path);
log.At(LogLevel.Info, $"Build {Notation} succeeded; {KScrStarter.IOTimeString(compileTime, ioTime: ioTime)}");
Environment.CurrentDirectory = oldwkdir;
}, $"Build {Notation} failed with exception");
}, $"Build {Notation} failed with exception", LogLevel.Error);
}

public void SaveToFiles(string dir = null!)
{
dir ??= Build.Output ?? Path.Combine(Environment.CurrentDirectory, "build/classes/");
dir ??= Path.Combine(Build.Output ?? Path.Combine(Environment.CurrentDirectory, "build"), "classes");
// Create FileStream for output ZIP archive
var lib = new FileInfo(Build.OutputLib ?? Path.Combine(dir, RuntimeBase.ModuleLibFile));
if (!KScrBuild.Rebuild && lib.IsUpToDate(KScrBuild.Md5Path))
Expand Down
14 changes: 1 addition & 13 deletions kscr-core/RuntimeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,7 @@ public IObjectRef PutObject(Stack stack, VariableContext varctx, IObject value,

public Stack Execute(string? mainClassName = null)
{
Method method;
if (mainClassName == null)
{
method = Package.FindEntrypoint();
}
else
{
var cls = FindType(mainClassName) ??
throw new FatalException($"Main class with name {mainClassName} was not found!");
method = cls.DeclaredMembers["main"] as Method ??
throw new FatalException("Main class has no main() method!");
}

var method = Package.FindEntrypoint(mainClassName);
var stack = MainStack;

try
Expand Down

0 comments on commit 72f284d

Please sign in to comment.