Skip to content

Commit cc96cf3

Browse files
authored
Merge pull request SCons#4492 from mwichmann/build/doc-options
Tweak documentation build
2 parents 1910ea4 + 9d972b5 commit cc96cf3

File tree

1 file changed

+36
-50
lines changed

1 file changed

+36
-50
lines changed

doc/SConscript

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -311,28 +311,22 @@ else:
311311
copy_dbfiles(env, toolpath, [], 'gs.py')
312312
copy_dbfiles(env, toolpath, [], 'zip.py')
313313

314-
# Each document will live in its own subdirectory "build/doc/xxx".
315-
# List them here by their subfolder names. Note how the specifiers
316-
# for each subdir (=DOCTARGETS) have nothing to do with which
317-
# formats get created, but which of the outputs get installed
318-
# to the build folder and added to the different source and binary
319-
# packages in the end.
314+
# Each document will build in its own subdirectory of "build/doc/".
315+
# The *docs* dictionary entries have the document (and thus directory)
316+
# name as the key, and a tuple of lists as the value.
320317
#
321-
# In addition to the list of target formats (DOCTARGETS), we also
322-
# store some dependency information in this dict. The DOCDEPENDS
323-
# list contains all files from each local "MANIFEST", after
324-
# installing/copying them to the build directory. It basically
325-
# links the original sources to the respective build folder,
326-
# such that a simple 'python bootstrap.py' rebuilds the
327-
# documentation when a file, like 'doc/user/depends.xml'
328-
# for example, changes.
318+
# The first list is the document formats enabled ("targets"). Note this
319+
# isn't what gets built, but what gets installed into the build folder
320+
# source/target lists.
321+
#
322+
# The second list ("depends") is for dependency information. Dependencies
323+
# are extracted from each local "MANIFEST" and added to this list.
324+
# This basically links the original sources to the respective build folder.
325+
#
326+
# The third list ("nodes") stores the created PDF and HTML files,
327+
# so that we can then install them in the proper places for getting
328+
# picked up by the archiving/packaging stages.
329329
#
330-
# Finally, in DOCNODES we store the created PDF and HTML files,
331-
# such that we can then install them in the proper places for
332-
# getting picked up by the archiving/packaging stages.
333-
DOCTARGETS = 0
334-
DOCDEPENDS = 1
335-
DOCNODES = 2
336330
docs = {
337331
# 'design': (['chunked', 'pdf'], [], []),
338332
# 'python10' : (['chunked','html','pdf'], [], []),
@@ -401,7 +395,7 @@ else:
401395
else:
402396
revaction([env.File(os.path.join(build, s))], [env.File(s)], env)
403397

404-
for doc in docs:
398+
for doc, (targets, depends, nodes) in docs.items():
405399
# Read MANIFEST file and copy the listed files to the build directory,
406400
# while branding them with the SCons copyright and the current
407401
# revision number...
@@ -423,82 +417,74 @@ else:
423417
else:
424418
target_dir = os.path.join(build, doc)
425419
if ext in ['.fig', '.jpg', '.svg']:
426-
docs[doc][DOCDEPENDS].extend(
420+
depends.extend(
427421
env.Command(build_s, doc_s, Copy("$TARGET", "$SOURCE"))
428422
)
429423
else:
430424
btarget = env.File(build_s)
431-
docs[doc][DOCDEPENDS].append(btarget)
425+
depends.append(btarget)
432426
revaction([btarget], [env.File(doc_s)], env)
433427

434-
#
435-
# For each document, build the document itself in HTML,
436-
# and PDF formats.
437-
#
438-
for doc in docs:
439-
440-
#
428+
# For each document, add targets for each of the selected formats
429+
for doc, (targets, depends, nodes) in docs.items():
441430
# Call SCons in each local doc folder
442-
#
443431
cleanopt = ''
444432
if env.GetOption('clean'):
445433
cleanopt = ' -c'
446434
scdir = os.path.join(build, doc)
447435
sctargets = []
448-
if 'html' in docs[doc][DOCTARGETS]:
436+
if 'html' in targets:
449437
sctargets.append(env.File(os.path.join(scdir, 'index.html')))
450-
if 'chunked' in docs[doc][DOCTARGETS]:
438+
if 'chunked' in targets:
451439
sctargets.append(
452440
env.File(os.path.join(scdir, f'scons-{doc}', 'index.html'))
453441
)
454-
if 'pdf' in docs[doc][DOCTARGETS]:
442+
if 'pdf' in targets:
455443
sctargets.append(env.File(os.path.join(scdir, f'scons-{doc}.pdf')))
456-
if 'epub' in docs[doc][DOCTARGETS]:
444+
if 'epub' in targets:
457445
sctargets.append(env.File(os.path.join(scdir, f'scons-{doc}.epub')))
458446

459-
if 'man' in docs[doc][DOCTARGETS]:
447+
if 'man' in targets:
460448
for m in man_page_list:
461449
sctargets.append(os.path.join(scdir, m))
462450
man, _1 = os.path.splitext(m)
463-
464451
sctargets.append(os.path.join(scdir, f'scons-{man}.pdf'))
465452
sctargets.append(os.path.join(scdir, f'scons-{man}.html'))
466453

467-
docs[doc][DOCNODES].extend(
454+
nodes.extend(
468455
env.Command(
469456
target=sctargets,
470-
source=buildsuite + docs[doc][DOCDEPENDS],
457+
source=buildsuite + depends,
471458
action="cd %s && $PYTHON ${SCONS_PY.abspath}%s" % (scdir, cleanopt),
472459
)
473460
)
474461

475462
install_css = False
476-
for doc in docs:
477-
463+
for doc, (targets, depends, nodes) in docs.items():
478464
# Collect the output files for this subfolder
479465
htmldir = os.path.join(build, 'HTML', f'scons-{doc}')
480466
htmlindex = os.path.join(htmldir, 'index.html')
481467
html = os.path.join(build, 'HTML', f'scons-{doc}.html')
482468
pdf = os.path.join(build, 'PDF', f'scons-{doc}.pdf')
483469
epub = os.path.join(build, 'EPUB', f'scons-{doc}.epub')
484470
text = os.path.join(build, 'TEXT', f'scons-{doc}.txt')
485-
if 'chunked' in docs[doc][DOCTARGETS]:
471+
if 'chunked' in targets:
486472
installed_chtml = env.ChunkedInstall(
487473
env.Dir(htmldir),
488474
os.path.join(build, doc, f'scons-{doc}', 'index.html'),
489475
)
490476
installed_chtml_css = env.Install(
491477
env.Dir(htmldir), os.path.join(build, doc, 'scons.css')
492478
)
493-
env.Depends(installed_chtml, docs[doc][DOCNODES])
494-
env.Depends(installed_chtml_css, docs[doc][DOCNODES])
479+
env.Depends(installed_chtml, nodes)
480+
env.Depends(installed_chtml_css, nodes)
495481

496482
tar_deps.extend([htmlindex, installed_chtml_css])
497483
tar_list.extend([htmldir])
498484
Local(htmlindex)
499485
env.Ignore(htmlindex, version_xml)
500486

501-
if 'html' in docs[doc][DOCTARGETS]:
487+
if 'html' in targets:
502488
env.InstallAs(
503489
target=env.File(html),
504490
source=env.File(os.path.join(build, doc, 'index.html')),
@@ -509,7 +495,7 @@ else:
509495
env.Ignore(html, version_xml)
510496
install_css = True
511497

512-
if 'pdf' in docs[doc][DOCTARGETS]:
498+
if 'pdf' in targets:
513499
env.InstallAs(
514500
target=env.File(pdf),
515501
source=env.File(os.path.join(build, doc, f'scons-{doc}.pdf')),
@@ -520,7 +506,7 @@ else:
520506
tar_deps.append(pdf)
521507
tar_list.append(pdf)
522508

523-
if 'epub' in docs[doc][DOCTARGETS] and gs:
509+
if 'epub' in targets and gs:
524510
env.InstallAs(
525511
target=env.File(epub),
526512
source=env.File(os.path.join(build, doc, f'scons-{doc}.epub')),
@@ -532,9 +518,9 @@ else:
532518
tar_list.append(epub)
533519

534520
if (
535-
'text' in docs[doc][DOCTARGETS]
521+
'text' in targets
536522
and lynx
537-
and (('html' in docs[doc][DOCTARGETS]) or (doc == 'man'))
523+
and ('html' in targets or doc == 'man')
538524
):
539525
texthtml = os.path.join(build, doc, 'index.html')
540526
if doc == 'man':
@@ -553,7 +539,7 @@ else:
553539
tar_deps.append(text)
554540
tar_list.append(text)
555541

556-
if 'man' in docs[doc][DOCTARGETS]:
542+
if 'man' in targets:
557543
for m in man_page_list:
558544
man, _1 = os.path.splitext(m)
559545

0 commit comments

Comments
 (0)