@@ -41,14 +41,13 @@ HIGHLIGHT_SERVER_URL="http://127.0.0.1:8080" # this needs to be coordinated with
41
41
function main {
42
42
processCommandLineArgs " $@ "
43
43
44
+ checkWattsi
45
+ ensureHighlighterInstalled
46
+
44
47
# $SKIP_BUILD_UPDATE_CHECK is set inside the Dockerfile so that we don't check for updates both inside and outside
45
48
# the Docker container.
46
49
if [[ $DO_UPDATE == " true" && $SKIP_BUILD_UPDATE_CHECK != " true" ]]; then
47
50
checkHTMLBuildIsUpToDate
48
- # If we're using Docker then this will be installed inside the container.
49
- if [[ $USE_DOCKER != " true" ]]; then
50
- pip3 install bs-highlighter
51
- fi
52
51
fi
53
52
54
53
findHTMLSource
@@ -178,6 +177,24 @@ function checkHTMLBuildIsUpToDate {
178
177
fi
179
178
}
180
179
180
+ # Tries to install the bs-highlighter Python package if necessary
181
+ # - Arguments: none
182
+ # - Output:
183
+ # - Either bs-highlighter-server will be in the $PATH, or a warning will be echoed
184
+ function ensureHighlighterInstalled {
185
+ # If we're using Docker then this will be installed inside the container.
186
+ # If we're not using local Wattsi then we won't use the local highlighter.
187
+ if [[ $USE_DOCKER != " true" && $LOCAL_WATTSI == " true" ]]; then
188
+ if hash pip3 2> /dev/null; then
189
+ if ! hash bs-highlighter-server 2> /dev/null; then
190
+ pip3 install bs-highlighter
191
+ fi
192
+ else
193
+ LOCAL_WATTSI=" false"
194
+ fi
195
+ fi
196
+ }
197
+
181
198
# Finds the location of the HTML Standard, and stores it in the HTML_SOURCE variable.
182
199
# It either guesses based on directory structure, or interactively prompts the user.
183
200
# - Arguments: none
@@ -537,6 +554,25 @@ Disallow: /review-drafts/" > "$HTML_OUTPUT/robots.txt"
537
554
fi
538
555
}
539
556
557
+ # Checks if Wattsi is available and up to date
558
+ # - Arguments: none
559
+ # - Output:
560
+ # - Sets $LOCAL_WATTSI to true or false
561
+ # - Echoes a warning if Wattsi is out of date according to $WATTSI_LATEST
562
+ function checkWattsi {
563
+ if hash wattsi 2> /dev/null; then
564
+ if [[ " $( wattsi --version | cut -d' ' -f2) " -lt " $WATTSI_LATEST " ]]; then
565
+ echo
566
+ echo " Warning: Your wattsi version is out of date. You should to rebuild an"
567
+ echo " up-to-date wattsi binary from the wattsi sources."
568
+ echo
569
+ fi
570
+ LOCAL_WATTSI=true
571
+ else
572
+ LOCAL_WATTSI=false
573
+ fi
574
+ }
575
+
540
576
# Runs Wattsi on the given file, either locally or using the web service
541
577
# - Arguments:
542
578
# - $1: the file to run Wattsi on
@@ -547,7 +583,6 @@ Disallow: /review-drafts/" > "$HTML_OUTPUT/robots.txt"
547
583
# - $HTML_TEMP/wattsi-output directory will contain the output from Wattsi on success
548
584
# - $HTML_TEMP/wattsi-output.txt will contain the output from Wattsi, on both success and failure
549
585
function runWattsi {
550
-
551
586
rm -rf " $2 "
552
587
mkdir " $2 "
553
588
@@ -559,19 +594,12 @@ function runWattsi {
559
594
" $HTML_CACHE /caniuse.json" \
560
595
" $HTML_CACHE /mdn-spec-links-html.json" \
561
596
" $HIGHLIGHT_SERVER_URL " )
562
- if hash wattsi 2> /dev/null; then
563
- if [[ " $( wattsi --version | cut -d' ' -f2) " -lt " $WATTSI_LATEST " ]]; then
564
- echo
565
- echo " Warning: Your wattsi version is out of date. You should to rebuild an"
566
- echo " up-to-date wattsi binary from the wattsi sources."
567
- echo
568
- fi
597
+ if [[ " $LOCAL_WATTSI " == " true" ]]; then
569
598
WATTSI_RESULT=" 0"
570
599
wattsi " ${WATTSI_ARGS[@]} " || WATTSI_RESULT=$?
571
600
else
572
- LOCAL_WATTSI=false
573
601
$QUIET || echo
574
- $QUIET || echo " Local wattsi is not present; trying the build server..."
602
+ $QUIET || echo " Local wattsi or pip3 are not present; trying the build server..."
575
603
576
604
CURL_ARGS=( https://build.whatwg.org/wattsi \
577
605
--form " source=@$1 " \
@@ -624,19 +652,20 @@ function generateBacklinks {
624
652
perl .post-process-partial-backlink-generator.pl " $HTML_TEMP /wattsi-output/index-$1 " > " $2 /index.html" ;
625
653
}
626
654
627
- # Starts the syntax-highlighting Python server
655
+ # Starts the syntax-highlighting Python server, when appropriate
628
656
# Arguments: none
629
- # Output:
657
+ # Output: if the server is necessary, then
630
658
# - A server will be running in the background, at $HIGHLIGHT_SERVER_URL
631
659
# - $HIGHLIGHT_SERVER_PID will be set for later use by stopHighlightServer
632
660
function startHighlightServer {
633
- HIGHLIGHT_SERVER_ARGS=()
634
- $QUIET && HIGHLIGHT_SERVER_ARGS+=( --quiet )
635
- # shellcheck disable=SC2068
636
- bs-highlighter-server ${HIGHLIGHT_SERVER_ARGS[@]+" ${HIGHLIGHT_SERVER_ARGS[@]} " } &
637
- HIGHLIGHT_SERVER_PID=$!
661
+ if [[ " $LOCAL_WATTSI " == " true " ]] ; then
662
+ HIGHLIGHT_SERVER_ARGS=( )
663
+ $QUIET && HIGHLIGHT_SERVER_ARGS+=( --quiet )
664
+ bs-highlighter-server ${HIGHLIGHT_SERVER_ARGS[@]+" ${HIGHLIGHT_SERVER_ARGS[@]} " } &
665
+ HIGHLIGHT_SERVER_PID=$!
638
666
639
- trap stopHighlightServer EXIT
667
+ trap stopHighlightServer EXIT
668
+ fi
640
669
}
641
670
642
671
# Stops the syntax-highlighting Python server
0 commit comments