Build a Tool in Scons, Then Using IT

xiaoxiao2021-03-06  75

From

http://www.scons.org/cgi-bin/wiki/usingcodegenerators

==

One fairly common requirement in builds is to create some tool from source code, and then use that tool as part of the build to generate other files. This example shows how to do that, with thanks to Gary Oberbrunner. The tool to be generated is Named MK_VDS, AND is Built from the source file mk_vds.c. The .txt input files are buy by mk_vds to generate .vds files.

# Sconstruct File

Env = environment ()

# Create the mk_vds generator Tool

MK_VDS_TOOL = Env.program (target = 'mk_vds', Source = 'mk_vds.c')

# This emitter Will Be Used Later by a builder, And Has An Explit Dependency on the mk_vds Tool

DEF MK_VDS_EMITTER (Target, Source, ENV):

Env.depends (target, mk_vds_tool)

Return (Target, SOURCE)

# Create a Builder (That Uses the Emitter) To build .vds files from .txt files

# The use of abspath is so what mk_vds's directory doesn't Have to be added to the shell path.

BLD = builder (action = mk_vds [0] .Abspath '<$ source> $ target',

Emitter = mk_vds_emitter,

SUFFIX = '.vds', src_suffix = '.txt')

# Add the new builder to the list of builders

ENV ['Builders'] ['MK_VDS'] = BLD

#Gerate foo.vds from foo.txt using mk_vds

Env.mk_vds ('foo.txt')

If you look at the resulting dependency tree you can see it it it it?

% Scons --debug = tree foo.vds

-FOO.VDS

-FOO.TXT

-MK_VDS

-MK_VDS.O

-MK_VDS.C

转载请注明原文地址:https://www.9cbs.com/read-97868.html

New Post(0)