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

Merge NixOS support (#2) #309

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7258477
Fix code style guide problems for PEP8 and Flake8
robwoolley Dec 11, 2024
e373e3a
Add support for Nix package generation.
lopsided98 Apr 1, 2019
d7848b1
Simple performance optimizations based on profiling.
lopsided98 May 5, 2019
34ec057
nix: add tests and fix code style
lopsided98 May 5, 2019
e45c948
nix: update to account for upstream changes
lopsided98 Dec 8, 2019
65066d7
nix: add ROS 2 support
lopsided98 Nov 7, 2019
ce860ad
Add ROS_PYTHON_VERSION to distro condition context.
lopsided98 Nov 8, 2019
b9f020f
nix: update based on upstream changes
lopsided98 Dec 8, 2019
cdfe6f6
nix: fix submitting pull requests.
lopsided98 Dec 9, 2019
2bad38b
nix: make dependency ordering deterministic
lopsided98 Dec 10, 2019
3d8c1c0
nix: put generated files in a subdirectory
lopsided98 Jan 18, 2020
f1a4bd0
nix: fix downloading archives from GitLab
lopsided98 May 2, 2020
6c49e84
nix: fix integration test ArgumentParser description
lopsided98 Aug 24, 2020
0f1e781
utils: ignore error removing downloaded file on error
lopsided98 Aug 24, 2020
d2e1109
nix: sort license dictionary
lopsided98 Mar 29, 2022
34f7f39
nix: add more license mappings
lopsided98 Mar 29, 2022
3fd5aa9
nix: provide condition context to package metadata parser
lopsided98 Mar 29, 2022
f014437
nix: add buildtool_depends to both buildInputs and nativeBuildInputs
lopsided98 Sep 20, 2022
a85af4f
nix: fix formatting to satisfy pycodestyle and flake8
lopsided98 Dec 9, 2022
d45c3ed
nix: rename NixDerivation to NixExpression
lopsided98 Dec 9, 2022
6865dfd
nix: fix license test and public domain license
lopsided98 Dec 9, 2022
d49c52d
nix: add rolling to --all mode
lopsided98 Dec 9, 2022
adcd250
nix: fix: escape special characters in license
koalp Feb 19, 2024
6d5327e
nix: escape description string
lopsided98 Mar 23, 2024
8063140
Fix trailing whitespace
lopsided98 Mar 23, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Supported Platforms:
--------------------
* Gentoo
* OpenEmbedded
* Nix

Installation:
=============
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def append_local_version_label(public_version):
'console_scripts': [
'superflore-gen-ebuilds = superflore.generators.ebuild:main',
'superflore-gen-oe-recipes = superflore.generators.bitbake:main',
'superflore-gen-nix = superflore.generators.nix:main',
'superflore-check-ebuilds = superflore.test_integration.gentoo:main',
]
}
Expand Down
8 changes: 5 additions & 3 deletions superflore/generators/bitbake/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ def main():
delta = "Regenerated: '%s'\n" % args.only
overlay.add_generated_files(args.ros_distro)
commit_msg = '\n'.join([get_pr_text(
title + '\n' + pr_comment.replace(
'**superflore**', 'superflore'), markup=''), delta])
comment=title + '\n' + pr_comment.replace(
'**superflore**', 'superflore'),
markup=''), delta])
overlay.commit_changes(args.ros_distro, commit_msg)
if args.dry_run:
save_pr(overlay, args.only, '', pr_comment, title=title)
Expand Down Expand Up @@ -216,7 +217,8 @@ def main():
args.ros_distro,
now)
commit_msg = '\n'.join([get_pr_text(
title + '\n' + pr_comment.replace('**superflore**', 'superflore'),
comment=title + '\n' +
pr_comment.replace('**superflore**', 'superflore'),
markup=''), delta])
overlay.commit_changes(args.ros_distro, commit_msg)
delta = gen_delta_msg(total_changes)
Expand Down
10 changes: 7 additions & 3 deletions superflore/generators/ebuild/gen_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def _gen_metadata_for_package(
warn("fetch metadata for package {}".format(pkg_name))
return pkg_metadata_xml
package_condition_context = _package_condition_context(distro.name)
pkg = PackageMetadata(pkg_xml, evaluate_condition_context=package_condition_context)
pkg = PackageMetadata(pkg_xml,
evaluate_condition_context=package_condition_context)
pkg_metadata_xml.upstream_email = pkg.upstream_email
pkg_metadata_xml.upstream_name = pkg.upstream_name
pkg_metadata_xml.longdescription = pkg.longdescription
Expand All @@ -174,7 +175,9 @@ def _gen_ebuild_for_package(
pkg_ebuild.src_uri = pkg_rosinstall[0]['tar']['uri']
pkg_names = get_package_names(distro)
package_condition_context = _package_condition_context(distro.name)
pkg_dep_walker = DependencyWalker(distro, evaluate_condition_context=package_condition_context)
pkg_dep_walker = DependencyWalker(
distro,
evaluate_condition_context=package_condition_context)

pkg_buildtool_deps = pkg_dep_walker.get_depends(pkg_name, "buildtool")
pkg_build_deps = pkg_dep_walker.get_depends(pkg_name, "build")
Expand Down Expand Up @@ -209,7 +212,8 @@ def _gen_ebuild_for_package(
except Exception:
warn("fetch metadata for package {}".format(pkg_name))
return pkg_ebuild
pkg = PackageMetadata(pkg_xml, evaluate_condition_context=package_condition_context)
pkg = PackageMetadata(pkg_xml,
evaluate_condition_context=package_condition_context)
pkg_ebuild.upstream_license = pkg.upstream_license
pkg_ebuild.description = pkg.description
pkg_ebuild.homepage = pkg.homepage
Expand Down
4 changes: 2 additions & 2 deletions superflore/generators/ebuild/overlay_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def regenerate_manifests(
dock.map_directory(self.repo.repo_dir, '/tmp/ros-overlay')
for distro in regen_dict.keys():
chunk_list = []
chunk_count = 0
pkg_list = regen_dict[distro]
while len(pkg_list) > 0:
current_chunk = list()
Expand All @@ -96,7 +95,8 @@ def regenerate_manifests(
info("key_lists: '%s'" % chunk_list)
for chunk in chunk_list:
for pkg in chunk:
pkg_dir = '/tmp/ros-overlay/ros-{0}/{1}'.format(distro, pkg)
pkg_dir = '/tmp/ros-overlay/ros-{0}/{1}'.format(distro,
pkg)
dock.add_bash_command('cd {0}'.format(pkg_dir))
dock.add_bash_command('repoman manifest')
try:
Expand Down
3 changes: 3 additions & 0 deletions superflore/generators/nix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from superflore.generators.nix.run import main
if __name__ == '__main__':
main()
110 changes: 110 additions & 0 deletions superflore/generators/nix/gen_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
from typing import Dict, Iterable

from rosdistro import DistributionFile
from rosinstall_generator.distro import get_package_names
from superflore.exceptions import UnresolvedDependency
from superflore.generators.nix.nix_package import NixPackage
from superflore.generators.nix.nix_package_set import NixPackageSet
from superflore.utils import err
from superflore.utils import make_dir
from superflore.utils import ok
from superflore.utils import warn

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

_version_regex = re.compile(r"version\s*=\s*\"([^\"]*)\"")


def regenerate_pkg(overlay, pkg: str, distro: DistributionFile,
preserve_existing: bool, tar_dir: str,
sha256_cache: Dict[str, str]):
all_pkgs = set(get_package_names(distro)[0])

if pkg not in all_pkgs:
raise RuntimeError("Unknown package '{}'".format(pkg))

normalized_pkg = NixPackage.normalize_name(pkg)

package_dir = os.path.join(overlay.repo.repo_dir, 'distros', distro.name,
normalized_pkg)
package_file = os.path.join(package_dir, 'default.nix')
make_dir(package_dir)

# check for an existing package
existing = os.path.exists(package_file)
previous_version = None

if preserve_existing and existing:
ok("derivation for package '{}' up to date, skipping...".format(pkg))
return None, [], None

if existing:
with open(package_file, 'r') as f:
existing_derivation = f.read()
version_match = _version_regex.search(existing_derivation)
if version_match:
try:
previous_version = version_match.group(1)
except IndexError:
pass
if not previous_version:
warn("Failed to extract previous package version")

try:
current = NixPackage(pkg, distro, tar_dir, sha256_cache, all_pkgs)
except Exception as e:
err('Failed to generate derivation for package {}!'.format(pkg))
raise e

try:
derivation_text = current.derivation.get_text(org, org_license)
except UnresolvedDependency:
err("'Failed to resolve required dependencies for package {}!"
.format(pkg))
unresolved = current.unresolved_dependencies
for dep in unresolved:
err(" unresolved: \"{}\"".format(dep))
return None, unresolved, None
except Exception as e:
err('Failed to generate derivation for package {}!'.format(pkg))
raise e

ok("Successfully generated derivation for package '{}'.".format(pkg))
try:
with open('{0}'.format(package_file), "w") as recipe_file:
recipe_file.write(derivation_text)
except Exception as e:
err("Failed to write derivation to disk!")
raise e
return current, previous_version, normalized_pkg


def regenerate_pkg_set(overlay, distro_name: str, pkg_names: Iterable[str]):
distro_dir = os.path.join(overlay.repo.repo_dir, 'distros', distro_name)
overlay_file = os.path.join(distro_dir, 'generated.nix')
make_dir(distro_dir)

package_set = NixPackageSet(pkg_names)

try:
with open(overlay_file, "w") as recipe_file:
recipe_file.write(package_set.get_text(org, org_license))
except Exception as e:
err("Failed to write derivation to disk!")
raise e
Loading