Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "license-org" and "license-text" parameters #298

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions superflore/generators/bitbake/gen_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from superflore.utils import retry_on_exception
from superflore.utils import warn

org = "Open Source Robotics Foundation"


def regenerate_pkg(
overlay, pkg, rosdistro, preserve_existing, srcrev_cache,
Expand Down Expand Up @@ -238,4 +236,4 @@ def __init__(
)

def recipe_text(self):
return self.recipe.get_recipe_text(org)
return self.recipe.get_recipe_text()
5 changes: 5 additions & 0 deletions superflore/generators/bitbake/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def main():
args = parser.parse_args(sys.argv[1:])
pr_comment = args.pr_comment
skip_keys = set(args.skip_keys) if args.skip_keys else set()

if args.license_org:
yoctoRecipe.org = args.license_org
if args.license_text:
yoctoRecipe.org_license = args.license_text
if args.pr_only:
if args.dry_run:
parser.error('Invalid args! cannot dry-run and file PR')
Expand Down
22 changes: 17 additions & 5 deletions superflore/generators/bitbake/yocto_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class yoctoRecipe(object):
platform_deps = set()
max_component_name = 0

org = "Open Source Robotics Foundation"
org_license = ''

def __init__(
self, component_name, num_pkgs, pkg_name, pkg_xml, rosdistro, src_uri,
srcrev_cache, skip_keys
Expand Down Expand Up @@ -377,13 +380,23 @@ def get_dependencies(

return dependencies, system_dependencies

def get_recipe_text(self, distributor):
def get_recipe_license_line(self):
ret = "# Copyright " + yoctoRecipe.org + "\n"
if yoctoRecipe.org_license:
ret += "# Distributed under the terms of the "
ret += yoctoRecipe.org_license
ret += " license\n\n"
else:
ret += "\n"
return ret

def get_recipe_text(self):
"""
Generate the Yocto Recipe, given the distributor line
and the license text.
"""
ret = "# Generated by superflore -- DO NOT EDIT\n#\n"
ret += "# Copyright " + distributor + "\n\n"
ret += self.get_recipe_license_line()
ret += self.get_top_inherit_line()
# description
if self.description:
Expand Down Expand Up @@ -535,7 +548,7 @@ def generate_superflore_datetime_inc(basepath, dist, now):
dist, datetime_file_name))
datetime_file.write('# Generated by superflore -- DO NOT EDIT')
datetime_file.write(
'\n#\n# Copyright Open Source Robotics Foundation\n\n')
'\n#' + yoctoRecipe.get_recipe_license_line())
datetime_file.write(
'\n# The time, in UTC, associated with the last superflore'
+ ' run that resulted in a change to the generated files.'
Expand Down Expand Up @@ -566,8 +579,7 @@ def generate_ros_distro_inc(
conf_file.write('# Generated by superflore -- DO NOT EDIT')
conf_file.write(
' (except ROS_DISTRO_METADATA_VERSION_REVISION)\n#\n')
conf_file.write(
'# Copyright Open Source Robotics Foundation\n\n')
conf_file.write(yoctoRecipe.get_recipe_license_line())
conf_file.write(
'# Increment every time meta-ros is released because of '
+ 'a manually created change, ie, NOT as a result of a '
Expand Down
13 changes: 8 additions & 5 deletions superflore/generators/ebuild/ebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class Ebuild(object):
Basic definition of an ebuild.
This is where any necessary variables will be filled.
"""
org = "Open Source Robotics Foundation"
org_license = "BSD"

def __init__(self):
self.eapi = str(6)
self.description = ""
Expand Down Expand Up @@ -101,10 +104,10 @@ def add_test_depend(self, tdepend, internal=True):
def add_keyword(self, keyword, stable=False):
self.keys.append(ebuild_keyword(keyword, stable))

def get_license_line(self, distributor, license_text):
def get_license_line(self):
ret = "# Copyright " + strftime("%Y", gmtime()) + " "
ret += distributor + "\n"
ret += "# Distributed under the terms of the " + license_text
ret += self.org + "\n"
ret += "# Distributed under the terms of the " + self.org_license
ret += " license\n\n"
return ret

Expand All @@ -130,13 +133,13 @@ def get_inherit_line(self):
else:
raise UnknownBuildType(self.build_type)

def get_ebuild_text(self, distributor, license_text):
def get_ebuild_text(self):
"""
Generate the ebuild in text, given the distributor line
and the license text.
"""
# EAPI=<eapi>
ret = self.get_license_line(distributor, license_text)
ret = self.get_license_line()
ret += self.get_eapi_line()
if self.python_3 and not self.is_ros2:
# enable python 2.7 and python 3.5
Expand Down
5 changes: 1 addition & 4 deletions superflore/generators/ebuild/gen_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@

no_python3 = ['tf']

org = "Open Source Robotics Foundation"
org_license = "BSD"


def regenerate_pkg(overlay, pkg, distro, preserve_existing=False):
version = get_pkg_version(distro, pkg)
Expand Down Expand Up @@ -214,4 +211,4 @@ def metadata_text(self):
return self.metadata_xml.get_metadata_text()

def ebuild_text(self):
return self.ebuild.get_ebuild_text(org, org_license)
return self.ebuild.get_ebuild_text()
6 changes: 6 additions & 0 deletions superflore/generators/ebuild/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from superflore.exceptions import NoGitHubAuthToken
from superflore.generate_installers import generate_installers
from superflore.generators.ebuild.gen_packages import regenerate_pkg
from superflore.generators.ebuild.ebuild import Ebuild
from superflore.generators.ebuild.overlay_instance import RosOverlay
from superflore.parser import get_parser
from superflore.repo_instance import RepoInstance
Expand All @@ -45,6 +46,11 @@ def main():
pr_comment = args.pr_comment
skip_keys = args.skip_keys or []
selected_targets = None

if args.license_org:
Ebuild.org = args.license_org
if args.license_text:
Ebuild.org_license = args.license_text
if not args.dry_run:
if 'SUPERFLORE_GITHUB_TOKEN' not in os.environ:
raise NoGitHubAuthToken()
Expand Down
10 changes: 10 additions & 0 deletions superflore/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ def get_parser(
nargs='+',
help='packages to skip during regeneration'
)
parser.add_argument(
'--license-org',
help='the distributor in copyright line of generated files',
type=str,
)
parser.add_argument(
'--license-text',
help='the license text in copyright line of generated files',
type=str,
)
return parser
36 changes: 18 additions & 18 deletions tests/test_ebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_simple(self):
"""Test Ebuild Format"""
ebuild = self.get_ebuild()
ebuild.add_run_depend('p2os_driver')
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
with open('tests/ebuild/simple_expected.ebuild', 'r') as expect_file:
s = expect_file.read()
correct_text = re.sub('Copyright 2017', 'Copyright ' + strftime("%Y", gmtime()), s)
Expand All @@ -47,7 +47,7 @@ def test_bad_external_build_depend(self):
ebuild.add_run_depend('p2os_driver')
ebuild.add_build_depend('fake_package', False)
with self.assertRaises(UnresolvedDependency):
ebuild_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
ebuild_text = ebuild.get_ebuild_text()
self.assertTrue('fake_package' in ebuild.get_unresolved())

def test_bad_external_run_depend(self):
Expand All @@ -56,22 +56,22 @@ def test_bad_external_run_depend(self):
ebuild.add_run_depend('p2os_driver')
ebuild.add_run_depend('fake_package', False)
with self.assertRaises(UnresolvedDependency):
ebuild_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
ebuild_text = ebuild.get_ebuild_text()

def test_external_build_depend(self):
"""Test External Build Dependency"""
ebuild = self.get_ebuild()
ebuild.add_run_depend('p2os_driver')
ebuild.add_build_depend('cmake', False)
ebuild_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
ebuild_text = ebuild.get_ebuild_text()
self.assertTrue('dev-util/cmake' in ebuild_text)

def test_external_run_depend(self):
"""Test External Run Dependency"""
ebuild = self.get_ebuild()
ebuild.add_run_depend('p2os_driver')
ebuild.add_run_depend('cmake', False)
ebuild_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
ebuild_text = ebuild.get_ebuild_text()
self.assertTrue('dev-util/cmake' in ebuild_text)

def test_rdepend_depend(self):
Expand All @@ -95,7 +95,7 @@ def test_build_depend_internal(self):
"""Test build depends when internal/external"""
ebuild = self.get_ebuild()
ebuild.add_build_depend('p2os_driver', True)
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('p2os_driver' in ebuild.depends)
self.assertFalse('p2os_driver' in ebuild.depends_external)
self.assertTrue('ros-lunar/p2os_driver' in got_text)
Expand All @@ -118,7 +118,7 @@ def test_depend_only_unresolved_rosdep(self):
"""Test DEPEND only packages"""
ebuild = self.get_ebuild()
ebuild.add_run_depend('pkg-config', False)
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('pkg-config' in ebuild.depends_external)
self.assertTrue('virtual/pkgconfig' in got_text)

Expand Down Expand Up @@ -146,20 +146,20 @@ def test_remove_python3(self):
"""Test The python_3 Boolean"""
ebuild = self.get_ebuild()
ebuild.python_3 = False
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('PYTHON_COMPAT=( python2_7 )' in got_text)

def test_default_python2_python3(self):
"""Test That Python2/3 Is the Default"""
ebuild = self.get_ebuild()
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('PYTHON_COMPAT=( python{2_7,3_5,3_6} )' in got_text)

def test_has_patches(self):
"""Test Patch Code Generation"""
ebuild = self.get_ebuild()
ebuild.has_patches = True;
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('EPATCH_SOURCE="${FILESDIR}"' in got_text)
self.assertTrue('EPATCH_SUFFIX="patch"' in got_text)
self.assertTrue('EPATCH_FORCE="yes"' in got_text)
Expand All @@ -168,7 +168,7 @@ def test_has_patches(self):
def test_lacks_patches(self):
"""Test Non-Patched Code Generation"""
ebuild = self.get_ebuild()
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertFalse('EPATCH_SOURCE="${FILESDIR}"' in got_text)
self.assertFalse('EPATCH_SUFFIX="patch"' in got_text)
self.assertFalse('EPATCH_FORCE="yes"' in got_text)
Expand All @@ -178,37 +178,37 @@ def test_opencv3_filter_flags(self):
"""Test Filter Flags for OpenCV3"""
ebuild = self.get_ebuild()
ebuild.name = 'opencv3'
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue("filter-flags '-march=*' '-mcpu=*' '-mtune=*'" in got_text)

def test_stage_filter_flags(self):
"""Test Filter Flags for Stage"""
ebuild = self.get_ebuild()
ebuild.name = 'stage'
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue("filter-flags '-std=*'" in got_text)

def test_distro_variable_mapping(self):
ebuild = self.get_ebuild()
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('ROS_DISTRO="lunar"' in got_text)
ebuild.distro = 'kinetic'
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('ROS_DISTRO="kinetic"' in got_text)

def test_catkin_nonbinary_mode(self):
ebuild = self.get_ebuild()
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertFalse('BUILD_BINARY="0"' in got_text)
ebuild.name = 'catkin'
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
self.assertTrue('BUILD_BINARY="0"' in got_text)

def test_issue_117(self):
"""Test for ros-infrastructure/superflore#117"""
ebuild = self.get_ebuild()
ebuild.upstream_license = ['BSD,LGPL,Apache 2.0']
got_text = ebuild.get_ebuild_text('Open Source Robotics Foundation', 'BSD')
got_text = ebuild.get_ebuild_text()
# grab the license line
license_line = [line for line in got_text.split('\n') if "LICENSE" in line][0]
self.assertEqual(license_line, 'LICENSE="( BSD LGPL Apache-2.0 )"')