def build_compiler
      node_name   = nodename(:function)
      fact_values = facts_hash(node_name)
      trusted_values = trusted_facts_hash(node_name)

      # Allow different Hiera configurations:
      HieraPuppet.instance_variable_set('@hiera', nil) if defined? HieraPuppet

      # if we specify a pre_condition, we should ensure that we compile that
      # code into a catalog that is accessible from the scope where the
      # function is called
      Puppet[:code] = pre_cond

      node_facts = Puppet::Node::Facts.new(node_name, fact_values.dup)

      node_options = {
        :parameters => fact_values,
        :facts => node_facts
      }

      stub_facts! fact_values

      node = build_node(node_name, node_options)

      if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
        Puppet.push_context(
          {
            :trusted_information => Puppet::Context::TrustedInformation.new('remote', node_name, trusted_values)
          },
          "Context for spec trusted hash"
        )
      end

      compiler = Puppet::Parser::Compiler.new(node)
      compiler.compile
      if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0
        loaders = Puppet::Pops::Loaders.new(adapter.current_environment)
        Puppet.push_context(
          {
            :loaders => loaders,
            :global_scope => compiler.context_overrides[:global_scope]
          },
        "set globals")
      end
      compiler
    end
def build_compiler
      node_name   = nodename(:function)
      fact_values = facts_hash(node_name)
      trusted_values = trusted_facts_hash(node_name)

      # Allow different Hiera configurations:
      HieraPuppet.instance_variable_set('@hiera', nil) if defined? HieraPuppet

      # if we specify a pre_condition, we should ensure that we compile that
      # code into a catalog that is accessible from the scope where the
      # function is called
      Puppet[:code] = pre_cond

      node_facts = Puppet::Node::Facts.new(node_name, fact_values.dup)

      node_options = {
        :parameters => fact_values,
        :facts => node_facts
      }

      stub_facts! fact_values

      node = build_node(node_name, node_options)

      if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
        Puppet.push_context(
          {
            :trusted_information => Puppet::Context::TrustedInformation.new('remote', node_name, trusted_values)
          },
          "Context for spec trusted hash"
        )
      end

      compiler = Puppet::Parser::Compiler.new(node)
      compiler.compile
      if Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0
        loaders = Puppet::Pops::Loaders.new(adapter.current_environment)
        Puppet.push_context(
          {
            :loaders => loaders,
            :global_scope => compiler.context_overrides[:global_scope]
          },
        "set globals")
      end
      compiler
    end
get a compiler with an attached compiled catalog