Commits

Thibaut Colar  committed 7c852c0

When we have a project of the form prj/src/build.fan then rebase the project root to prj so we see all the files
Build file utilities

  • Participants
  • Parent commits 5e54716

Comments (0)

Files changed (8)

File src/brie/build.fan

                `fan/command/`,
                `fan/widget/`]
     resDirs = [`res/`]
-    version = Version("1.0.0")
+    version = Version("1.0.1")
     meta    =  ["license.name"   : "Academic License",
                 "vcs.uri"   : "https://bitbucket.org/tcolar/camembert"]
     docSrc  = true
   }
-}
+}

File src/brie/fan/index/IndexCrawler.fan

 
   const Index index
 
+  ** Reindex all pods
   Duration indexAll()
   {
     index.setIsIndexing(true)
     finally index.setIsIndexing(false)
   }
 
+  ** Index a given pod (ie: after it's rebuilt)
   Obj? indexPod(PodInfo pod)
   {
     index.setIsIndexing(true)
     finally index.setIsIndexing(false)
   }
 
+//////////////////////////////////////////////////////////////////////////
+// Private methods
+//////////////////////////////////////////////////////////////////////////
+
+
+  ** Index a folder of sources as provided by the user
   private Void indexSrcDir(File dir)
   {
     if (!dir.isDir) return
     dir.listDirs.each |subDir| { indexSrcDir(subDir) }
   }
 
+  ** Index a folder of pods(libraries) as provided by the user
   private Void indexPodDir(File dir)
   {
     if (!dir.isDir) return
     dir.listDirs.each |subDir| { indexPodDir(subDir) }
   }
 
+
   private Bool isPodSrcDir(File dir)
   {
-    build :=  dir + `build.fan`
-    if (!build.exists) return false
-
-    try
-    {
-      in := build.in
-      Str? line
-      while ((line = in.readLine) != null)
-      {
-        if (line.contains("class ")) break
-      }
-      in.close
-      return line.contains("BuildPod")
-    }
-    catch (Err e) e.trace
-    return false
+    return FileUtil.findBuildPod(dir, dir) != null
   }
 
   ** Relying on dir being == to podName is asking for troublee from build.fan
   ** So trying to lokup the real nam
   private Str getPodName(File buildDir)
   {
-    build :=  buildDir + `build.fan`
-    name := build.readAllLines.eachWhile |Str s -> Str?|
+    build :=  FileUtil.findBuildPod(buildDir, buildDir)
+    if(build == null)
+      return buildDir.name
+    Str? name
+    try
     {
-       line := s.trim
-       parts := line.split('=')
-       if(parts.size != 2) return null
-       val := parts[1].trim
-       if(val[0]=='"' && val[-1]=='"' && val[1].isAlpha) // (might start with $ or % -> variable)
-        return val[1..-2]
-       return null
-    }
+      name = build.readAllLines.eachWhile |Str s -> Str?|
+      {
+         line := s.trim
+         parts := line.split('=')
+         if(parts.size != 2) return null
+         val := parts[1].trim
+         if(val[0]=='"' && val[-1]=='"' && val[1].isAlpha) // (might start with $ or % -> variable)
+          return val[1..-2]
+         return null
+      }
+    } catch(Err e) {e.trace}
     if(name == null)
     {
       echo("Didn't find the podName in $build.osPath - Will use $buildDir.name")
     return name ?: buildDir.name
   }
 
+  ** Index the sources of a pod
   private Void indexPodSrcDir(File dir, Str podName)
   {
     files := File[,]
       dir.list.each |f| { if (f.ext == "pod") indexPodLib(f) }
   }
 
+  ** Index a pod file
   private Void indexPodLib(File podFile)
   {
     types := TypeInfo[,]
     finally zip.close
   }
 
-  Int skipAttrs(InStream in, Str[] names)
+  private Int skipAttrs(InStream in, Str[] names)
   {
     lineNum := 0
     num := in.readU2

File src/brie/fan/index/IndexModel.fan

 using compilerDoc
 using concurrent
 
+** Group is a dir with a BuilGroup type build file
+** And might contain multiple child pods
+/*const class PodGroup
+{
+   const Str name // folder name based
+   const File srcDir
+   const File builFile // Might be build.fan or buildall.fan ...
+} */
+
 const class PodInfo
 {
   new make(Str name, File? podFile, TypeInfo[] types, File? srcDir, File[] srcFiles)
     this.types      = types
     this.srcDir     = srcDir
     this.srcFiles   = srcFiles
+    // todo set parent if it's a group child
     types.each |t| { t.podRef.val = this }
   }
 
   const TypeInfo[] types
   const File? srcDir
   const File[] srcFiles
+  //const PodGroup? parent
 }
 
 const class TypeInfo

File src/brie/fan/space/PodSpace.fan

     if (!dir.isDir) throw Err("Not a dir: $dir")
       this.name = name
     this.dir  = dir.normalize
-    this.file = file ?: dir + `build.fan`
+    this.file = file ?: FileUtil.findBuildPod(dir, dir)
     Regex[] r := Regex[,]
     try
     {

File src/brie/fan/util/FileUtil.fan

   {
     x.uri.toStr[dir.uri.toStr.size..-1].toUri
   }
+
+  ** Try to find a build file of type buildPod
+  ** first in dir/build.fan
+  ** Then in dir/src/build.fan
+  ** Then for a build pod up the directory tree but no further than upTo
+  static File? findBuildPod(File? dir, File? upTo)
+  {
+    if(dir == null)
+      return null
+    build :=  dir + `build.fan`
+    if(isBuildPod(build))
+     return build
+    build = dir + `src/build.fan`
+    if(isBuildPod(build))
+     return build
+    while(dir!=null && dir != upTo)
+    {
+      build = dir + `build.fan`
+      if(isBuildPod(build))
+       return build
+      dir = dir.parent
+    }
+    // not found
+    return null
+  }
+
+
+  private static Bool isBuildPod(File buildFile)
+  {
+    if(! buildFile.exists)
+      return false
+    try
+    {
+      in := buildFile.in
+      Str? line
+      while ((line = in.readLine) != null)
+      {
+        if (line.contains("class ")) break
+      }
+      in.close
+      return line.contains("BuildPod")
+    }
+    catch (Err e) e.trace
+    return false
+  }
 }

File src/brie/fan/util/ProcessUtil.fan

 {
   private [Str:RunArgs]? runArgs
   private File runArgsFile := Env.cur.workDir + `etc/camenbert/run.fog`
-  
+
   new make()
   {
     if(runArgsFile.exists)
     {
       try
         runArgs = runArgsFile.readObj
-      catch(Err e) {e.trace; runArgs = [:]}  
-      }  
+      catch(Err e) {e.trace; runArgs = [:]}
+      }
     else
       runArgs = [:]
   }
-  
+
   File? findBuildFile(File? f)
   {
-    if (f == null) return null
-      if (f.name == "build.fan") return f
-
-      // lookup up directory tree until we find "build.fan"
-    if (!f.isDir) f = f.parent
-      while (f.path.size > 0)
-    {
-      buildFile := f + `build.fan`
-      if (buildFile.exists) return buildFile
-        f = f.parent
-    }
-    return null
-  }  
+    return FileUtil.findBuildPod(f.parent, null)
+  }
 
   ** Find build / run commands for a given pod
   ** If first time for this pod, ask user first
       // First time running this, ask the user
       cmd := Text{text="fan"}
       arg1 := Text{text="$pod"}
