@@ -5634,7 +5634,7 @@ may be a string or a list of strings.</para>
5634
5634
</listitem >
5635
5635
</varlistentry >
5636
5636
5637
- <varlistentry >
5637
+ <varlistentry id = " target_scanner " >
5638
5638
<term ><parameter >target_scanner</parameter ></term >
5639
5639
<listitem >
5640
5640
<para >A Scanner object that
@@ -5652,7 +5652,7 @@ for information about creating Scanner objects.</para>
5652
5652
</listitem >
5653
5653
</varlistentry >
5654
5654
5655
- <varlistentry >
5655
+ <varlistentry id = " source_scanner " >
5656
5656
<term ><parameter >source_scanner</parameter ></term >
5657
5657
<listitem >
5658
5658
<para >A Scanner object that
@@ -7243,11 +7243,12 @@ the rest are optional:
7243
7243
<term ><parameter >function</parameter ></term >
7244
7244
<listitem >
7245
7245
<para >
7246
- A scanner function to call to process
7246
+ A function which can process ("scan")
7247
7247
a given Node (usually a file)
7248
7248
and return a list of Nodes
7249
- representing the implicit
7250
- dependencies (usually files) found in the contents.
7249
+ representing any implicit
7250
+ dependencies (usually files) which will be tracked
7251
+ for the Node.
7251
7252
The function must accept three required arguments,
7252
7253
<parameter >node</parameter >,
7253
7254
<parameter >env</parameter > and
@@ -7260,59 +7261,98 @@ the internal &SCons; node representing the file to scan,
7260
7261
the scan, and <parameter >path</parameter > is a tuple
7261
7262
of directories that can be searched for files,
7262
7263
as generated by the optional scanner
7263
- <parameter >path_function</parameter > (see below).
7264
- If <parameter >argument</parameter > was supplied when the Scanner
7265
- object was created, it is given as <parameter >arg</parameter >
7266
- when the scanner function is called; since <parameter >argument</parameter >
7267
- is optional, the default is no <parameter >arg</parameter >.
7264
+ <xref linkend =" path_function" />.
7265
+ If the <xref linkend =" scanner-argument" />
7266
+ parameter was supplied when the Scanner object was created,
7267
+ it is passed as the <parameter >arg</parameter > parameter
7268
+ to the scanner function when it is called.
7269
+ Since <parameter >argument</parameter > is optional,
7270
+ the scanner function <emphasis >may</emphasis > be
7271
+ called without an <parameter >arg</parameter > parameter.
7268
7272
</para >
7273
+
7269
7274
<para >
7270
- The function can use use
7275
+ The scanner function can make use of
7271
7276
<function >str</function >(<parameter >node</parameter >)
7272
7277
to fetch the name of the file,
7273
- <replaceable >node</replaceable >.<function >dir</function >
7278
+ <parameter >node</parameter >.<methodname >dir</methodname >
7274
7279
to fetch the directory the file is in,
7275
- <replaceable >node</replaceable >.<function >get_contents</function >()
7280
+ <parameter >node</parameter >.<methodname >get_contents</methodname >()
7276
7281
to fetch the contents of the file as bytes or
7277
- <replaceable >node</replaceable >.<function >get_text_contents</function >()
7282
+ <parameter >node</parameter >.<methodname >get_text_contents</methodname >()
7278
7283
to fetch the contents of the file as text.
7279
7284
</para >
7285
+
7280
7286
<para >
7281
- The function must take into account the <parameter >path</parameter >
7282
- directories when generating the dependency Nodes. To illustrate this,
7283
- a C language source file may contain a line like
7284
- <literal >#include "foo.h"</literal >. However, there is no guarantee
7285
- that <filename >foo.h</filename > exists in the current directory:
7286
- the contents of &cv-link-CPPPATH; is passed to the C preprocessor which
7287
- will look in those places for the header,
7288
- so the scanner function needs to look in those places as well
7289
- in order to build Nodes with correct paths.
7290
- Using &f-link-FindPathDirs; with an argument of <literal >CPPPATH</literal >
7291
- as the <parameter >path_function</parameter > in the &f-Scanner; call
7292
- means the scanner function will be called with the paths extracted
7293
- from &cv-CPPPATH; in the environment <parameter >env</parameter >
7294
- passed as the <parameter >paths</parameter > parameter.
7295
- </para >
7296
- <para >
7297
- Note that the file to scan is
7298
- <emphasis >not</emphasis >
7299
- guaranteed to exist at the time the scanner is called -
7300
- it could be a generated file which has not been generated yet -
7301
- so the scanner function must be tolerant of that.
7287
+ The scanner function should account for any directories
7288
+ listed in the <parameter >path</parameter > parameter
7289
+ when determining the existence of possible dependencies.
7290
+ External tools such as the C/C++ preprocessor are given
7291
+ lists of directories to search for source file inclusion directives
7292
+ (e.g. <literal >#include "myheader.h"</literal >).
7293
+ That list is generated from the relevant path variable
7294
+ (e.g. &cv-link-CPPPATH; for C/C++). The Scanner can be
7295
+ directed to pass the same list on to the scanner function
7296
+ via the <parameter >path</parameter > parameter so it can
7297
+ search in the same places.
7298
+ The Scanner is enabled to pass this list via the
7299
+ <xref linkend =" path_function" /> argument at Scanner creation time.
7302
7300
</para >
7301
+
7303
7302
<para >
7304
- Alternatively, you can supply a dictionary as the
7305
- <parameter >function</parameter > parameter,
7306
- to map keys (such as file suffixes) to other Scanner objects.
7303
+ Instead of a scanner function, you can supply a dictionary as the
7304
+ <parameter >function</parameter > parameter.
7305
+ The dictionary must map keys (such as file suffixes)
7306
+ to other Scanner objects.
7307
7307
A Scanner created this way serves as a dispatcher:
7308
- the Scanner's <parameter > skeys</ parameter > parameter is
7308
+ the Scanner's <xref linkend = " skeys" / > parameter is
7309
7309
automatically populated with the dictionary's keys,
7310
7310
indicating that the Scanner handles Nodes which would be
7311
7311
selected by those keys; the mapping is then used to pass
7312
7312
the file on to a different Scanner that would not have been
7313
7313
selected to handle that Node based on its
7314
7314
own <parameter >skeys</parameter >.
7315
7315
</para >
7316
+
7317
+ <para >
7318
+ Note that the file to scan is
7319
+ <emphasis >not</emphasis >
7320
+ guaranteed to exist at the time the scanner is called -
7321
+ it could be a generated file which has not been generated yet -
7322
+ so the scanner function must be tolerant of that.
7323
+ </para >
7324
+
7325
+ <para >
7326
+ While many scanner functions operate on source code files by
7327
+ looking for known patterns in the code, they can really
7328
+ do anything they need to.
7329
+ For example, the &b-link-Program; Builder is assigned a
7330
+ <xref linkend =" target_scanner" /> which examines the
7331
+ list of libraries supplied for the build (&cv-link-LIBS; )
7332
+ and decides whether to add them as dependencies,
7333
+ it does not look <emphasis >inside</emphasis > the built binary.
7334
+ </para >
7335
+
7336
+ <para >
7337
+ It is up to the scanner function to decide whether or not to
7338
+ generate an &SCons; dependency for candidates identified by scanning.
7339
+ Dependencies are a key part of &SCons; operation,
7340
+ enabling both rebuild determination and correct ordering of builds.
7341
+ It is particularly important that generated files which are
7342
+ dependencies are added into the Node graph,
7343
+ or use-before-create failures are likely.
7344
+ However, not everything may need to be tracked as a dependency.
7345
+ In some cases, implementation-provided header files change
7346
+ infrequently but are included very widely,
7347
+ so tracking them in the &SCons; node graph could become quite
7348
+ expensive for limited benefit -
7349
+ consider for example the C standard header file
7350
+ <filename >string.h</filename >.
7351
+ The scanner function is not passed any special information
7352
+ to help make this choice, so the decision making encoded
7353
+ in the scanner function must be carefully considered.
7354
+ </para >
7355
+
7316
7356
</listitem >
7317
7357
</varlistentry >
7318
7358
@@ -7325,7 +7365,7 @@ The default value is <literal>"NONE"</literal>.</para>
7325
7365
</listitem >
7326
7366
</varlistentry >
7327
7367
7328
- <varlistentry >
7368
+ <varlistentry id = " scanner-argument " >
7329
7369
<term ><parameter >argument</parameter ></term >
7330
7370
<listitem >
7331
7371
<para >If specified,
@@ -7339,7 +7379,7 @@ as the optional parameter each of those functions takes.
7339
7379
</listitem >
7340
7380
</varlistentry >
7341
7381
7342
- <varlistentry >
7382
+ <varlistentry id = " skeys " >
7343
7383
<term ><parameter >skeys</parameter ></term >
7344
7384
<listitem >
7345
7385
<para >Scanner key(s) indicating the file types
@@ -7355,27 +7395,42 @@ it will be expanded into a list by the current environment.
7355
7395
</listitem >
7356
7396
</varlistentry >
7357
7397
7358
- <varlistentry >
7398
+ <varlistentry id = " path_function " >
7359
7399
<term ><parameter >path_function</parameter ></term >
7360
7400
<listitem >
7361
- <para >A Python function that takes four or five arguments:
7401
+ <para >
7402
+ If specified, a function to generate paths to pass to
7403
+ the scanner function to search while generating dependencies.
7404
+ The function must take five arguments:
7362
7405
a &consenv; ,
7363
7406
a Node for the directory containing
7364
7407
the &SConscript; file in which
7365
7408
the first target was defined,
7366
7409
a list of target nodes,
7367
7410
a list of source nodes,
7368
7411
and the value of <parameter >argument</parameter >
7369
- if it was supplied when the Scanner was created.
7412
+ if it was supplied when the Scanner was created
7413
+ (since <parameter >argument</parameter > is optional,
7414
+ the function may be called without this argument,
7415
+ the <parameter >path_function</parameter >
7416
+ should be prepared for this).
7370
7417
Must return a tuple of directories
7371
7418
that can be searched for files to be returned
7372
7419
by this Scanner object.
7373
- (Note that the
7374
- &f-link-FindPathDirs;
7375
- function can be used to return a ready-made
7420
+ </para >
7421
+
7422
+ <para >
7423
+ The &f-link-FindPathDirs;
7424
+ function can be called to return a ready-made
7376
7425
<parameter >path_function</parameter >
7377
7426
for a given &consvar; name,
7378
- instead of having to write your own function from scratch.)
7427
+ which is often easier than writing your own function from scratch.
7428
+ For example,
7429
+ <userinput >path_function=FindPathDirs('CPPPATH')</userinput >
7430
+ means the scanner function will be called with the paths extracted
7431
+ from &cv-CPPPATH; in the &consenv; <parameter >env</parameter >,
7432
+ and passed as the <parameter >path</parameter > parameter
7433
+ to the scanner function.
7379
7434
</para >
7380
7435
</listitem >
7381
7436
</varlistentry >
0 commit comments