From 77ef0dadf1ddd8e5cb0a359543ab4db9d01450b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Fri, 7 Jun 2019 00:00:00 +0000 Subject: [PATCH] readme: make local file links work relative to out/ Thanks to awesome help at: https://github.com/asciidoctor/asciidoctor/issues/3324 --- Gemfile | 3 ++ Gemfile.lock | 13 ++++++++ README.adoc | 11 ++++--- .../extract-link-targets | 0 asciidoctor/link-target-up.rb | 31 +++++++++++++++++++ build-doc | 21 ++++++------- 6 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock rename asciidoctor-extract-links => asciidoctor/extract-link-targets (100%) create mode 100644 asciidoctor/link-target-up.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4b692fd --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'asciidoctor', '2.0.10' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..cc1c34e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + asciidoctor (2.0.10) + +PLATFORMS + ruby + +DEPENDENCIES + asciidoctor (= 2.0.10) + +BUNDLED WITH + 2.0.1 diff --git a/README.adoc b/README.adoc index 926c7cf..4e10aeb 100644 --- a/README.adoc +++ b/README.adoc @@ -14880,20 +14880,21 @@ Source: link:build-doc[] When running link:build-doc[], we do the following checks: * `<<>>` inner links are not broken -* `+link:somefile[]+` links point to paths that exist via <>. Upstream wontfix at: https://github.com/asciidoctor/asciidoctor/issues/3210 +* `+link:somefile[]+` links point to paths that exist via <>. Upstream wontfix at: https://github.com/asciidoctor/asciidoctor/issues/3210 The scripts prints what you have to fix and exits with an error status if there are any errors. -===== asciidoctor-extract-links +[[asciidoctor-extract-link-targets]] +===== asciidoctor/extract-link-targets -Documentation for link:asciidoctor-extract-links[] +Documentation for link:asciidoctor/extract-link-targets[] Extract link targets from Asciidoctor document. Usage: .... -./asciidoctor-extract-links README.adoc +./asciidoctor/extract-link-targets README.adoc .... Output: one link target per line. @@ -14930,7 +14931,7 @@ ls "$(./getvar buildroot_build_dir)" Note that host tools like QEMU and gem5 store all archs in a single directory to factor out build objects, so cleaning one arch will clean all of them. -To only nuke only one Buildroot package, we can use the link:https://buildroot.org/downloads/manual/manual.html#pkg-build-steps[]`-dirclean`] Buildroot target: +To only nuke only one Buildroot package, we can use the link:https://buildroot.org/downloads/manual/manual.html#pkg-build-steps[`-dirclean`] Buildroot target: .... ./build-buildroot --no-all -- -dirclean diff --git a/asciidoctor-extract-links b/asciidoctor/extract-link-targets similarity index 100% rename from asciidoctor-extract-links rename to asciidoctor/extract-link-targets diff --git a/asciidoctor/link-target-up.rb b/asciidoctor/link-target-up.rb new file mode 100644 index 0000000..4c5c4c7 --- /dev/null +++ b/asciidoctor/link-target-up.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby + +=begin +README.html links break because we place that output file in out/ +This extension hacks local link targets to the right path. +=end + +require 'asciidoctor' +require 'asciidoctor/extensions' + +class Main < Asciidoctor::Extensions::InlineMacroProcessor + use_dsl + named :link + ExternalLinkRegex = /^https?:\/\// + def process parent, target, attrs + text = attrs[1] + if text.nil? || text.empty? + text = target + end + if !ExternalLinkRegex.match?(target) + target = File.join('..', target) + end + create_anchor parent, text, type: :link, target: target + end +end + +Asciidoctor::Extensions.register do + inline_macro Main +end + +#(Asciidoctor.load_file(ARGV[0])).convert diff --git a/build-doc b/build-doc index 6a08004..072e18f 100755 --- a/build-doc +++ b/build-doc @@ -19,25 +19,22 @@ https://github.com/cirosantilli/linux-kernel-module-cheat#build-the-documentatio ) def timed_main(self): - self.sh.run_cmd( + asciidoctor_dir = os.path.join(self.env['root_dir'], 'asciidoctor') + exit_status = self.sh.run_cmd( [ 'asciidoctor', LF, - '-o', self.env['readme_out'], LF, - '-v', self.env['readme'], LF, + '--failure-level', 'info', LF, + '--require', os.path.join(asciidoctor_dir, 'link-target-up.rb'), LF, + '--out-file', self.env['readme_out'], LF, + '--trace', LF, + '--verbose', LF, + self.env['readme'], LF, ], out_file=self.env['build_doc_log'], ) - error_re = re.compile('^asciidoctor: WARNING: ') - exit_status = 0 - if not self.env['dry_run']: - with open(self.env['build_doc_log']) as f: - for line in f: - if error_re.search(line): - exit_status = 1 - break external_link_re = re.compile('^https?://') for link in subprocess.check_output([ - os.path.join(self.env['root_dir'], 'asciidoctor-extract-links'), + os.path.join(asciidoctor_dir, 'extract-link-targets'), self.env['readme'] ]).decode().splitlines(): if not external_link_re.match(link):