Class: Rscons::Builders::Preprocess

Inherits:
Rscons::Builder show all
Defined in:
lib/rscons/builders/preprocess.rb

Overview

The Preprocess builder invokes the C preprocessor

Instance Method Summary collapse

Methods inherited from Rscons::Builder

#create_build_target, #features, #name, #produces?, #setup, #standard_build, #standard_finalize, #standard_threaded_build

Instance Method Details

#default_variables(env) ⇒ Hash

Return default construction variables for the builder.

Parameters:

  • env (Environment)

    The Environment using the builder.

Returns:

  • (Hash)

    Default construction variables for the builder.


13
14
15
16
17
18
19
# File 'lib/rscons/builders/preprocess.rb', line 13

def default_variables(env)
  {
    "CPP_CMD" => %w[
      ${_PREPROCESS_CC} -E ${_PREPROCESS_DEPGEN}
      -o ${_TARGET} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${_SOURCES}],
  }
end

#finalize(options) ⇒ String?

Finalize the build operation.

Parameters:

  • options (Hash)

    Builder finalize options.

Returns:

  • (String, nil)

    Name of the target file on success or nil on failure.


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rscons/builders/preprocess.rb', line 54

def finalize(options)
  if options[:command_status]
    target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
    if File.exists?(vars['_DEPFILE'])
      deps += Environment.parse_makefile_deps(vars['_DEPFILE'], nil)
      FileUtils.rm_f(vars['_DEPFILE'])
    end
    cache.register_build(target, options[:tc].command, deps.uniq, env)
    target
  end
end

#run(options) ⇒ String, ThreadedCommand

Run the builder to produce a build target.

Parameters:

  • options (Hash)

    Builder run options.

Returns:


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rscons/builders/preprocess.rb', line 28

def run(options)
  target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
  if sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
    pp_cc = "${CXX}"
    depgen = "${CXXDEPGEN}"
  else
    pp_cc = "${CC}"
    depgen = "${CCDEPGEN}"
  end
  vars = vars.merge("_PREPROCESS_CC" => pp_cc,
                    "_PREPROCESS_DEPGEN" => depgen,
                    "_TARGET" => target,
                    "_SOURCES" => sources,
                    "_DEPFILE" => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)))
  command = env.build_command("${CPP_CMD}", vars)
  # Store vars back into options so new keys are accessible in #finalize.
  options[:vars] = vars
  standard_threaded_build("#{name} #{target}", target, command, sources, env, cache)
end