diff --git a/bloom/generators/debian/generator.py b/bloom/generators/debian/generator.py index fe629c8d..2a980a7d 100644 --- a/bloom/generators/debian/generator.py +++ b/bloom/generators/debian/generator.py @@ -108,6 +108,12 @@ debug(traceback.format_exc()) error("empy was not detected, please install it.", exit=True) +try: + from ros_license_toolkit.package import get_packages_in_path +except ImportError: + debug(traceback.format_exc()) + error("ros_license_toolkit was not detected, please install it.", exit=True) + # Fix unicode bug in empy # This should be removed once upstream empy is fixed # See: https://github.com/ros-infrastructure/bloom/issues/196 @@ -118,7 +124,6 @@ except NameError: pass # End fix - # Drop the first log prefix for this command enable_drop_first_log_prefix(True) @@ -467,6 +472,10 @@ def generate_substitutions_from_package( # Summarize dependencies summarize_dependency_mapping(data, depends, build_depends, resolved_deps) # Copyright + package_path = os.path.abspath(os.path.dirname(package.filename)) + pkg = get_packages_in_path(package_path)[0] + data['Copyright_file_content'] = pkg.get_copyright_file_contents() + licenses = [] for l in package.licenses: if hasattr(l, 'file') and l.file is not None: diff --git a/bloom/generators/debian/templates/ament_cmake/copyright.em b/bloom/generators/debian/templates/ament_cmake/copyright.em index bc82fd5d..b9c0a57b 100644 --- a/bloom/generators/debian/templates/ament_cmake/copyright.em +++ b/bloom/generators/debian/templates/ament_cmake/copyright.em @@ -1,11 +1 @@ -Format: Bloom subset of https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: @(Name) -@[if BugTracker]Upstream-Contact: @(BugTracker)@\n@[end if]@ -@[if Source]Source: @(Source)@\n@[end if]@ -@[for License, Text in Licenses]@ - -Files: See file headers in repository for details -Copyright: See package copyright in source code for details -License: @(License) - @(Text) -@[end for]@ +@(Copyright_file_content) diff --git a/bloom/generators/debian/templates/ament_python/copyright.em b/bloom/generators/debian/templates/ament_python/copyright.em index bc82fd5d..b9c0a57b 100644 --- a/bloom/generators/debian/templates/ament_python/copyright.em +++ b/bloom/generators/debian/templates/ament_python/copyright.em @@ -1,11 +1 @@ -Format: Bloom subset of https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: @(Name) -@[if BugTracker]Upstream-Contact: @(BugTracker)@\n@[end if]@ -@[if Source]Source: @(Source)@\n@[end if]@ -@[for License, Text in Licenses]@ - -Files: See file headers in repository for details -Copyright: See package copyright in source code for details -License: @(License) - @(Text) -@[end for]@ +@(Copyright_file_content) diff --git a/bloom/generators/debian/templates/catkin/copyright.em b/bloom/generators/debian/templates/catkin/copyright.em index bc82fd5d..b9c0a57b 100644 --- a/bloom/generators/debian/templates/catkin/copyright.em +++ b/bloom/generators/debian/templates/catkin/copyright.em @@ -1,11 +1 @@ -Format: Bloom subset of https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: @(Name) -@[if BugTracker]Upstream-Contact: @(BugTracker)@\n@[end if]@ -@[if Source]Source: @(Source)@\n@[end if]@ -@[for License, Text in Licenses]@ - -Files: See file headers in repository for details -Copyright: See package copyright in source code for details -License: @(License) - @(Text) -@[end for]@ +@(Copyright_file_content) diff --git a/bloom/generators/debian/templates/cmake/copyright.em b/bloom/generators/debian/templates/cmake/copyright.em index bc82fd5d..b9c0a57b 100644 --- a/bloom/generators/debian/templates/cmake/copyright.em +++ b/bloom/generators/debian/templates/cmake/copyright.em @@ -1,11 +1 @@ -Format: Bloom subset of https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: @(Name) -@[if BugTracker]Upstream-Contact: @(BugTracker)@\n@[end if]@ -@[if Source]Source: @(Source)@\n@[end if]@ -@[for License, Text in Licenses]@ - -Files: See file headers in repository for details -Copyright: See package copyright in source code for details -License: @(License) - @(Text) -@[end for]@ +@(Copyright_file_content) diff --git a/setup.py b/setup.py index 8729e72f..4beca415 100755 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ 'PyYAML', 'rosdep >= 0.15.0', 'rosdistro >= 0.8.0', + 'ros_license_toolkit >= 1.2.2', 'vcstools >= 0.1.22', ] diff --git a/test/system_tests/test_catkin_release.py b/test/system_tests/test_catkin_release.py index 2034ae7e..bd64abdc 100644 --- a/test/system_tests/test_catkin_release.py +++ b/test/system_tests/test_catkin_release.py @@ -82,13 +82,19 @@ def create_upstream_repository(packages, directory=None, format_versions=None): os.symlink('../{0}.h'.format(package), 'include/sym/{0}.h'.format(package)) user('mkdir debian') user('touch debian/something.udev') - user('echo "{0} license" > LICENSE'.format(package)) + user('echo "{0} license text" > LICENSE'.format(package)) + user('echo "(c) 2010 {0} Inc.\n//comment\nsome sourcecode" > include/file.h'.format(package)) user('git add package.xml .cproject .project include debian "white space.txt~" LICENSE') user('git commit -m "Releasing version 0.1.0" --allow-empty') user('git tag 0.1.0 -m "Releasing version 0.1.0"') return os.getcwd() +def _check_string_for_content(string, to_check): + assert string.count(to_check) == 1, \ + ">" + to_check + "< not found in:\n---\n" + string + "\n---" + + def _test_unary_package_repository(release_dir, version, directory=None, env=None): print("Testing in {0} at version {1}".format(release_dir, version)) with change_directory(release_dir): @@ -236,7 +242,8 @@ def test_multi_package_repository(directory=None): env.update(set_up_fake_rosdep(rosdep_dir, fake_distros, fake_rosdeps)) # Setup pkgs = ['foo', 'bar_ros', 'baz'] - upstream_dir = create_upstream_repository(pkgs, directory, format_versions=[1, 2, 3]) + upstream_dir = create_upstream_repository( + pkgs, directory, format_versions=[1, 2, 3]) upstream_url = 'file://' + upstream_dir release_url = create_release_repo( upstream_url, @@ -379,8 +386,15 @@ def test_multi_package_repository(directory=None): package_xml).group(1)) # Is there a copyright file for this pkg? with open('debian/copyright', 'r') as f: - assert (format_version <= 2) ^ (pkg + ' license' in f.read()), \ - "debian/copyright does not include right license text" + copyright_file = f.read() + _check_string_for_content(copyright_file, + "Format: https://www.debian.org/doc/") + _check_string_for_content(copyright_file, + "License: BSD") + _check_string_for_content(copyright_file, + 'Copyright: (c) 2010 ' + pkg + ' Inc.') + _check_string_for_content(copyright_file, + pkg + ' license text') @in_temporary_directory def test_upstream_tag_special_tag(directory=None):