From a256ab3a43e3c92fb678a1e1d86b8dd6eca81ba2 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 31 Jul 2024 09:12:38 -0600 Subject: [PATCH] Modify the Builder Methods manpage section In clarifying the detail on when a builder's target can be deduced, it seemed like the concept of a single-source builder ought to be introduced in this context. So now those builders we know are single-source have that notation in their entry in this section. Also mentions that pseudo-Builders may have a diffeent calling sequence. A chunk of text about dependencies previously appeared after the listing of builder methods, where it would be hard to spot. Moved up into the text before the listing, and integrate in a bit more smoothly. A couple of very minor typing things adjusted along the way - mainly using single_source consistently as a bool. Signed-off-by: Mats Wichmann --- CHANGES.txt | 2 + RELEASE.txt | 3 + SCons/BuilderTests.py | 4 +- SCons/Node/__init__.py | 2 +- SCons/Tool/Tool.xml | 81 ++--- SCons/Tool/__init__.py | 4 +- doc/man/scons.xml | 691 +++++++++++++++++------------------------ 7 files changed, 343 insertions(+), 444 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ed6905ba7..0eab29a67 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -198,6 +198,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER attribute and to explain what's being done in the example. - Test framework reformatted using settings from pyproject.toml. Includes code embedded in docstrings. + - Improve the Builder Methods intro section in manpage, making sure + all prose appears before the listing of methods. From Adam Scott: - Changed Ninja's TEMPLATE rule pool to use `install_pool` instead of diff --git a/RELEASE.txt b/RELEASE.txt index 19927a3c2..6b6b6644f 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -224,6 +224,9 @@ DOCUMENTATION being created from '${SOURCE.base}.out' to use a valid special attribute and to explain what's being done in the example. +- Improve the descriptive portion of the Builder Methods section in + the manpage: reword, reorganize. + DEVELOPMENT ----------- diff --git a/SCons/BuilderTests.py b/SCons/BuilderTests.py index adfa64828..6b8c9eec0 100644 --- a/SCons/BuilderTests.py +++ b/SCons/BuilderTests.py @@ -714,8 +714,8 @@ def func(target, source, env) -> None: infiles.append(test.workpath('%d.in' % i)) outfiles.append(test.workpath('%d.out' % i)) test.write(infiles[-1], "\n") - builder = SCons.Builder.Builder(action=SCons.Action.Action(func,None), - single_source = 1, suffix='.out') + builder = SCons.Builder.Builder(action=SCons.Action.Action(func, None), + single_source=True, suffix='.out') env['CNT'] = [0] tgt = builder(env, target=outfiles[0], source=infiles[0])[0] s = str(tgt) diff --git a/SCons/Node/__init__.py b/SCons/Node/__init__.py index 055c3090c..48e62746d 100644 --- a/SCons/Node/__init__.py +++ b/SCons/Node/__init__.py @@ -215,7 +215,7 @@ def get_contents_dir(node): contents.append('%s %s\n' % (n.get_csig(), n.name)) return ''.join(contents) -def get_contents_file(node): +def get_contents_file(node) -> bytes: if not node.rexists(): return b'' fname = node.rfile().get_abspath() diff --git a/SCons/Tool/Tool.xml b/SCons/Tool/Tool.xml index fcd33fe93..19511fe14 100644 --- a/SCons/Tool/Tool.xml +++ b/SCons/Tool/Tool.xml @@ -36,13 +36,13 @@ if it is not already present. Example: - + # builds foo.c env.CFile(target='foo.c', source='foo.l') # builds bar.c env.CFile(target='bar', source='bar.y') - + @@ -3343,62 +3272,13 @@ it is omitted in this listing for brevity. - -All -targets of builder methods automatically depend on their sources. -An explicit dependency can -be specified using the -&f-link-env-Depends; -method of a &consenv; (see below). - -In addition, -&scons; -automatically scans -source files for various programming languages, -so the dependencies do not need to be specified explicitly. -By default, SCons can -C source files, -C++ source files, -Fortran source files with -.F -(POSIX systems only), -.fpp, -or -.FPP -file extensions, -and assembly language files with -.S -(POSIX systems only), -.spp, -or -.SPP -files extensions -for C preprocessor dependencies. -SCons also has default support -for scanning D source files, -You can also write your own Scanners -to add support for additional source file types. -These can be added to the default -Scanner object used by the -&b-link-Object;, &b-link-StaticObject; and &b-link-SharedObject; -Builders by adding them -to the -SourceFileScanner -object. -See -for more information about -defining your own Scanner objects -and using the -SourceFileScanner -object. - &SCons; Functions and Environment Methods -&SCons; provides a variety of &consenv; methods +&SCons; provides a variety of &consenv; methods and global functions to manipulate the build configuration. Often, a &consenv; method and a global function with the same name exist for convenience. @@ -3441,19 +3321,17 @@ with two key differences: -&Consenv; methods that change the environment +&Consenv; methods that read from or change the environment act on the environment instance from which they are called, -while the corresponding global function acts on -a special “hidden” &consenv; called the Default Environment. -In some cases, the global function may take -an initial argument giving the object to operate on. +while the corresponding global function reads from +a special “hidden” &consenv; called the &DefEnv; String-valued arguments (including strings in list-valued arguments) -are subject to construction variable expansion +are subject to &consvar; expansion by the environment method form; variable expansion is not immediately performed in the global function. For example, Default('$MYTARGET') @@ -5844,7 +5722,7 @@ Adding new Tool modules is described in Builder Objects &scons; -can be extended to build different types of targets +can be extended to build additional types of targets by adding new Builder objects to a &consenv;. In general, @@ -5853,7 +5731,7 @@ when you want to build a new type of file or other external target. For output file types &scons; already knows about, you can usually modify the behavior of premade Builders such as &b-link-Program;, &b-link-Object; or &b-link-Library; -by changing the &consvars; they use +by changing the &consvars; that control their behavior (&cv-link-CC;, &cv-link-LINK;, etc.). In this manner you can, for example, change the compiler to use, which is simpler and less error-prone than writing a new builder. @@ -5865,8 +5743,8 @@ The documentation for each Builder lists which using the &f-link-Builder; factory function. -Once created, a builder is added to an environment -by entering it in the &cv-link-BUILDERS; dictionary +Once created, a builder is added to a &consenv; +by registering it in the &cv-link-BUILDERS; dictionary in that environment (some of the examples in this section illustrate this). Doing so automatically triggers &SCons; to add a method @@ -6399,16 +6277,14 @@ env.MyBuild('sub/dir/foo.out', 'sub/dir/foo.in') -&Python; only keeps one current directory -location even if there are multiple threads. +&Python; only tracks one current directory location, +even if there are multiple executing threads. This means that use of the chdir -argument -will +argument will not -work with the SCons - -option, +work with &SCons; in multi-threaded mode +(the option), because individual worker threads spawned by SCons interfere with each other when they start changing directory. @@ -6420,8 +6296,8 @@ when they start changing directory. Any additional keyword arguments supplied when a Builder object is created (that is, when the &f-link-Builder; function is called) -will be set in the executing construction -environment when the Builder object is called. +will be set in the executing &consenv; +when the Builder object is called. The canonical example here would be to set a &consvar; to the repository of a source code system. @@ -6440,6 +6316,19 @@ and emitter functions. + +When handling errors in a custom builder method, +remember that the corresponding Action is executed at a different +time than the &SConscript; file statement calling the builder. +Wrapping a builder call in a try block +is not useful, +as success of the builder call is not the same as +the build itself succeeding. +If necessary, code a Builder's Action to exit with +a useful exception message indicating the problem in the &SConscript; files. +Programmatic recovery from build errors is rarely useful. + + @@ -6583,7 +6472,7 @@ will expand &consvars; in any argument strings, including action, at the time it is called, -using the construction variables in the &consenv; through which +using the &consvars; in the &consenv; through which it was called. The global function form &f-link-Action; delays variable expansion until the Action object is actually used.