logo
class

compiler::ResolveDepends

sys::Obj
  compiler::CompilerSupport
    compiler::CompilerStep
      compiler::ResolveDepends
  1  //
  2  // Copyright (c) 2006, Brian Frank and Andy Frank
  3  // Licensed under the Academic Free License version 3.0
  4  //
  5  // History:
  6  //   26 Dec 05  Brian Frank  Creation
  7  //    5 Jun 06  Brian Frank  Ported from Java to Fan
  8  //
  9  
 10  **
 11  ** ResolveDepends resolves each dependency to a CPod and
 12  ** checks the version.  We also set Namespace.depends in
 13  ** this step.
 14  **
 15  class ResolveDepends : CompilerStep
 16  {
 17  
 18  //////////////////////////////////////////////////////////////////////////
 19  // Construction
 20  //////////////////////////////////////////////////////////////////////////
 21  
 22    **
 23    ** Constructor takes the associated Compiler
 24    **
 25    new make(Compiler compiler)
 26      : super(compiler)
 27    {
 28      loc = compiler.input.inputLoc
 29    }
 30  
 31  //////////////////////////////////////////////////////////////////////////
 32  // Methods
 33  //////////////////////////////////////////////////////////////////////////
 34  
 35    **
 36    ** Run the step
 37    **
 38    override Void run()
 39    {
 40      log.verbose("ResolveDepends")
 41  
 42      // if the input has no dependencies, then
 43      // assume a dependency on sys
 44      input := compiler.input
 45      isSys := input.podName == "sys"
 46      if (input.depends.isEmpty && !isSys)
 47        compiler.input.depends.add(Depend.fromStr("sys 0+"))
 48  
 49      // we initialize the Namespace.depends map
 50      // as we process each dependency
 51      ns.depends = Str:Depend[:]
 52  
 53      // process each dependency
 54      input.depends.each |Depend depend|
 55      {
 56        ns.depends[depend.name] = depend
 57        resolveDepend(depend)
 58      }
 59  
 60      // check that everything has a dependency on sys
 61      if (!ns.depends.containsKey("sys") && !isSys)
 62        err("All pods must have a dependency on 'sys'", loc)
 63  
 64      bombIfErr
 65    }
 66  
 67    **
 68    ** Resolve the dependency via reflection using
 69    ** the pods the compiler is running against.
 70    **
 71    private Void resolveDepend(Depend depend)
 72    {
 73      pod := ns.resolvePod(depend.name, false)
 74      if (pod == null)
 75      {
 76        err("Cannot resolve depend: pod '$depend.name' not found", loc)
 77        return
 78      }
 79  
 80      if (!depend.match(pod.version))
 81      {
 82        err("Cannot resolve depend: '$pod.name $pod.version' != '$depend'", loc)
 83        return
 84      }
 85    }
 86  
 87  //////////////////////////////////////////////////////////////////////////
 88  // Fields
 89  //////////////////////////////////////////////////////////////////////////
 90  
 91    Location loc
 92  
 93  }