def generate!(requirements, instance_group, job, package, stemcell)
      # Our assumption here is that package dependency graph
      # has no cycles: this is being enforced on release upload.
      # Other than that it's a vanilla Depth-First Search (DFS).

      @logger.info("Checking whether package '#{package.desc}' needs to be compiled for stemcell '#{stemcell.desc}'")
      requirement_key = [package.id, "#{stemcell.os}/#{stemcell.version}"]
      requirement = requirements[requirement_key]

      if requirement # We already visited this and its dependencies
        requirement.add_instance_group(instance_group) # But we still need to register with this instance group
        return requirement
      end

      package_dependency_manager = PackageDependenciesManager.new(job.release.model)

      requirement = create_requirement(instance_group, job, package, stemcell, package_dependency_manager)

      @logger.info("Processing package '#{package.desc}' dependencies")
      dependencies = package_dependency_manager.dependencies(package)
      dependencies.each do |dependency|
        @logger.info("Package '#{package.desc}' depends on package '#{dependency.desc}'")
        dependency_requirement = generate!(requirements, instance_group, job, dependency, stemcell)
        requirement.add_dependency(dependency_requirement)
      end

      requirements[requirement_key] = requirement
      requirement
    end
def generate!(requirements, instance_group, job, package, stemcell)
      # Our assumption here is that package dependency graph
      # has no cycles: this is being enforced on release upload.
      # Other than that it's a vanilla Depth-First Search (DFS).

      @logger.info("Checking whether package '#{package.desc}' needs to be compiled for stemcell '#{stemcell.desc}'")
      requirement_key = [package.id, "#{stemcell.os}/#{stemcell.version}"]
      requirement = requirements[requirement_key]

      if requirement # We already visited this and its dependencies
        requirement.add_instance_group(instance_group) # But we still need to register with this instance group
        return requirement
      end

      package_dependency_manager = PackageDependenciesManager.new(job.release.model)

      requirement = create_requirement(instance_group, job, package, stemcell, package_dependency_manager)

      @logger.info("Processing package '#{package.desc}' dependencies")
      dependencies = package_dependency_manager.dependencies(package)
      dependencies.each do |dependency|
        @logger.info("Package '#{package.desc}' depends on package '#{dependency.desc}'")
        dependency_requirement = generate!(requirements, instance_group, job, dependency, stemcell)
        requirement.add_dependency(dependency_requirement)
      end

      requirements[requirement_key] = requirement
      requirement
    end
The rquirements hash passed in by the caller will be populated with CompiledPackageRequirement objects