From 68190084f549dcf15f18f031c9609ab684d2a87f Mon Sep 17 00:00:00 2001 From: Jason Shi Date: Tue, 16 May 2023 06:33:41 -0700 Subject: [PATCH 1/2] Add "license-org" and "license-text" parameters If "license-org" and license-text" are passing in command line, the default value will be overlayed in generated files. Signed-off-by: Jason Shi --- superflore/generators/bitbake/gen_packages.py | 4 +--- superflore/generators/bitbake/run.py | 5 +++++ superflore/generators/bitbake/yocto_recipe.py | 22 ++++++++++++++----- superflore/generators/ebuild/ebuild.py | 13 ++++++----- superflore/generators/ebuild/gen_packages.py | 6 +---- superflore/generators/ebuild/run.py | 6 +++++ superflore/parser.py | 10 +++++++++ 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/superflore/generators/bitbake/gen_packages.py b/superflore/generators/bitbake/gen_packages.py index 7c9cd8fb..08cdfea5 100644 --- a/superflore/generators/bitbake/gen_packages.py +++ b/superflore/generators/bitbake/gen_packages.py @@ -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, @@ -238,4 +236,4 @@ def __init__( ) def recipe_text(self): - return self.recipe.get_recipe_text(org) + return self.recipe.get_recipe_text() diff --git a/superflore/generators/bitbake/run.py b/superflore/generators/bitbake/run.py index 88c9c4cd..39fc3f8f 100644 --- a/superflore/generators/bitbake/run.py +++ b/superflore/generators/bitbake/run.py @@ -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') diff --git a/superflore/generators/bitbake/yocto_recipe.py b/superflore/generators/bitbake/yocto_recipe.py index 9e413f6a..c35cf911 100644 --- a/superflore/generators/bitbake/yocto_recipe.py +++ b/superflore/generators/bitbake/yocto_recipe.py @@ -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 @@ -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: @@ -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.' @@ -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 ' diff --git a/superflore/generators/ebuild/ebuild.py b/superflore/generators/ebuild/ebuild.py index e4034572..33865231 100644 --- a/superflore/generators/ebuild/ebuild.py +++ b/superflore/generators/ebuild/ebuild.py @@ -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 = "" @@ -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 @@ -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= - 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 diff --git a/superflore/generators/ebuild/gen_packages.py b/superflore/generators/ebuild/gen_packages.py index 915ec519..459c3311 100644 --- a/superflore/generators/ebuild/gen_packages.py +++ b/superflore/generators/ebuild/gen_packages.py @@ -39,10 +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) ebuild_name =\ @@ -214,4 +210,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() diff --git a/superflore/generators/ebuild/run.py b/superflore/generators/ebuild/run.py index 866d4c52..fc876e89 100644 --- a/superflore/generators/ebuild/run.py +++ b/superflore/generators/ebuild/run.py @@ -20,6 +20,7 @@ from superflore.generate_installers import generate_installers from superflore.generators.ebuild.gen_packages import regenerate_pkg from superflore.generators.ebuild.overlay_instance import RosOverlay +from superflore.generators.ebuild.ebuild import Ebuild from superflore.parser import get_parser from superflore.repo_instance import RepoInstance from superflore.TempfileManager import TempfileManager @@ -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() diff --git a/superflore/parser.py b/superflore/parser.py index 184c984f..d3085b39 100644 --- a/superflore/parser.py +++ b/superflore/parser.py @@ -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 From a9ee9411f91c67e717c1047a56e4ed981be6da08 Mon Sep 17 00:00:00 2001 From: Jason Shi Date: Thu, 1 Jun 2023 11:37:26 +0800 Subject: [PATCH 2/2] test: update ebuild.get_ebuild_text parameters Signed-off-by: Jason Shi --- superflore/generators/ebuild/gen_packages.py | 1 + superflore/generators/ebuild/run.py | 2 +- tests/test_ebuild.py | 36 ++++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/superflore/generators/ebuild/gen_packages.py b/superflore/generators/ebuild/gen_packages.py index 459c3311..bf1d452e 100644 --- a/superflore/generators/ebuild/gen_packages.py +++ b/superflore/generators/ebuild/gen_packages.py @@ -39,6 +39,7 @@ no_python3 = ['tf'] + def regenerate_pkg(overlay, pkg, distro, preserve_existing=False): version = get_pkg_version(distro, pkg) ebuild_name =\ diff --git a/superflore/generators/ebuild/run.py b/superflore/generators/ebuild/run.py index fc876e89..aa3cc497 100644 --- a/superflore/generators/ebuild/run.py +++ b/superflore/generators/ebuild/run.py @@ -19,8 +19,8 @@ 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.overlay_instance import RosOverlay 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 from superflore.TempfileManager import TempfileManager diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py index 36c732cd..a5382641 100644 --- a/tests/test_ebuild.py +++ b/tests/test_ebuild.py @@ -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) @@ -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): @@ -56,14 +56,14 @@ 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): @@ -71,7 +71,7 @@ def test_external_run_depend(self): 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): @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 )"')