@@ -7,6 +7,7 @@ namespace KScr.Build;
77
88public class Module
99{
10+ private readonly Log log ;
1011 public readonly ModuleInfo ? ModulesInfo ;
1112 public readonly ModuleInfo ModuleInfo ;
1213 public readonly DirectoryInfo RootDir ;
@@ -16,6 +17,7 @@ public Module(ModuleInfo? modulesInfo, ModuleInfo moduleInfo, DirectoryInfo root
1617 ModulesInfo = modulesInfo ;
1718 ModuleInfo = moduleInfo ;
1819 RootDir = rootDir ;
20+ log = new Log ( Notation ) ;
1921 }
2022
2123 public ProjectInfo Project => ModulesInfo != null ? ModulesInfo . Project + ModuleInfo . Project : ModuleInfo . Project ;
@@ -30,10 +32,9 @@ private IEnumerable<T> Concat<T>(IEnumerable<T>? first, IEnumerable<T>? second)
3032
3133 public void RunBuild ( )
3234 {
33- Log < Module > . WithExceptionLogger ( ( ) =>
35+ log . RunWithExceptionLogger ( ( ) =>
3436 {
35- var oldwkdir = Environment . CurrentDirectory ;
36- Log < KScrBuild > . At ( LogLevel . Debug , $ "Set working Directory for module: { Environment . CurrentDirectory = RootDir . FullName } ") ;
37+ ( var oldwkdir , Environment . CurrentDirectory ) = ( Environment . CurrentDirectory , RootDir . FullName ) ;
3738
3839 var cmd = new CmdCompile ( )
3940 {
@@ -46,9 +47,9 @@ public void RunBuild()
4647 } ;
4748
4849 long compileTime = - 1 , ioTime = - 1 ;
49- if ( cmd . Output . IsUpToDate ( KScrBuild . Md5Path ) )
50+ if ( ! KScrBuild . Rebuild && cmd . Output . IsUpToDate ( KScrBuild . Md5Path ) )
5051 {
51- Log < Module > . At ( LogLevel . Config , $ "Build { Notation } not necessary; output dir is up-to-date") ;
52+ log . At ( LogLevel . Config , $ "Build { Notation } not necessary; output dir is up-to-date") ;
5253 goto skipBuild ;
5354 }
5455
@@ -59,17 +60,17 @@ public void RunBuild()
5960 KScrStarter . LoadClasspath ( cmd ) ;
6061 }
6162
62- Log < Module > . At ( LogLevel . Config , $ "Compiling source '{ cmd . Source } ' into '{ cmd . Output } '...") ;
63+ log . At ( LogLevel . Config , $ "Compiling source '{ cmd . Source } ' into '{ cmd . Output } '...") ;
6364 compileTime = KScrStarter . CompileSource ( cmd , cmd . PkgBase ) ;
6465 if ( KScrStarter . VM . CompilerErrors . Count > 0 )
6566 foreach ( var error in KScrStarter . VM . CompilerErrors )
66- Log < Module > . At ( LogLevel . Error , "Compiler Error:\r \n " + error ) ;
67+ log . At ( LogLevel . Error , "Compiler Error:\r \n " + error ) ;
6768 ioTime = KScrStarter . WriteClasses ( cmd ) ;
6869
6970 skipBuild :
7071 ioTime += DebugUtil . Measure ( ( ) => SaveToFiles ( ) ) ;
7172 cmd . Output . UpdateMd5 ( KScrBuild . Md5Path ) ;
72- Log < Module > . At ( LogLevel . Info , $ "Build { Notation } succeeded; { KScrStarter . IOTimeString ( compileTime , ioTime : ioTime ) } ") ;
73+ log . At ( LogLevel . Info , $ "Build { Notation } succeeded; { KScrStarter . IOTimeString ( compileTime , ioTime : ioTime ) } ") ;
7374 Environment . CurrentDirectory = oldwkdir ;
7475 } , $ "Build { Notation } failed with exception") ;
7576 }
@@ -79,12 +80,12 @@ public void SaveToFiles(string dir = null!)
7980 dir ??= Build . Output ?? Path . Combine ( Environment . CurrentDirectory , "build/classes/" ) ;
8081 // Create FileStream for output ZIP archive
8182 var lib = new FileInfo ( Build . OutputLib ?? Path . Combine ( dir , RuntimeBase . ModuleLibFile ) ) ;
82- if ( lib . IsUpToDate ( KScrBuild . Md5Path ) )
83+ if ( ! KScrBuild . Rebuild && lib . IsUpToDate ( KScrBuild . Md5Path ) )
8384 {
84- Log < Module > . At ( LogLevel . Config , $ "Create Package { Notation } not necessary; output library is up-to-date") ;
85+ log . At ( LogLevel . Config , $ "Create Package { Notation } not necessary; output library is up-to-date") ;
8586 return ;
8687 }
87- Log < Module > . At ( LogLevel . Debug , $ "Writing module { Notation } to file { lib . FullName } ") ;
88+ log . At ( LogLevel . Debug , $ "Writing module { Notation } to file { lib . FullName } ") ;
8889 if ( lib . Exists )
8990 lib . Delete ( ) ;
9091 var zipFile = lib . OpenWrite ( ) ;
0 commit comments