@@ -35,43 +35,78 @@ import SCons.Util
35
35
36
36
Import ('command_line' , 'env' , 'whereis' , 'revaction' )
37
37
38
+ # Check prerequisites and flags for building the documentation. There are
39
+ # several combinations in play. Conceptually there are five builds:
40
+ # - manpage and user guide output in html (and manpage in roff-style "source")
41
+ # - manpage and user guide output in pdf
42
+ # - API docs with Sphinx output in html
43
+ # - API docs with Sphinx output in pdf
44
+ # - Bundle up the built bits into the tarball for upload to the website.
38
45
#
39
- # -- Check prerequisites for building the documentation ---
46
+ # These are sometimes a bit in tension. For example, we shouldn't need any
47
+ # doc bits to build the wheel for testing or uploading, except that the
48
+ # manpages (.1 format) are built and dropped into the top directory for
49
+ # use by distribution packagers - even though that's not really a suitable
50
+ # place for them. And since we're often building the wheel to make a release,
51
+ # we actually may end up wanting the docs anyway.
40
52
#
41
- skip_doc = False
42
-
43
- try :
44
- import SConsDoc
45
- import SConsExamples
46
- except ImportError as exc :
47
- print ("doc: SConsDoc failed to import, the error was:" )
48
- print (f" ImportError: { exc } " )
49
- print (" Please make sure that python-lxml is installed." )
50
- skip_doc = True
51
-
52
- fop = whereis ('fop' )
53
- xep = whereis ('xep' )
54
-
55
- if not fop and not xep :
56
- print ("doc: No PDF renderer found (fop|xep)!" )
57
- skip_doc = True
58
-
59
- skip_doc_arg = ARGUMENTS .get ('SKIP_DOC' )
60
- if skip_doc_arg is not None :
61
- skip_doc = skip_doc_arg in ['True' , '1' , 'true' ]
53
+ # We want to be able to have some choice in combinations, so that for example
54
+ # there's a command to build just the manpages for distros without having
55
+ # to have the whole fop (for pdf) and Sphinx (for API docs) chains setup
56
+ # just to do a successful build, since those won't be part of those
57
+ # packages anyway.
58
+
59
+ skip_doc_build = False
60
+ skip_pdf_build = False
61
+ skip_api_build = False
62
+
63
+ # SKIP_DOC is a csv with various options. It doesn't seem necessary
64
+ # to do a very sophisticated decode of it, but could add that later.
65
+ skip_doc_args = ARGUMENTS .get ('SKIP_DOC' , 'none' ).split (',' )
66
+ if 'none' not in skip_doc_args :
67
+ if 'all' in skip_doc_args :
68
+ skip_doc_build = skip_pdf_build = skip_api_build = True
69
+ if 'api' in skip_doc_args :
70
+ skip_api_build = True
71
+ if 'pdf' in skip_doc_args :
72
+ skip_pdf_build = True
73
+
74
+ if not skip_doc_build :
75
+ try :
76
+ import SConsDoc
77
+ import SConsExamples
78
+ except ImportError as exc :
79
+ print ("doc: SConsDoc failed to import, the error was:" )
80
+ print (f" ImportError: { exc } " )
81
+ print (" Please make sure the Python lxml package is installed." )
82
+ print (" Skipping documentation build." )
83
+ skip_doc_build = skip_pdf_build = skip_api_build = True
84
+
85
+ if not skip_pdf_build :
86
+ fop = whereis ('fop' )
87
+ xep = whereis ('xep' )
88
+
89
+ if not fop and not xep :
90
+ print ("doc: No PDF renderer found (fop|xep)!" )
91
+ print (" Skipping PDF generation." )
92
+ skip_pdf_build = True
93
+
94
+ if not skip_api_build :
95
+ ctx = env .Configure ()
96
+ sphinx = ctx .CheckProg ("sphinx-build" )
97
+ if sphinx is None :
98
+ print ("doc: Configure did not find sphinx-build" )
99
+ print (" Skipping API docs generation." )
100
+ skip_api_build = True
101
+ ctx .Finish ()
62
102
63
103
#
64
104
# --- Configure build
65
105
#
66
- env = env .Clone ()
67
-
68
106
build = os .path .join (command_line .build_dir , 'doc' )
69
-
70
107
gs = whereis ('gs' )
71
108
lynx = whereis ('lynx' )
72
-
73
109
dist_doc_tar_gz = '$DISTDIR/scons-doc-${VERSION}.tar.gz'
74
-
75
110
tar_deps = []
76
111
tar_list = []
77
112
@@ -105,7 +140,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT.
105
140
man_page_list = ['scons.1' , 'scons-time.1' , 'sconsign.1' ]
106
141
107
142
# Template for the MAN page texts when we can't properly
108
- # create them because the skip_doc flag is set (required
143
+ # create them because the skip_doc_build flag is set (required
109
144
# modules/tools aren't installed in the current system)
110
145
man_replace_tpl = r""".TH "%(uctitle)s" "1" "%(today)s" "SCons %(version)s" "SCons %(version)s"
111
146
.ie \n(.g .ds Aq \(aq
@@ -121,7 +156,7 @@ update the system and try running the build again.
121
156
#
122
157
# --- Processing ---
123
158
#
124
- if skip_doc :
159
+ if skip_doc_build :
125
160
print ("doc: ...skipping building User Guide." )
126
161
print (" ...creating fake MAN pages." )
127
162
@@ -138,6 +173,7 @@ if skip_doc:
138
173
version = env .subst ('$VERSION' )
139
174
for m in man_page_list :
140
175
man , _ = os .path .splitext (m )
176
+ # TODO: add these to Alias?
141
177
with open (os .path .join (scdir , m ), "w" ) as fman :
142
178
fman .write (
143
179
man_replace_tpl
@@ -158,6 +194,7 @@ else:
158
194
# Always create a version.xml file containing the version information
159
195
# for this run. Ignore it for dependency purposes so we don't
160
196
# rebuild all the docs every time just because the date changes.
197
+ # TODO: couldn't we use Textfile + Ignore?
161
198
date , ver , rev , copyright_years = env .Dictionary (
162
199
'DATE' , 'VERSION' , 'REVISION' , 'COPYRIGHT_YEARS'
163
200
)
@@ -439,16 +476,18 @@ else:
439
476
sctargets .append (
440
477
env .File (os .path .join (scdir , f'scons-{ doc } ' , 'index.html' ))
441
478
)
442
- if 'pdf' in targets :
479
+ if 'pdf' in targets and not skip_pdf_build :
443
480
sctargets .append (env .File (os .path .join (scdir , f'scons-{ doc } .pdf' )))
444
481
if 'epub' in targets :
445
482
sctargets .append (env .File (os .path .join (scdir , f'scons-{ doc } .epub' )))
446
483
447
484
if 'man' in targets :
448
485
for m in man_page_list :
486
+ # TODO: add targets to an alias?
449
487
sctargets .append (os .path .join (scdir , m ))
450
488
man , _1 = os .path .splitext (m )
451
- sctargets .append (os .path .join (scdir , f'scons-{ man } .pdf' ))
489
+ if not skip_pdf_build :
490
+ sctargets .append (os .path .join (scdir , f'scons-{ man } .pdf' ))
452
491
sctargets .append (os .path .join (scdir , f'scons-{ man } .html' ))
453
492
454
493
nodes .extend (
@@ -489,13 +528,13 @@ else:
489
528
target = env .File (html ),
490
529
source = env .File (os .path .join (build , doc , 'index.html' )),
491
530
)
492
- tar_deps .extend ([ html ] )
493
- tar_list .extend ([ html ] )
531
+ tar_deps .append ( html )
532
+ tar_list .append ( html )
494
533
Local (html )
495
534
env .Ignore (html , version_xml )
496
535
install_css = True
497
536
498
- if 'pdf' in targets :
537
+ if 'pdf' in targets and not skip_pdf_build :
499
538
env .InstallAs (
500
539
target = env .File (pdf ),
501
540
source = env .File (os .path .join (build , doc , f'scons-{ doc } .pdf' )),
@@ -546,17 +585,21 @@ else:
546
585
pdf = os .path .join (build , 'PDF' , f'{ man } -man.pdf' )
547
586
html = os .path .join (build , 'HTML' , f'{ man } -man.html' )
548
587
549
- env .InstallAs (
550
- target = env .File (pdf ),
551
- source = env .File (os .path .join (build , 'man' , f'scons-{ man } .pdf' )),
552
- )
588
+ if not skip_pdf_build :
589
+ env .InstallAs (
590
+ target = env .File (pdf ),
591
+ source = env .File (os .path .join (build , 'man' , f'scons-{ man } .pdf' )),
592
+ )
553
593
env .InstallAs (
554
594
target = env .File (html ),
555
595
source = env .File (os .path .join (build , 'man' , f'scons-{ man } .html' )),
556
596
)
557
597
558
- tar_deps .extend ([pdf , html ])
559
- tar_list .extend ([pdf , html ])
598
+ tar_deps .append (html )
599
+ tar_list .append (html )
600
+ if not skip_pdf_build :
601
+ tar_deps .append (pdf )
602
+ tar_list .append (pdf )
560
603
561
604
# Install CSS file, common to all single HTMLs
562
605
if install_css :
@@ -565,22 +608,26 @@ else:
565
608
target = env .File (css_file ),
566
609
source = env .File (os .path .join (build , 'user' , 'scons.css' )),
567
610
)
568
- tar_deps .extend ([ css_file ] )
569
- tar_list .extend ([ css_file ] )
611
+ tar_deps .append ( css_file )
612
+ tar_list .append ( css_file )
570
613
Local (css_file )
571
614
572
- if not skip_doc :
615
+ if skip_api_build :
616
+ Alias ("apidoc" )
617
+ else :
573
618
# Build API DOCS
574
619
# TODO: Better specify dependencies on source files
575
- pdf_file = env .Command (
576
- target = '#/build/doc/api/scons-api.pdf' ,
577
- source = env .Glob ('#/SCons/*' ),
578
- action = [Delete ("#/build/doc/api" ), "cd doc && make pdf" ],
579
- )
580
- pdf_install = os .path .join (build , 'PDF' , 'scons-api.pdf' )
581
- env .InstallAs (target = pdf_install , source = pdf_file )
582
- tar_deps .append (pdf_install )
583
- tar_list .append (pdf_install )
620
+ if not skip_pdf_build :
621
+ pdf_file = env .Command (
622
+ target = '#/build/doc/api/scons-api.pdf' ,
623
+ source = env .Glob ('#/SCons/*' ),
624
+ action = [Delete ("#/build/doc/api" ), "cd doc && make pdf" ],
625
+ )
626
+ pdf_install = os .path .join (build , 'PDF' , 'scons-api.pdf' )
627
+ env .InstallAs (target = pdf_install , source = pdf_file )
628
+ tar_deps .append (pdf_install )
629
+ tar_list .append (pdf_install )
630
+ Alias ('apidoc' , pdf_file )
584
631
585
632
htmldir = os .path .join (build , 'HTML' , 'scons-api' )
586
633
html_files = env .Command (
@@ -591,6 +638,7 @@ if not skip_doc:
591
638
)
592
639
tar_deps .append (htmldir )
593
640
tar_list .append (htmldir )
641
+ Alias ('apidoc' , html_files )
594
642
595
643
#
596
644
# Now actually create the tar file of the documentation,
0 commit comments