Skip to content

Commit e04e0a2

Browse files
authored
Introduce MIGRATION warnings (#686)
This adds the concept of "MIGRATION warnings" that are specifically around migrating to Asciidoctor. By default these warnings are only enforced against the "latest" version of each book where "latest" is the first version listed in the `branches` list. The idea is that we'd like "modern" versions of the documentation to be fully Asciioctor compatible but that we won't be able to do that overnight and that we won't be able to modify very old documentation to be compatible and we will forever rely on the compatibility layer in branches that are not actively being developed. This only adds a single `MIGRATION` warning, emitted when the start of a code block doesn't match the end of a code block. These are very simple to fix and we can fix them before migrating the book to Asciidoctor. In future work we'll want to emit `MIGRATION` warnings when we use the "old" style for things like the `beta[]` macro. Since the "new" style is not compatible with Asciidoc the order of operations has to be: 1. Switch the book to Asciidoctor, suppressing the warnings for `beta[]` 2. Migrate all usages of the `beta[]` macro to the new `beta::[]` style. 3. Remove the suppression. This change doesn't have a way to suppress any `MIGRATION` warnings on the latest version of the each book. As I said above, it *always* suppresses them on older versions. When you use `./build_docs --doc` we can't tell whether you are building the latest version of a book or an older version so we assume that you are building the latest version. This is the most common thing. When you build an older version you can do ``` ./build_docs --suppress_migration_warnings --doc foo.asciidoctor ``` to suppress the `MIGRATION` warnings. Begins work on #671
1 parent 5c8a445 commit e04e0a2

File tree

8 files changed

+47
-14
lines changed

8 files changed

+47
-14
lines changed

build_docs.pl

+11-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ BEGIN
5454
GetOptions(
5555
$Opts, #
5656
'all', 'push', 'target_repo=s', 'reference=s', 'rebuild', 'no_fetch', #
57-
'single', 'pdf', 'doc=s', 'out=s', 'toc', 'chunk=i',
57+
'single', 'pdf', 'doc=s', 'out=s', 'toc', 'chunk=i', 'suppress_migration_warnings',
5858
'open', 'skiplinkcheck', 'linkcheckonly', 'staging', 'procs=i', 'user=s', 'lang=s',
5959
'lenient', 'verbose', 'reload_template', 'resource=s@', 'asciidoctor', 'in_standard_docker',
6060
'conf=s',
@@ -110,13 +110,18 @@ sub build_local {
110110
die "--asciidoctor is only supported by build_docs and not by build_docs.pl";
111111
}
112112

113+
my $latest = !$Opts->{suppress_migration_warnings};
113114
if ( $Opts->{single} ) {
114115
$dir->rmtree;
115116
$dir->mkpath;
116-
build_single( $index, $dir, %$Opts );
117+
build_single( $index, $dir, %$Opts,
118+
latest => $latest
119+
);
117120
}
118121
else {
119-
build_chunked( $index, $dir, %$Opts );
122+
build_chunked( $index, $dir, %$Opts,
123+
latest => $latest
124+
);
120125
}
121126

122127
say "Done";
@@ -794,6 +799,9 @@ sub usage {
794799
--lang Defaults to 'en'
795800
--resource Path to image dir - may be repeated
796801
--asciidoctor Use asciidoctor instead of asciidoc.
802+
--suppress_migration_warnings
803+
Suppress warnings about Asciidoctor migration
804+
issues. Use this when building "old" branches.
797805
798806
WARNING: Anything in the `out` dir will be deleted!
799807

integtest/Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ check: \
1616
beta_expected_files beta_same_files \
1717
experimental_expected_files experimental_same_files \
1818
missing_include_fails_asciidoc missing_include_fails_asciidoctor \
19+
migration_warnings \
1920
readme_expected_files readme_same_files \
2021
small_all_expected_files
2122

@@ -97,6 +98,14 @@ missing_include_fails_asciidoctor: missing_include.asciidoc
9798
test $$? -eq 255
9899
$(call GREP,'ERROR: missing_include.asciidoc: line 7: include file not found: /docs_build/integtest/missing.asciidoc',/tmp/out)
99100

101+
.PHONY: migration_warnings
102+
migration_warnings: migration_warnings.asciidoc
103+
set +e; \
104+
$(BD_DUMMY) --asciidoctor --doc migration_warnings.asciidoc > /tmp/out 2>&1; \
105+
test $$? -eq 255
106+
$(call GREP,"WARNING: migration_warnings.asciidoc: line 7: MIGRATION: code block end doesn't match start",/tmp/out)
107+
$(BD_DUMMY) --asciidoctor --doc migration_warnings.asciidoc --suppress_migration_warnings
108+
100109
/tmp/readme_asciidoc: /docs_build/README.asciidoc
101110
$(BD) --doc /docs_build/README.asciidoc
102111

@@ -154,7 +163,7 @@ define GREP=
154163
false; \
155164
}
156165
grep $(1) $(2) > /dev/null || { \
157-
echo "Couldn't find $(1) in $(2):"; \
166+
echo "Couldn't" find $(1) in $(2):; \
158167
cat $(2); \
159168
false; \
160169
}

integtest/migration_warnings.asciidoc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
= Title
2+
3+
== Chapter
4+
5+
--------
6+
CODE HERE
7+
----

lib/ES/Book.pm

+6-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ sub build {
172172
}
173173
);
174174

175+
my $latest = 1;
175176
for my $branch ( @{ $self->branches } ) {
176-
$self->_build_book( $branch, $pm, $rebuild );
177+
$self->_build_book( $branch, $pm, $rebuild, $latest );
178+
$latest = 0;
177179

178180
my $branch_title = $self->branch_title($branch);
179181
if ( $branch eq $self->current ) {
@@ -219,7 +221,7 @@ sub build {
219221
#===================================
220222
sub _build_book {
221223
#===================================
222-
my ( $self, $branch, $pm, $rebuild ) = @_;
224+
my ( $self, $branch, $pm, $rebuild, $latest ) = @_;
223225

224226
my $branch_dir = $self->dir->subdir($branch);
225227
my $source = $self->source;
@@ -260,6 +262,7 @@ sub _build_book {
260262
template => $template,
261263
resource => [$checkout],
262264
asciidoctor => $self->asciidoctor,
265+
latest => $latest,
263266
);
264267
}
265268
else {
@@ -280,6 +283,7 @@ sub _build_book {
280283
template => $template,
281284
resource => [$checkout],
282285
asciidoctor => $self->asciidoctor,
286+
latest => $latest,
283287
);
284288
$self->_add_title_to_toc( $branch, $branch_dir );
285289
}

lib/ES/Toc.pm

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ sub write {
4141
lang => $self->lang,
4242
root_dir => '',
4343
edit_urls => {'' => ''},
44+
latest => 1,
4445
);
4546
$adoc_file->remove;
4647
}

lib/ES/Util.pm

+10-6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sub build_chunked {
4646
my $noindex = $opts{noindex} || '';
4747
my $page_header = custom_header($index) || $opts{page_header} || '';
4848
my $asciidoctor = $opts{asciidoctor} || 0;
49+
my $latest = $opts{latest};
4950

5051
$dest->rmtree;
5152
$dest->mkpath;
@@ -149,7 +150,7 @@ sub build_chunked {
149150
} or do { $output = $@; $died = 1; };
150151
}
151152

152-
_check_build_error( $output, $died, $lenient );
153+
_check_build_error( $output, $died, $lenient, $latest );
153154

154155
my ($chunk_dir) = grep { -d and /\.chunked$/ } $dest->children
155156
or die "Couldn't find chunk dir in <$dest>";
@@ -182,6 +183,7 @@ sub build_single {
182183
my $resources = $opts{resource} || [];
183184
my $page_header = custom_header($index) || $opts{page_header} || '';
184185
my $asciidoctor = $opts{asciidoctor} || 0;
186+
my $latest = $opts{latest};
185187

186188
my %xsltopts = (
187189
"generate.toc" => $toc,
@@ -276,7 +278,7 @@ sub build_single {
276278
} or do { $output = $@; $died = 1; };
277279
}
278280

279-
_check_build_error( $output, $died, $lenient );
281+
_check_build_error( $output, $died, $lenient, $latest );
280282

281283
my $base_name = $index->basename;
282284
$base_name =~ s/\.[^.]+$/.html/;
@@ -293,13 +295,15 @@ sub build_single {
293295
#===================================
294296
sub _check_build_error {
295297
#===================================
296-
my ( $output, $died, $lenient ) = @_;
297-
my $warned = grep {/^(a2x|asciidoc(tor)?): (WARNING|ERROR):/} split "\n", $output;
298+
my ( $output, $died, $lenient, $latest ) = @_;
298299

300+
my @lines = split "\n", $output;
301+
my @build_warnings = grep {/^(a2x|asciidoc(tor)?): (WARNING|ERROR):/} @lines;
302+
@build_warnings = grep {!/MIGRATION:/} @build_warnings unless $latest;
303+
my $warned = @build_warnings;
299304
return unless $died || $warned;
300305

301-
my @warn = grep { /(WARNING|ERROR):/ || !/^(a2x|asciidoc(tor)?): / } split "\n",
302-
$output;
306+
my @warn = grep { /(WARNING|ERROR):/ || !/^(a2x|asciidoc(tor)?): / } @lines;
303307

304308
if ( $died || $warned && !$lenient ) {
305309
die join "\n", ( '', @warn, '' );

resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def reader.process_line(line)
154154
if @code_block_start
155155
if line != @code_block_start
156156
line.replace(@code_block_start)
157-
logger.warn message_with_context "code block end doesn't match start", :source_location => cursor
157+
logger.warn message_with_context "MIGRATION: code block end doesn't match start", :source_location => cursor
158158
end
159159
@code_block_start = nil
160160
else

resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
<screen>foo</screen>
326326
</chapter>
327327
DOCBOOK
328-
actual = convert input, {}, match(/<stdin>: line 4: code block end doesn't match start/)
328+
actual = convert input, {}, match(/WARN: <stdin>: line 4: MIGRATION: code block end doesn't match start/)
329329
expect(actual).to eq(expected.strip)
330330
end
331331

0 commit comments

Comments
 (0)