Git commit c9c64efcd530946e534761cc3aa5abfc557e2d2b by Harald Sitter. Committed on 23/01/2015 at 09:56. Pushed by sitter into branch 'fix-documentation'.
initial support for multi-documention fetching this is where doc/ contains multiple dirs rather than a flat structure with one index.docbook. there are a number of restrictions on this a) it's either or, you can't have both b) multi-dir doc directories *MUST* use optional_add_subdir, this in particular is necessary because the CMakeLists will be replicated into translations as to allow the use of branching based on available cmake packages for example c) a doc folder that is not in the source will also not be included from the translations (kinda obvious) d) all subdirectories are auto-supplied with CMakeLists.txt M +74 -44 lib/documentation.rb A +0 -0 test/data/cmakeeditor/test_create_handbook_complex/de/doc1/index.docbook A +1 -0 test/data/cmakeeditor/test_create_handbook_complex/en_US/CMakeLists.txt A +0 -0 test/data/cmakeeditor/test_create_handbook_complex/en_US/doc1/index.docbook A +0 -0 test/data/cmakeeditor/test_create_handbook_complex/en_US/doc2/index.docbook A +0 -0 test/data/cmakeeditor/test_create_handbook_complex/fr/doc2/index.docbook A +0 -0 test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid1/index.docbook A +0 -0 test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook A +0 -0 test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/doc-valid2.1/index.docbook A +0 -0 test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/index.docbook A +0 -0 test/data/multi-doc/CMakeLists.txt M +174 -89 test/test_cmakeeditor.rb M +53 -0 test/test_l10n.rb http://commits.kde.org/releaseme/c9c64efcd530946e534761cc3aa5abfc557e2d2b diff --git a/lib/documentation.rb b/lib/documentation.rb index 12ebc71..7b55fd6 100644 --- a/lib/documentation.rb +++ b/lib/documentation.rb @@ -93,76 +93,106 @@ class DocumentationL10n < Source end def get(sourceDirectory) - previous_pwd = Dir.pwd dir = "#{Dir.pwd}/#{sourceDirectory}/doc" temp_dir = "#{Dir.pwd}/#{sourceDirectory}/l10n" Dir.mkdir(dir) unless File.exists?(dir) availableLanguages = vcs.cat("subdirs").split("\n") - docs = Array.new - - # On git a layout doc/{file,file,file} may appear, in this case we move stuff - # to en_US. - # A more complicated case would be doc/{dir,dir}/{file,file} which can happen for - # multisource repos such as plasma-workspace. - # FIXME: multi-source documentation is not tested - # need new data set with something like - # doc/foo/index.docbook - # doc/bar/index.docbook - # doc/foobar/meow.txt - unless Dir.glob("#{dir}/**/index.docbook").empty? or File.exists?("#{dir}/en_US") then - files = Dir.glob("#{dir}/*").uniq - p files - Dir.mkdir("#{dir}/en_US") - FileUtils.mv(files, "#{dir}/en_US") - docs << "en_US" # We placed an en_US, make sure it is in the docs list. + docs = [] + + # On git a layout doc/{file,file,file} may appear, in this case we move + # stuff to en_US. + # A more complicated case would be doc/{dir,dir}/{file,file} which can + # happen for multisource repos such as plasma-workspace. + unless Dir.glob("#{dir}/**/index.docbook").empty? || + File.exist?("#{dir}/en_US") + files = Dir.glob("#{dir}/*").uniq + Dir.mkdir("#{dir}/en_US") + FileUtils.mv(files, "#{dir}/en_US") + docs << 'en_US' # We created an en_US, make sure it is in the list. end # No documentation avilable -> leave me alone - if not File.exists?("#{dir}/en_US") then - puts("There is no en_US documentation :(") - puts("Leave me alone :(") - return + unless File.exist?("#{dir}/en_US") + puts 'There is no en_US documentation :(' + puts 'Leave me alone :(' + return end CMakeEditor::create_language_specific_doc_lists!("#{dir}/en_US", "en_US", project_name) - for language in availableLanguages + availableLanguages.each do |language| + p language language.chomp! next if language == "x-test" or language == "en_US" puts "Downloading #{language} documentation translations for #{sourceDirectory}" - FileUtils.rm_rf(temp_dir) - vcs.get(temp_dir, vcs_l10n_path(language)) - unless FileTest.exists?("#{temp_dir}/index.docbook") # without index the translation is not worth butter - puts ' no valid documentation translation found, skipping.' - next + + doc_dirs = Dir.chdir("#{dir}/en_US") do + Dir.glob("*").select { |f| File.directory?(f) } end dest_dir = "#{dir}/#{language}" - puts("Copying #{language}'s #{@project_name} documentation over...") - FileUtils.mv(temp_dir, dest_dir) + done = false + + puts " Trying to copy..." + if !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(temp_dir, "#{language}/docs/#{@i18n_path}") + not_translated_doc_dirs = doc_dirs.clone + doc_selection = Dir.glob("#{temp_dir}/*").select do |d| + basename = File.basename(d) + if doc_dirs.include?(basename) + not_translated_doc_dirs.delete(basename) + next true + end + next false + end + p not_translated_doc_dirs + p doc_selection + if doc_selection.empty? + next + end + Dir.mkdir(dest_dir) # Important otherwise first copy is dir itself... + doc_selection.each do |d| + FileUtils.mv(d, dest_dir, verbose: true) + end + puts `ls -lah #{dest_dir}` + CMakeEditor::create_language_specific_doc_lists!(dest_dir, language, project_name) + docs += [language] + done = true + end + unless done + # FIXME this also needs to act as fallback + puts vcs.get(temp_dir, vcs_l10n_path(language)) + unless FileTest.exists?("#{temp_dir}/index.docbook") # without index the translation is not worth butter + puts ' no valid documentation translation found, skipping.' + next + end - CMakeEditor::create_language_specific_doc_lists!("#{dir}/#{language}", language, project_name) + FileUtils.mv(temp_dir, dest_dir) - # add to SVN in case we are tagging - # FIXME: direct svn access - `svn add #{dir}/#{language}/CMakeLists.txt` - docs += [language] + CMakeEditor.create_language_specific_doc_lists!("#{dir}/#{language}", language, project_name) + + # add to SVN in case we are tagging + # FIXME: direct svn access + `svn add #{dir}/#{language}/CMakeLists.txt` + docs += [language] + end - puts( "done.\n" ) + puts 'done.' + puts end - if not docs.empty? - CMakeEditor::create_doc_meta_lists!(dir) - CMakeEditor::append_optional_add_subdirectory!(sourceDirectory, 'doc') + if !docs.empty? + CMakeEditor.create_doc_meta_lists!(dir) + CMakeEditor.append_optional_add_subdirectory!(sourceDirectory, 'doc') else - puts "no docs found :'<" - FileUtils::rm_rf(dir) + puts 'no docs found !!!' + FileUtils.rm_rf(dir) end - FileUtils::rm_rf(temp_dir) - ensure - Dir.chdir(previous_pwd) + FileUtils.rm_rf(temp_dir) end end diff --git a/test/data/cmakeeditor/test_create_handbook_complex/de/doc1/index.docbook b/test/data/cmakeeditor/test_create_handbook_complex/de/doc1/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/cmakeeditor/test_create_handbook_complex/en_US/CMakeLists.txt b/test/data/cmakeeditor/test_create_handbook_complex/en_US/CMakeLists.txt new file mode 100644 index 0000000..821cc64 --- /dev/null +++ b/test/data/cmakeeditor/test_create_handbook_complex/en_US/CMakeLists.txt @@ -0,0 +1 @@ +ecm_optional_add_subdirectory(doc1) diff --git a/test/data/cmakeeditor/test_create_handbook_complex/en_US/doc1/index.docbook b/test/data/cmakeeditor/test_create_handbook_complex/en_US/doc1/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/cmakeeditor/test_create_handbook_complex/en_US/doc2/index.docbook b/test/data/cmakeeditor/test_create_handbook_complex/en_US/doc2/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/cmakeeditor/test_create_handbook_complex/fr/doc2/index.docbook b/test/data/cmakeeditor/test_create_handbook_complex/fr/doc2/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid1/index.docbook b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid1/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/doc-valid2.1/index.docbook b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/doc-valid2.1/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/index.docbook b/test/data/l10nrepo/trunk/l10n-kf5/de/docs/kde-workspace/doc-valid2/index.docbook new file mode 100644 index 0000000..e69de29 diff --git a/test/data/multi-doc/CMakeLists.txt b/test/data/multi-doc/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/test_cmakeeditor.rb b/test/test_cmakeeditor.rb index c0d9dbc..c28baac 100644 --- a/test/test_cmakeeditor.rb +++ b/test/test_cmakeeditor.rb @@ -25,104 +25,189 @@ require_relative "lib/testme" require_relative "../lib/cmakeeditor" class TestCMakeEditor < Testme - attr_accessor :dir - attr_accessor :file - attr_accessor :lang - - def setup - @dir = Dir.pwd + "/tmp_cmakeeditor_" + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join - Dir.mkdir(@dir) - @file = @dir + "/CMakeLists.txt" - @lang = 'xx' - end + attr_accessor :dir + attr_accessor :file + attr_accessor :lang - def teardown - FileUtils.rm_rf(@dir) - end + def setup + @dir = Dir.pwd + "/tmp_cmakeeditor_" + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join + Dir.mkdir(@dir) + @file = @dir + "/CMakeLists.txt" + @lang = 'xx' + end - def assert_has_terminal_newline(data) - assert(data.end_with?("\n")) - end + def teardown + FileUtils.rm_rf(@dir) + 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') - CMakeEditor::create_language_specific_doc_lists!(dir, lang, "yolo") - assert(File::exists?(file)) - data = File.read(file) - assert(data.downcase.include?('kdoctools_create_handbook(index.docbook install_destination ${html_install_dir}/xx subdir yolo)')) - assert_has_terminal_newline(data) - end + def assert_has_terminal_newline(data) + assert(data.end_with?("\n")) + end - def test_create_doc_meta_lists - Dir.mkdir("#{dir}/aa") - Dir.mkdir("#{dir}/bb") - Dir.mkdir("#{dir}/cc") - CMakeEditor::create_doc_meta_lists!(dir) - assert(File::exists?(file)) - data = File.read(file) - 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 assert_valid_kdoctools(file) + p file + parts = file.split('/') + language = parts.first + dir = parts[-2] + expected_line = CMakeEditor.create_handbook(language, dir) + assert_equal(expected_line, File.read(file)) + end - def create_cmakelists! - f = File.new(@file, File::CREAT | File::RDWR | File::TRUNC) - f << "#FOO_SUBDIR\n" - f.close + def assert_equal_valid_meta_cmakelists(dir, file = 'CMakeLists.txt') + Dir.chdir(dir) do + dirs = Dir.glob('*').select { |f| File.directory?(f) } + # FIXME: this again a variation of assert unordered nonesense lists + # see below + expected_subdirs = [] + dirs.each do |d| + expected_subdirs << CMakeEditor.add_subdirectory(d).strip + end + present_subdirs = File.read(file).split($RS) + missing_subdirs = [] + expected_subdirs.each do |f| + missing_subdirs << f unless present_subdirs.include?(f) + present_subdirs.delete(f) + end + assert(missing_subdirs.empty?, "missing dir(S): #{missing_subdirs}") + assert(present_subdirs.empty?, "unexpected dir(s): #{present_subdirs}") end + end - def test_append_po_install_instructions_append - create_cmakelists! - CMakeEditor::append_po_install_instructions!(dir, 'po') - assert(File::exists?(file)) - data = File.read(file) - assert(data.include?("#FOO_SUBDIR\n")) - assert(data.include?("ki18n_install(po)")) - assert_has_terminal_newline(data) - # Make sure the editor doesn't append if it is already there... - CMakeEditor::append_po_install_instructions!(dir, 'po') - data = File.read(file) - assert(data.scan('ki18n_install(po)').count == 1) + def test_create_handbook_complex + # tmpdir now conflicts with testme... + FileUtils.rm_rf(@dir) + origin_dir = "#{@datadir}/cmakeeditor/#{__method__}" + FileUtils.cp_r(Dir.glob("#{origin_dir}/*"), '.', verbose: true) + %w(en_US de fr).each do |lang| + CMakeEditor.create_language_specific_doc_lists!("#{Dir.pwd}/#{lang}", lang, 'yolo') end - - def test_append_po_install_instructions_substitute - create_cmakelists! - CMakeEditor::append_po_install_instructions!(dir, 'foo') - assert(File::exists?(file)) - data = File.read(file) - assert(!data.include?("#FOO_SUBDIR\n")) - assert(data.include?("ki18n_install(foo)")) - assert_has_terminal_newline(data) + # 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_US + en_US/CMakeLists.txt + en_US/doc1 + en_US/doc1/CMakeLists.txt + en_US/doc1/index.docbook + en_US/doc2 + en_US/doc2/CMakeLists.txt + en_US/doc2/index.docbook + de + de/CMakeLists.txt + de/doc1 + de/doc1/CMakeLists.txt + de/doc1/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_US/CMakeLists.txt'), + File.read('fr/CMakeLists.txt')) + assert_valid_kdoctools('fr/doc2/CMakeLists.txt') + assert_valid_kdoctools('en_US/doc1/CMakeLists.txt') + assert_valid_kdoctools('en_US/doc2/CMakeLists.txt') + assert_equal(File.read('en_US/CMakeLists.txt'), + File.read('de/CMakeLists.txt')) + assert_valid_kdoctools('de/doc1/CMakeLists.txt') + end - def test_append_optional_add_subdirectory_append - create_cmakelists! - CMakeEditor::append_optional_add_subdirectory!(dir, 'append') - assert(File::exists?(file)) - data = File.read(file) - assert(data.include?("#FOO_SUBDIR\n")) - assert(data.include?("add_subdirectory(append)")) - assert_has_terminal_newline(data) - # Make sure the editor doesn't append if it is already there... - CMakeEditor::append_optional_add_subdirectory!(dir, 'po') - data = File.read(file) - assert(data.scan('add_subdirectory(append)').count == 1) - 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("#{dir}/index.docbook") + CMakeEditor.create_language_specific_doc_lists!(dir, lang, 'yolo') + assert(File.exist?(file)) + data = File.read(file) + assert_equal(CMakeEditor.create_handbook(lang, 'yolo'), data) + assert_has_terminal_newline(data) + end - def test_append_optional_add_subdirectory_substitute - create_cmakelists! - CMakeEditor::append_optional_add_subdirectory!(dir, 'foo') - assert(File::exists?(file)) - data = File.read(file) - assert(!data.include?("#FOO_SUBDIR\n")) - assert(data.include?("ECMOptionalAddSubdirectory")) - assert(data.include?("ecm_optional_add_subdirectory(foo")) - assert_has_terminal_newline(data) - end + def test_create_handbook_uses_basename + lang = 'fr' + with_path = CMakeEditor.create_handbook(lang, '/tmp/kittens') + with_name = CMakeEditor.create_handbook(lang, 'kittens') + assert_equal(with_path, with_name) + end + + def test_create_doc_meta_lists + Dir.mkdir("#{dir}/aa") + Dir.mkdir("#{dir}/bb") + Dir.mkdir("#{dir}/cc") + CMakeEditor.create_doc_meta_lists!(dir) + assert(File.exist?(file)) + data = File.read(file) + 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(@file, File::CREAT | File::RDWR | File::TRUNC) + f << "#FOO_SUBDIR\n" + f.close + end + + def test_append_po_install_instructions_append + create_cmakelists! + CMakeEditor::append_po_install_instructions!(dir, 'po') + assert(File::exists?(file)) + data = File.read(file) + assert(data.include?("#FOO_SUBDIR\n")) + assert(data.include?("ki18n_install(po)")) + assert_has_terminal_newline(data) + # Make sure the editor doesn't append if it is already there... + CMakeEditor::append_po_install_instructions!(dir, 'po') + data = File.read(file) + assert(data.scan('ki18n_install(po)').count == 1) + end + + def test_append_po_install_instructions_substitute + create_cmakelists! + CMakeEditor::append_po_install_instructions!(dir, 'foo') + assert(File::exists?(file)) + data = File.read(file) + assert(!data.include?("#FOO_SUBDIR\n")) + assert(data.include?("ki18n_install(foo)")) + assert_has_terminal_newline(data) + end + + def test_append_optional_add_subdirectory_append + create_cmakelists! + CMakeEditor::append_optional_add_subdirectory!(dir, 'append') + assert(File::exists?(file)) + data = File.read(file) + assert(data.include?("#FOO_SUBDIR\n")) + assert(data.include?("add_subdirectory(append)")) + assert_has_terminal_newline(data) + # Make sure the editor doesn't append if it is already there... + CMakeEditor::append_optional_add_subdirectory!(dir, 'po') + data = File.read(file) + assert(data.scan('add_subdirectory(append)').count == 1) + end + + def test_append_optional_add_subdirectory_substitute + create_cmakelists! + CMakeEditor::append_optional_add_subdirectory!(dir, 'foo') + assert(File::exists?(file)) + data = File.read(file) + assert(!data.include?("#FOO_SUBDIR\n")) + assert(data.include?("ECMOptionalAddSubdirectory")) + assert(data.include?("ecm_optional_add_subdirectory(foo")) + assert_has_terminal_newline(data) + end end diff --git a/test/test_l10n.rb b/test/test_l10n.rb index 5a5eabe..2cdfdd6 100644 --- a/test/test_l10n.rb +++ b/test/test_l10n.rb @@ -154,4 +154,57 @@ class TestL10n < Testme assert(!File::exists?("#{@dir}/doc/de/index.docbook")) assert(!File::exists?("#{@dir}/doc/de/CMakeLists.txt")) end + + def test_get_doc_multi_doc + d = DocumentationL10n.new(DocumentationL10n::TRUNK, "plasma-desktop", 'kde-workspace') + d.initRepoUrl("file://#{Dir.pwd}/#{@svnTemplateDir}") + 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( + CMakeLists.txt + en_US + en_US/CMakeLists.txt + en_US/doc-valid2 + en_US/doc-valid2/CMakeLists.txt + en_US/doc-valid2/index.docbook + en_US/doc-valid2/doc-valid2.1 + en_US/doc-valid2/doc-valid2.1/CMakeLists.txt + en_US/doc-valid2/doc-valid2.1/index.docbook + en_US/doc-valid2/doc-valid2.1/doc-valid2.1.1 + en_US/doc-valid2/doc-valid2.1/doc-valid2.1.1/CMakeLists.txt + en_US/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook + en_US/doc-invalid1 + en_US/doc-valid1 + en_US/doc-valid1/CMakeLists.txt + en_US/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('**/**') } + 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}") + + # FIXME: check contents? + end end
