About Monkey 2 › Forums › Monkey 2 Development › smartbuild – A tool for updating the modules.
This topic contains 2 replies, has 2 voices, and was last updated by
cocon 2 years ago.
-
AuthorPosts
-
April 12, 2017 at 3:11 am #7863
This tool was based on Degac’s cool idea. It will try to build modules only if any source file is more recent than any of the library files. It will detect this timestamp difference and if there is any, it will run the mx2cc tool.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214' set build settings' target name = smartbuild' application type = console'' to run it from the command line see this example' smartbuild D:\Programming\monkey2\bin\mx2cc_windows.exe D:\Programming\monkey2\modules desktop#Import "<libc>"#Import "<std>"Using std..Class Config AbstractGlobal RootDir:String = ""Global Mx2cc:String = ""Global Target:String = ""Function Set:Bool()Return Config.Mx2cc <> "" And Mx2cc <> "" And Target <> ""EndEndClass ModuleField Name:StringField Location:StringProperty FullPath:String()Return CombinePath(Location, Name)EndField SourceTime:LongField BuildTime:LongEndClass ModuleCollection AbstractPublicGlobal Modules := New List<Module>Global ModulesToUpdate := New List<Module>Function ScanModules()RetreiveModules()DetectBuildTimes()DetectSourceTimes()DetectModulesToUpdate()EndPrivateFunction RetreiveModules()For Local item := Eachin LoadDir(Config.RootDir)Local m := New Modulem.Name = itemm.Location = Config.RootDir.Replace("\", "/")Modules.Add(m)NextEndFunction DetectSourceTimeForModule(module:Module, path:String = "")Local includedFiles := New String[](".h", ".c", ".cpp", ".monkey2")If path = "" Then path = module.FullPathFor Local item := Eachin LoadDir(path)' before doing anything skip the buildv directoriesIf item.Contains(".buildv") Then Continue' repeat this function again with recursion to visit all directoriesDetectSourceTimeForModule(module, CombinePath(path, item))' check for files with valid extensionsFor Local i := Eachin includedFilesLocal filePath := CombinePath(path, item)If i = ExtractExt(filePath)' update the source time to the most recent oneLocal sourceTime := GetFileTime(CombinePath(path, item))If sourceTime > module.SourceTimemodule.SourceTime = sourceTimeReturnEndEndNextNextEndFunction DetectSourceTimes()For Local module := Eachin ModulesDetectSourceTimeForModule(module)NextEndFunction DetectBuildTimeForModule(module:Module, path:String = "")Local includedFiles := New String[](".a", ".so", ".dylib")For Local item := Eachin LoadDir(path)' repeat this function again with recursion to visit all directoriesDetectBuildTimeForModule(module, CombinePath(path, item))' check for files with valid extensionsFor Local i := Eachin includedFilesLocal libPath := CombinePath(path, item)If i = ExtractExt(libPath)' update the build time to the most recent oneLocal libTime := GetFileTime(libPath)If module.BuildTime < libTimemodule.BuildTime = libTimeReturnEndEndNextNextEndFunction DetectBuildTimes()For Local module := Eachin Modules' locate the buildv direcoryLocal buildPath := ""For Local item := Eachin LoadDir(module.FullPath)If item.Contains(".buildv")buildPath = CombinePath(module.FullPath, item)EndNextIf buildPath = "" Then Continue' locate the compiled libraryDetectBuildTimeForModule(module, buildPath)NextEndFunction DetectModulesToUpdate()For Local m := Eachin ModulesIf m.SourceTime > m.BuildTimeModulesToUpdate.Add(m)EndNextEndPublicFunction HasModulesToUpdate:Bool()Return ModulesToUpdate.Count() > 0EndFunction ModulesToUpdateMx2cc:String()If Not HasModulesToUpdate() Then Return ""Local out := ""For Local m := Eachin ModulesToUpdateout += m.Name + " "NextReturn outEndEndFunction Main()SetAppArgsConfiguration()'SetUserConfiguration()If Not Config.Set()ReturnEndBuildModules()EndFunction SetAppArgsConfiguration()Local args := AppArgs()If args.Length <> 4Print("Usage: smartbuild mx2cc_location module_location mx2cc_target")ReturnEndConfig.Mx2cc = args[1]Config.RootDir = args[2]Config.Target = args[3]EndFunction SetUserConfiguration()Config.Mx2cc = "D:\Programming\monkey2\bin\mx2cc_windows.exe"Config.RootDir = "D:\Programming\monkey2\modules"Config.Target = "desktop"EndFunction BuildModules()' scan for modulesModuleCollection.ScanModules()' exit if there are no modules to updateIf Not ModuleCollection.HasModulesToUpdate()Print("Completed Without Rebuilding")ReturnEnd' prepare the mx2cc parameters and run itLocal modules := ModuleCollection.ModulesToUpdateMx2cc()Local cmdDebug := Config.Mx2cc + " makemods -config=release -target=" + Config.Target + " " + modulesLocal cmdRelease := Config.Mx2cc + " makemods -config=debug -target=" + Config.Target + " " + modules' start building processPrint("Modules To Rebuild")Print(modules)Print("")Print(cmdDebug)libc.system(cmdDebug)Print("")Print(cmdRelease)libc.system(cmdRelease)Print("")EndFunction CombinePath:String(p1:String, p2:String)Return p1 + "/" + p2EndAttachments:
April 12, 2017 at 11:07 am #7867Wow, I like that someone found my concept/idea useful and make it real & working
I will read carefully your code to see your implementation (I still have an ‘old function/type’ style..!)
Hope that this thing will be one day a Monkey2 compiler ‘feature’ as default.April 12, 2017 at 2:11 pm #7868I had also an idea about squeezing it in Ted2Go, perhaps in the summer I will go for it.
-
AuthorPosts
You must be logged in to reply to this topic.