-      arg2 := Text(); arg3 := Text(); arg4 := Text(); arg5 := Text(); arg6 := Text(); 
+      arg2 := Text(); arg3 := Text(); arg4 := Text(); arg5 := Text(); arg6 := Text();
       dir := Text{text = folder.osPath}
       dialog := Dialog(frame)
       {
           it.bottom = Label{text = "This will be saved in $runArgsFile.osPath"}
         }
       }
-      
+
       if (Dialog.ok != dialog.open) return null
-      
+
         d := (dir.text.trim == folder.osPath) ? null : dir.text.trim
       params := Str[,]
       [cmd.text, arg1.text, arg2.text, arg3.text, arg4.text, arg5.text, arg6.text].each
       {
         if( ! it.trim.isEmpty) {params.add(it.trim)}
         }
-      runArgs[pod] = RunArgs.makeManual(pod, params, d)  
-      
+      runArgs[pod] = RunArgs.makeManual(pod, params, d)
+
       runArgsFile.writeObj(runArgs)
     }
-     
-    return runArgs[pod]     
-  }  
-  
+
+    return runArgs[pod]
+  }
+
   Void warnNoBuildFile(Frame frame)
   {
     Dialog.openErr(frame, "No build.fan file found")
-  }  
-  
+  }
+
   Int waitForProcess(Console console, Duration timeout := 1min)
   {
     Actor(ActorPool(), |Obj? obj-> Obj? | {
         {
           Actor.sleep(100ms)
         }
-        return c.lastResult  
+        return c.lastResult
       }).send(Unsafe(console)).get(timeout)
   }
 }
   const Str pod
   const Str[] args
   const Str? runDir // null if pod dir
-  
+
   new make(|This| f) {f(this)}
-  
+
   new makeManual(Str pod, Str[] args, Str? runDir)
   {
     this.args = args
       runDir = null
     this.pod = pod
   }
-  
+
   Void execute(Console console, File defaultDir)
   {
-    if(args.isEmpty) 
+    if(args.isEmpty)
       return
     folder := runDir != null ? File.os(runDir) : defaultDir
-    if(args[0]=="fan" || args[0] == "fan.exe")    
-      console.execFan(args[1 .. -1], folder) 
-    else  
-      console.exec(args, folder) 
+    if(args[0]=="fan" || args[0] == "fan.exe")
+      console.execFan(args[1 .. -1], folder)
+    else
+      console.exec(args, folder)
   }
 }
 

File src/brie/fan/widget/Item.fan

   {
     this.dis  = p.name
     this.icon = sys.theme.iconPod
-    this.file = p.srcDir + `build.fan`
+    this.file = FileUtil.findBuildPod(p.srcDir, p.srcDir)
+
     this.pod  = p
     if (f != null) f(this)
   }

File src/brie/todo.txt

 
 allow copy from console output
 
-slots/types nav -> sort
-
 space nav pill -> right click: find in space (so don't need to open file to do it)
 
 If file is opened in file view but file exists in pod view - open it in pod view ??