Git commit d701767a34fc38b24fb5d4379338fc1420f2ef54 by Harald Sitter. Committed on 10/08/2017 at 10:03. Pushed by sitter into branch 'master'.
port documentation handling to kdoctools now that plasma dropped the if conditionals in doc/CMakeLists.txt requirement we can rely on kdoctools' somewhat less sophisticated documentation handling. saves us excessive amounts of code with insane complexity and aligns the source tree more with what frameworks have. this also gives us "free" manpage support, add some minor branching to correctly detect and copy manpage docbooks into the final tree. also new test case to assert the results are well-formed BUG: 381103 BUG: 382550 M +7 -7 .gitignore M +14 -86 lib/releaseme/cmakeeditor.rb M +82 -81 lib/releaseme/documentation.rb M +4 -102 test/cmakeeditor_test.rb A +1 -0 test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/man-amarok.1.docbook A +1 -0 test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/unicorn/man-unicorn.1.docbook A +4 -0 test/data/multi-doc/doc/doc-valid1/CMakeLists.txt A +4 -0 test/data/single-pot/doc/CMakeLists.txt A +0 -0 test/data/source-with-manpage/CMakeLists.txt A +8 -0 test/data/source-with-manpage/Messages.sh A +4 -0 test/data/source-with-manpage/doc/CMakeLists.txt A +1 -0 test/data/source-with-manpage/doc/man-amarok.1.docbook A +4 -0 test/data/source-with-manpage/doc/subdir/CMakeLists.txt A +1 -0 test/data/source-with-manpage/doc/subdir/man-unicorn.1.docbook M +100 -50 test/documentation_test.rb https://commits.kde.org/releaseme/d701767a34fc38b24fb5d4379338fc1420f2ef54 diff --git a/.gitignore b/.gitignore index d7a99ff..7431a07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -doc -coverage -html -old -output -.yardoc -plasma/bugzilla-cookies.inc +/doc/ +/coverage/ +/html/ +/old/ +/output +/.yardoc +/plasma/bugzilla-cookies.inc diff --git a/lib/releaseme/cmakeeditor.rb b/lib/releaseme/cmakeeditor.rb index 7d8954d..913f96c 100644 --- a/lib/releaseme/cmakeeditor.rb +++ b/lib/releaseme/cmakeeditor.rb @@ -38,92 +38,6 @@ module ReleaseMe "add_subdirectory(#{rel})\n" end - # FIXME: INSTALL_DEST needs to take into account subdirs of language - # e.g. kcontrol/foo/ must install to language/kcontrol/foo/ - def create_handbook(language, subdir) - <<-EOF -kdoctools_create_handbook(index.docbook - INSTALL_DESTINATION \${HTML_INSTALL_DIR}/#{language} - SUBDIR #{subdir})\n - EOF - end - - # FIXME: this is getting an awful many arguments - def write_handbook(dir, language, subdir) - log_debug " -- Writing #{dir}/CMakeLists.txt for #{language} :: #{subdir}" - File.write("#{dir}/CMakeLists.txt", create_handbook(language, subdir)) - end - - # Creates the CMakeLists.txt for doc/$LANG/* - # FIXME: don't overwrite en' CMakeLists.txt for a given subdir - def create_language_specific_doc_lists!(dir, language, software_name) - if File.exist?("#{dir}/index.docbook") - # When there is an index.docbook we mustn't copy the en version as - # we have to write our own CMakeLists in order to have things installed - # in the correct language directory! Also see kdoctools_create_handbook - # arguments. - write_handbook(dir, language, software_name) - elsif !Dir.glob("#{dir}/*").select { |f| File.directory?(f) }.empty? - # -- Recyle en' CMakeLists -- - enusdir = "#{dir}/../en/" - enuscmake = "#{enusdir}/CMakeLists.txt" - unless File.exist?(enuscmake) - raise 'there is no cmakelists in enUS and also no index.docbook' - end - # FIXME: naughty - FileUtils.cp(enuscmake, dir) unless File.basename(dir) == 'en' - Dir.glob("#{dir}/**/**").each do |current_dir| - next unless File.directory?(current_dir) - next if File.basename(dir) == 'en' - dir_pathname = Pathname.new(dir) - current_dir_pathname = Pathname.new(current_dir) - relative_path = current_dir_pathname.relative_path_from(dir_pathname) - # FIXME: this will fail if the cmakelists doesn't exist, which is - # possible but also a bit odd, not sure if we should just - # ignore that... - # FIXME: has no test backing I think - cmakefile = "#{enusdir}/#{relative_path}/CMakeLists.txt" - FileUtils.cp(cmakefile, current_dir) if File.exist?(cmakefile) - end - Dir.glob("#{dir}/**/index.docbook").each do |docbook| - # FIXME: subdir logic needs testing through documentation class - # FIXME: this is not tested via our tests - dirname = File.dirname(docbook) - - dir_pathname = Pathname.new(dir) - current_dir_pathname = Pathname.new(dirname) - relative_path = current_dir_pathname.relative_path_from(dir_pathname) - - subdir = File.join(relative_path) - subdir.chomp!(File::SEPARATOR) - # FIXME: really naughty workaround to avoid overwriting existing lists - unless language == 'en' && File.exist?("#{dirname}/CMakeLists.txt") - # FIXME: no test backing - write_handbook(dirname, language, subdir) - end - end - else - raise 'There is no index.docbook but also no directories' - end - - # en may already have a super cmakelists, do not twiddle with it! - log_debug "Writing main cmakelists #{dir}/../CMakeLists.txt" - # FIXME: not thread safe - File.open("#{dir}/../CMakeLists.txt", 'a') do |f| - f.write(add_subdirectory(dir, relative_to: "#{dir}/..")) - end - end - - # Creates the CMakeLists.txt for doc/* - def create_doc_meta_lists!(dir) - file = File.new("#{dir}/CMakeLists.txt", 'w') - Dir.foreach(dir) do |lang| - next if %w[. .. CMakeLists.txt].include?(lang) - file << "add_subdirectory(#{lang})\n" - end - file.close - end - # Helper, append methods can get one arg, which is expected to be a # path we can split into its pieces. # TODO: possibly deprecate calling the appends with two args altogether. @@ -166,6 +80,20 @@ kdoctools_create_handbook(index.docbook end end + # Appends the install instructions for documentation in po/* + def append_doc_install_instructions!(dir, subdir = nil) + dir, subdir = dir_subdir_split(dir) unless subdir + macro = "\nfind_package(KF5DocTools CONFIG REQUIRED)\nkdoctools_install(#{subdir})\n" + edit_file("#{dir}/CMakeLists.txt") do |data| + break if data =~ /.*#\s*SKIP_#{subdir.upcase}_INSTALL/ + if data.include?("##{subdir.upcase}_SUBDIR") + data.sub!("##{subdir.upcase}_SUBDIR", macro) + elsif (data =~ /^\s*(kdoctools_install)\s*\(\s*#{subdir}\s*\).*$/).nil? + data << macro + end + end + end + # Appends the inclusion of subdir/CMakeLists.txt def append_optional_add_subdirectory!(dir, subdir = nil) dir, subdir = dir_subdir_split(dir) unless subdir diff --git a/lib/releaseme/documentation.rb b/lib/releaseme/documentation.rb index 805b4d7..db1e4e2 100644 --- a/lib/releaseme/documentation.rb +++ b/lib/releaseme/documentation.rb @@ -1,5 +1,5 @@ #-- -# Copyright (C) 2007-2015 Harald Sitter <[email protected]> +# Copyright (C) 2007-2017 Harald Sitter <[email protected]> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -36,28 +36,30 @@ module ReleaseMe end def get(srcdir) - # TODO: instead of moving the trees around, checkout into /po. This should - # simplify the actual logic a bit. There is however the fairly silly use - # case of CMakeLists re-use to be considered. i.e. if a source has - # multiple docbooks and some of them are dependent on build-time - # configuration it would be weird if those docbooks got installed all the - # time for $lang while the native english docs are flag sensitive. - @docdir = "#{File.expand_path(srcdir)}/doc" - FileUtils.mkpath(@docdir) - - docs = [] - languages_without_documentation = [] + @srcdir = File.expand_path(srcdir) + @podir = if Dir.exist?("#{@srcdir}/po") + "#{@srcdir}/po" + elsif Dir.exist?("#{@srcdir}/poqm") + "#{@srcdir}/poqm" + else + "#{@srcdir}/po" # Default to po + end + + langs_with_documentation = [] + langs_without_documentation = [] log_info "Downloading documentations for #{srcdir}" - unless get_en('en') - log_warn 'There is no en documentation. Skipping documentation :(' - FileUtils.rmdir(@docdir) + # return false if doc_dirs.empty? + unless translatables? + log_warn <<-EOF +Could not find any documentation by checking for *.docbook files in the source. +Skipping documentation :( + EOF return end - docs << 'en' - queue = languages_queue(%w(en)) + queue = languages_queue(%w[en]) threads = [] THREAD_COUNT.times do threads << Thread.new do @@ -65,97 +67,96 @@ module ReleaseMe until queue.empty? language = queue.pop(true) if get_language(language) - docs << language + langs_with_documentation << language else - languages_without_documentation << language + langs_without_documentation << language end end end end ThreadsWait.all_waits(threads) - if !docs.empty? - CMakeEditor.create_doc_meta_lists!(@docdir) - CMakeEditor.append_optional_add_subdirectory!(@docdir) + if !langs_with_documentation.empty? + CMakeEditor.append_doc_install_instructions!(@podir) else log_warn 'There are no translations at all!' - FileUtils.rm_rf(@docdir) end - return if languages_without_documentation.empty? - log_info "No translations for: #{languages_without_documentation.join(', ')}" + return if langs_without_documentation.empty? + log_info "No translations for: #{langs_without_documentation.join(', ')}" end private - def doc_dirs - # FIXME: this could be put in the class instance assuming we never want to - # have different projects in the same ruby instance - return @doc_dirs if defined? @doc_dirs - @doc_dirs = Dir.glob("#{@docdir}/en/*").collect do |f| - next nil unless File.directory?(f) - File.basename(f) + def docbook_dirs + Dir.glob("#{@srcdir}/**/*.docbook").collect do |file| + next nil if manpage?(file) + name = File.basename(File.dirname(file)) + %w[doc docs docbook documentation].include?(name) ? nil : name end - @doc_dirs = @doc_dirs.compact end - def get_en(language) - # FIXME: code dup from regular get - destdir = "#{@docdir}/#{language}" - - # On git a layout doc/{file,file,file} may appear, in this case we move - # stuff to en. - # A more complicated case would be doc/{dir,dir}/{file,file} which can - # happen for multisource repos such as plasma-workspace. - unless Dir.glob("#{@docdir}/**/index.docbook").empty? || - File.exist?(destdir) - list = Dir.glob("#{@docdir}/*").uniq - FileUtils.mkpath(destdir) - FileUtils.mv(list, destdir) - end - if File.exist?(destdir) - CMakeEditor.create_language_specific_doc_lists!(destdir, language, @project_name) - return true + def kdoctools_dirs + Dir.glob("#{@srcdir}/**/CMakeLists.txt").collect do |file| + next unless file.include?('doc/') + regex = Regexp.new('kdoctools_create_handbook\s*\(.+\s+SUBDIR\s+(?<subdir>[^\)\s]+)\)', + Regexp::IGNORECASE | Regexp::MULTILINE) + matchdata = regex.match(File.read(file)) + next nil unless matchdata + matchdata.named_captures.fetch('subdir', nil) + end.compact + end + + def manpages + Dir.glob("#{@srcdir}/**/CMakeLists.txt").collect do |file| + next unless file.include?('doc/') + regex = Regexp.new('kdoctools_create_manpage\s*\(\s*(?<man>man-[^\)\s]+\.docbook)', + Regexp::IGNORECASE | Regexp::MULTILINE) + matchdata = regex.match(File.read(file)) + next nil unless matchdata + matchdata.named_captures.fetch('man', nil) + end.compact + end + + def doc_dirs + (docbook_dirs + kdoctools_dirs).uniq.compact + end + + def translatables? + !doc_dirs.empty? || !manpages.empty? + end + + def manpage?(path) + File.basename(path) =~ /man-.+\.docbook/ + end + + def find_all_docs(dir) + doc_dirs.select do |doc_dir| + Dir.exist?("#{dir}/#{doc_dir}") end - false end - def get_language(language) - destdir = "#{@docdir}/#{language}" + def find_all_manpages(dir) + manpages.collect do |manpage| + Dir.glob("#{dir}/**/#{manpage}").collect do |x| + Pathname.new(x).relative_path_from(Pathname.new(dir)).to_s + end + end.flatten + end + def get_language(language) Dir.mktmpdir(self.class.to_s) do |tmpdir| - unless doc_dirs.empty? - # FIXME: recyle for single-get? - # FIXME: check cmake file for add_subdir that are not optional and warn if there are any - @vcs.get(tmpdir, "#{language}/docs/#{@i18n_path}") - - not_translated_doc_dirs = doc_dirs - # FIXME: for some reason with plasma-desktop /* didn't work - # yet the tests passed, so the tests seem insufficient - doc_selection = Dir.glob("#{tmpdir}/**").select do |d| - basename = File.basename(d) - if doc_dirs.include?(basename) - not_translated_doc_dirs.delete(basename) - next true - end - next false - end - break if doc_selection.empty? + @vcs.get(tmpdir, "#{language}/docs/#{@i18n_path}") - FileUtils.mkpath(destdir) - doc_selection.each { |d| FileUtils.mv(d, destdir) } - CMakeEditor.create_language_specific_doc_lists!(destdir, language, @project_name) - return true + selection = (find_all_docs(tmpdir) + find_all_manpages(tmpdir)).uniq + selection.each do |d| + dest = "#{@podir}/#{language}/docs/#{File.dirname(d)}" + FileUtils.mkpath(dest, verbose: true) + FileUtils.cp_r("#{tmpdir}/#{d}", dest, verbose: true) end - @vcs.get(tmpdir, vcs_l10n_path(language)) - return false unless FileTest.exist?("#{tmpdir}/index.docbook") - - FileUtils.mkpath(destdir) - FileUtils.cp_r(Dir.glob("#{tmpdir}/*"), destdir) - CMakeEditor.create_language_specific_doc_lists!(destdir, language, @project_name) + return !selection.empty? end - true end end end diff --git a/test/cmakeeditor_test.rb b/test/cmakeeditor_test.rb index 9e71f38..b66e6f9 100644 --- a/test/cmakeeditor_test.rb +++ b/test/cmakeeditor_test.rb @@ -1,5 +1,5 @@ #-- -# Copyright (C) 2014 Harald Sitter <[email protected]> +# Copyright (C) 2014-2017 Harald Sitter <[email protected]> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -28,14 +28,6 @@ class TestCMakeEditor < Testme assert(data.end_with?("\n")) end - def assert_valid_kdoctools(file) - parts = file.split('/') - language = parts.first - dir = parts[-2] - expected_line = ReleaseMe::CMakeEditor.create_handbook(language, dir) - assert_equal(expected_line, File.read(file)) - end - def assert_equal_valid_meta_cmakelists(dir, file = 'CMakeLists.txt') Dir.chdir(dir) do dirs = Dir.glob('*').select { |f| File.directory?(f) } @@ -56,96 +48,6 @@ class TestCMakeEditor < Testme end end - def test_create_handbook_complex - origin_dir = "#{@datadir}/cmakeeditor/#{__method__}" - FileUtils.cp_r(Dir.glob("#{origin_dir}/*"), '.') - %w(en de fr).each do |lang| - ReleaseMe::CMakeEditor.create_language_specific_doc_lists!("#{Dir.pwd}/#{lang}", lang, 'yolo') - end - # FIXME: put in testme as assert_files_exist - expected_files = %w( - CMakeLists.txt - fr - fr/CMakeLists.txt - fr/doc2 - fr/doc2/CMakeLists.txt - fr/doc2/index.docbook - en - en/CMakeLists.txt - en/doc1 - en/doc1/CMakeLists.txt - en/doc1/index.docbook - en/doc2 - en/doc2/CMakeLists.txt - en/doc2/index.docbook - en/doc3 - en/doc3/CMakeLists.txt - en/doc3/doc3.1 - en/doc3/doc3.1/CMakeLists.txt - en/doc3/doc3.1/index.docbook - de - de/CMakeLists.txt - de/doc1 - de/doc1/CMakeLists.txt - de/doc1/index.docbook - de/doc3 - de/doc3/CMakeLists.txt - de/doc3/doc3.1 - de/doc3/doc3.1/CMakeLists.txt - de/doc3/doc3.1/index.docbook - ) - present_files = Dir.glob('**/**') - missing_files = [] - expected_files.each do |f| - missing_files << f unless present_files.include?(f) - present_files.delete(f) - end - assert(missing_files.empty?, "missing file(S): #{missing_files}") - assert(present_files.empty?, "unexpected file(s): #{present_files}") - assert_equal_valid_meta_cmakelists('.') - assert_equal(File.read('en/CMakeLists.txt'), - File.read('fr/CMakeLists.txt')) - assert_valid_kdoctools('fr/doc2/CMakeLists.txt') - assert_valid_kdoctools('en/doc1/CMakeLists.txt') - assert_valid_kdoctools('en/doc2/CMakeLists.txt') - assert_equal(File.read('en/CMakeLists.txt'), - File.read('de/CMakeLists.txt')) - assert_valid_kdoctools('de/doc1/CMakeLists.txt') - end - - def test_create_language_specific_handbook_lists - # Internally create attempts to find the most meaningful creation which - # involves checking whether the doc dir even is valid and possibly - # refusing to write anything when not, so make the doc dir the least bit - # valid by creating index.docbook. - FileUtils.touch('index.docbook') - ReleaseMe::CMakeEditor.create_language_specific_doc_lists!(Dir.pwd, 'xx', 'yolo') - assert_path_exist('CMakeLists.txt') - data = File.read('CMakeLists.txt') - assert_equal(ReleaseMe::CMakeEditor.create_handbook('xx', 'yolo'), data) - assert_has_terminal_newline(data) - end - - def test_create_handbook_with_subpath - output = ReleaseMe::CMakeEditor.create_handbook('es', 'kittens/kittentroll') - assert(output.include?('${HTML_INSTALL_DIR}/es')) - assert(output.include?('SUBDIR kittens/kittentroll')) - end - - def test_create_doc_meta_lists - Dir.mkdir("#{Dir.pwd}/aa") - Dir.mkdir("#{Dir.pwd}/bb") - Dir.mkdir("#{Dir.pwd}/cc") - ReleaseMe::CMakeEditor.create_doc_meta_lists!(Dir.pwd) - assert_path_exist('CMakeLists.txt') - data = File.read('CMakeLists.txt') - assert(!data.downcase.include?('find_package(gettext')) # PO-only! - assert(data.downcase.include?('add_subdirectory(aa)')) - assert(data.downcase.include?('add_subdirectory(bb)')) - assert(data.downcase.include?('add_subdirectory(cc)')) - assert_has_terminal_newline(data) - end - def create_cmakelists! f = File.new('CMakeLists.txt', File::CREAT | File::RDWR | File::TRUNC) f << "#FOO_SUBDIR\n" @@ -164,14 +66,14 @@ class TestCMakeEditor < Testme # Make sure the editor doesn't append if it is already there... ReleaseMe::CMakeEditor.append_po_install_instructions!(Dir.pwd, 'po') data = File.read('CMakeLists.txt') - assert(data.scan('ki18n_install(po)').count == 1) + assert_includes(data, 'ki18n_install(po)') end def test_append_po_install_instructions_with_ecm_to_qm File.write('CMakeLists.txt', ' ecm_install_po_files_as_qm ( po ) ') ReleaseMe::CMakeEditor.append_po_install_instructions!(Dir.pwd, 'po') data = File.read('CMakeLists.txt') - assert(data.scan('ki18n_install(po)').count == 0) + refute_includes(data, 'ki18n_install(po)') end def test_append_po_install_instructions_substitute @@ -195,7 +97,7 @@ class TestCMakeEditor < Testme # Make sure the editor doesn't append if it is already there... ReleaseMe::CMakeEditor.append_optional_add_subdirectory!(Dir.pwd, 'po') data = File.read('CMakeLists.txt') - assert(data.scan('add_subdirectory(append)').count == 1) + assert_includes(data, 'add_subdirectory(append)') end def test_append_optional_add_subdirectory_substitute diff --git a/test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/man-amarok.1.docbook b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/man-amarok.1.docbook new file mode 100644 index 0000000..112ed86 --- /dev/null +++ b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/man-amarok.1.docbook @@ -0,0 +1 @@ +manpage diff --git a/test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/unicorn/man-unicorn.1.docbook b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/unicorn/man-unicorn.1.docbook new file mode 100644 index 0000000..112ed86 --- /dev/null +++ b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/extragear-multimedia/amarok/unicorn/man-unicorn.1.docbook @@ -0,0 +1 @@ +manpage diff --git a/test/data/multi-doc/doc/doc-valid1/CMakeLists.txt b/test/data/multi-doc/doc/doc-valid1/CMakeLists.txt new file mode 100644 index 0000000..4e10cb2 --- /dev/null +++ b/test/data/multi-doc/doc/doc-valid1/CMakeLists.txt @@ -0,0 +1,4 @@ +########### install files ############### +# +# +kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en SUBDIR amarok) diff --git a/test/data/single-pot/doc/CMakeLists.txt b/test/data/single-pot/doc/CMakeLists.txt new file mode 100644 index 0000000..4e10cb2 --- /dev/null +++ b/test/data/single-pot/doc/CMakeLists.txt @@ -0,0 +1,4 @@ +########### install files ############### +# +# +kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en SUBDIR amarok) diff --git a/test/data/source-with-manpage/CMakeLists.txt b/test/data/source-with-manpage/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/data/source-with-manpage/Messages.sh b/test/data/source-with-manpage/Messages.sh new file mode 100755 index 0000000..d271217 --- /dev/null +++ b/test/data/source-with-manpage/Messages.sh @@ -0,0 +1,8 @@ +#! /bin/sh +$EXTRACTRC `find . -name "*.rc" -o -name "*.ui" -o -name "*.kcfg"` >> rc.cpp +$EXTRACTATTR --attr=layout,name data/DefaultPlaylistLayouts.xml >> rc.cpp +LIST=`find . -name \*.h -o -name \*.cpp` +if test -n "$LIST"; then + $XGETTEXT $LIST -o $podir/amarok.pot +fi +rm -f rc.cpp diff --git a/test/data/source-with-manpage/doc/CMakeLists.txt b/test/data/source-with-manpage/doc/CMakeLists.txt new file mode 100644 index 0000000..0137356 --- /dev/null +++ b/test/data/source-with-manpage/doc/CMakeLists.txt @@ -0,0 +1,4 @@ +########### install files ############### +# +# +kdoctools_create_manpage (man-amarok.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR}) diff --git a/test/data/source-with-manpage/doc/man-amarok.1.docbook b/test/data/source-with-manpage/doc/man-amarok.1.docbook new file mode 100644 index 0000000..112ed86 --- /dev/null +++ b/test/data/source-with-manpage/doc/man-amarok.1.docbook @@ -0,0 +1 @@ +manpage diff --git a/test/data/source-with-manpage/doc/subdir/CMakeLists.txt b/test/data/source-with-manpage/doc/subdir/CMakeLists.txt new file mode 100644 index 0000000..6ce843f --- /dev/null +++ b/test/data/source-with-manpage/doc/subdir/CMakeLists.txt @@ -0,0 +1,4 @@ +########### install files ############### +# +# +kdoctools_create_manpage (man-unicorn.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR}) diff --git a/test/data/source-with-manpage/doc/subdir/man-unicorn.1.docbook b/test/data/source-with-manpage/doc/subdir/man-unicorn.1.docbook new file mode 100644 index 0000000..112ed86 --- /dev/null +++ b/test/data/source-with-manpage/doc/subdir/man-unicorn.1.docbook @@ -0,0 +1 @@ +manpage diff --git a/test/documentation_test.rb b/test/documentation_test.rb index b28b206..ee3d28d 100644 --- a/test/documentation_test.rb +++ b/test/documentation_test.rb @@ -1,3 +1,23 @@ +#-- +# Copyright (C) 2014-2017 Harald Sitter <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License or (at your option) version 3 or any later version +# accepted by the membership of KDE e.V. (or its successor approved +# by the membership of KDE e.V.), which shall act as a proxy +# defined in Section 14 of version 3 of the license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +#++ + require 'fileutils' require_relative 'lib/testme' @@ -44,7 +64,7 @@ class TestDocumentation < Testme end def create_doc_without_translation - ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, 'frenchfries', @i18n_path) + ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, 'frenchfries', 'frenchfries') end def test_no_doc @@ -58,6 +78,8 @@ class TestDocumentation < Testme d.get(@dir) assert_path_exist("#{@dir}/Messages.sh") refute_path_exist("#{@dir}/doc") + assert_equal([], Dir.glob("#{@dir}/po/*/docs")) + refute_path_exist('CMakeLists.txt') end def test_get_doc @@ -67,13 +89,21 @@ class TestDocumentation < Testme FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) d.get(@dir) - assert_path_exist("#{@dir}/CMakeLists.txt") - assert_path_exist("#{@dir}/doc/CMakeLists.txt") - assert_path_exist("#{@dir}/doc/en/index.docbook") - assert_path_exist("#{@dir}/doc/en/CMakeLists.txt") - assert_path_exist("#{@dir}/doc/de/index.docbook") - assert_path_exist("#{@dir}/doc/de/CMakeLists.txt") + Dir.chdir(@dir) do + assert_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') + + docs = Dir.glob('po/*/docs/*') + assert_includes(docs, 'po/fr/docs/amarok') + assert_includes(docs, 'po/de/docs/amarok') + assert_equal(2, docs.size) + + # en tree is ok + assert_path_exist('doc/index.docbook') + # FIXME: should we require a cmakelists? + end + end + def test_get_doc_without_l10n # en only (everything works if only doc/ is present in git but not # translated) d = create_doc_without_translation @@ -81,58 +111,55 @@ class TestDocumentation < Testme FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) d.get(@dir) - assert_path_exist("#{@dir}/CMakeLists.txt") - assert_path_exist("#{@dir}/doc/CMakeLists.txt") - assert_path_exist("#{@dir}/doc/en/index.docbook") - assert_path_exist("#{@dir}/doc/en/CMakeLists.txt") - refute_path_exist("#{@dir}/doc/de/index.docbook") - refute_path_exist("#{@dir}/doc/de/CMakeLists.txt") + Dir.chdir(@dir) do + refute_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') + + assert_empty(Dir.glob('po/*/docs/*')) + + assert_path_exist('doc/CMakeLists.txt') + assert_path_exist('doc/index.docbook') + end end def test_get_doc_multi_doc d = ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, - 'plasma-desktop', - 'kde-workspace') + 'plasma-desktop', + 'kde-workspace') d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-doc'), @dir) d.get(@dir) # fr mustn't appear, it's empty - # FIXME: I am actually not sure CMakeLists ought to be generated - # recursively through 2->2.1->2.1.1 at all. - expected_files = %w( + expected_files = %w[ CMakeLists.txt - en - en/CMakeLists.txt - en/doc-valid2 - en/doc-valid2/CMakeLists.txt - en/doc-valid2/index.docbook - en/doc-valid2/doc-valid2.1 - en/doc-valid2/doc-valid2.1/CMakeLists.txt - en/doc-valid2/doc-valid2.1/index.docbook - en/doc-valid2/doc-valid2.1/doc-valid2.1.1 - en/doc-valid2/doc-valid2.1/doc-valid2.1.1/CMakeLists.txt - en/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook - en/doc-invalid1 - en/doc-valid1 - en/doc-valid1/CMakeLists.txt - en/doc-valid1/index.docbook - de - de/CMakeLists.txt - de/doc-valid2 - de/doc-valid2/CMakeLists.txt - de/doc-valid2/index.docbook - de/doc-valid2/doc-valid2.1 - de/doc-valid2/doc-valid2.1/CMakeLists.txt - de/doc-valid2/doc-valid2.1/index.docbook - de/doc-valid2/doc-valid2.1/doc-valid2.1.1 - de/doc-valid2/doc-valid2.1/doc-valid2.1.1/CMakeLists.txt - de/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook - de/doc-valid1 - de/doc-valid1/CMakeLists.txt - de/doc-valid1/index.docbook - ) - present_files = Dir.chdir("#{@dir}/doc/") { Dir.glob('**/**') } + doc + doc/CMakeLists.txt + doc/doc-valid2 + doc/doc-valid2/CMakeLists.txt + doc/doc-valid2/index.docbook + doc/doc-valid2/doc-valid2.1 + doc/doc-valid2/doc-valid2.1/CMakeLists.txt + doc/doc-valid2/doc-valid2.1/index.docbook + doc/doc-valid2/doc-valid2.1/doc-valid2.1.1 + doc/doc-valid2/doc-valid2.1/doc-valid2.1.1/CMakeLists.txt + doc/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook + doc/doc-invalid1 + doc/doc-valid1 + doc/doc-valid1/CMakeLists.txt + doc/doc-valid1/index.docbook + po + po/de + po/de/docs + po/de/docs/doc-valid2 + po/de/docs/doc-valid2/index.docbook + po/de/docs/doc-valid2/doc-valid2.1 + po/de/docs/doc-valid2/doc-valid2.1/index.docbook + po/de/docs/doc-valid2/doc-valid2.1/doc-valid2.1.1 + po/de/docs/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook + po/de/docs/doc-valid1 + po/de/docs/doc-valid1/index.docbook + ] + present_files = Dir.chdir(@dir) { Dir.glob('**/**') } missing_files = [] expected_files.each do |f| missing_files << f unless present_files.include?(f) @@ -141,6 +168,29 @@ class TestDocumentation < Testme assert(missing_files.empty?, "missing file(s): #{missing_files}") assert(present_files.empty?, "unexpected file(s): #{present_files}") - # FIXME: check contents? + Dir.chdir(@dir) do + assert_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') + end + end + + def test_man + d = create_doc + d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + FileUtils.rm_rf(@dir) + FileUtils.cp_r(data('source-with-manpage'), @dir) + d.get(@dir) + Dir.chdir(@dir) do + assert_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') + + # NOTE: Our manpage line up is different from applications releases. + # We pack them into their original subdir whereas the other script + # packs them into the main dir. The reason is that we use the same code + # paths as for documentation which makes it cheaper for us to preserver + # the dir. + docs = Dir.glob('po/*/docs/**/*.docbook') + assert_includes(docs, 'po/de/docs/amarok/man-amarok.1.docbook') + assert_includes(docs, 'po/de/docs/amarok/unicorn/man-unicorn.1.docbook') + assert_equal(2, docs.size) + end end end
