Implement --extra-*-inputs

This commit is contained in:
Michal Sojka 2024-09-15 17:47:35 +02:00
parent ac0a6f67bc
commit b36f2108fa
2 changed files with 44 additions and 7 deletions

View file

@ -12,7 +12,11 @@ reasonably well.
usage: ros2nix [-h] usage: ros2nix [-h]
[--output OUTPUT | --output-as-ros-pkg-name | --output-as-nix-pkg-name] [--output OUTPUT | --output-as-ros-pkg-name | --output-as-nix-pkg-name]
[--output-dir OUTPUT_DIR] [--fetch] [--distro DISTRO] [--output-dir OUTPUT_DIR] [--fetch] [--distro DISTRO]
[--src-param SRC_PARAM] [--source-root SOURCE_ROOT] [--flake] [--src-param SRC_PARAM] [--source-root SOURCE_ROOT]
[--extra-build-inputs DEP1,DEP2,...]
[--extra-propagated-build-inputs DEP1,DEP2,...]
[--extra-check-inputs DEP1,DEP2,...]
[--extra-native-build-inputs DEP1,DEP2,...] [--flake]
[--nixfmt] [--copyright-holder COPYRIGHT_HOLDER] [--nixfmt] [--copyright-holder COPYRIGHT_HOLDER]
[--license LICENSE] [--license LICENSE]
source [source ...] source [source ...]
@ -53,9 +57,21 @@ options:
Set sourceRoot attribute value in the generated Nix Set sourceRoot attribute value in the generated Nix
expression. Substring '{package_name}' gets replaced expression. Substring '{package_name}' gets replaced
with the package name. (default: None) with the package name. (default: None)
--extra-build-inputs DEP1,DEP2,...
Additional dependencies to add to the generated Nix
expressions (default: [])
--extra-propagated-build-inputs DEP1,DEP2,...
Additional dependencies to add to the generated Nix
expressions (default: [])
--extra-check-inputs DEP1,DEP2,...
Additional dependencies to add to the generated Nix
expressions (default: [])
--extra-native-build-inputs DEP1,DEP2,...
Additional dependencies to add to the generated Nix
expressions (default: [])
--flake Generate top-level flake.nix instead of default.nix. --flake Generate top-level flake.nix instead of default.nix.
Use with --fetch if some package.xml files are outside Use with --fetch if some package.xml files are outside
of the flake repo. (default: False) of the flake repo (default: False)
--nixfmt Format the resulting expressions with nixfmt (default: --nixfmt Format the resulting expressions with nixfmt (default:
False) False)
--copyright-holder COPYRIGHT_HOLDER --copyright-holder COPYRIGHT_HOLDER

View file

@ -150,6 +150,10 @@ def generate_flake(args):
''') ''')
def comma_separated(arg: str) -> list[str]:
return [i.strip() for i in arg.split(",")]
def ros2nix(args): def ros2nix(args):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog="ros2nix", formatter_class=argparse.ArgumentDefaultsHelpFormatter prog="ros2nix", formatter_class=argparse.ArgumentDefaultsHelpFormatter
@ -200,11 +204,28 @@ def ros2nix(args):
"Substring '{package_name}' gets replaced with the package name.", "Substring '{package_name}' gets replaced with the package name.",
) )
parser.add_argument(
"--extra-build-inputs", type=comma_separated, metavar="DEP1,DEP2,...", default=[],
help="Additional dependencies to add to the generated Nix expressions",
)
parser.add_argument(
"--extra-propagated-build-inputs", type=comma_separated, metavar="DEP1,DEP2,...", default=[],
help="Additional dependencies to add to the generated Nix expressions",
)
parser.add_argument(
"--extra-check-inputs", type=comma_separated, metavar="DEP1,DEP2,...", default=[],
help="Additional dependencies to add to the generated Nix expressions",
)
parser.add_argument(
"--extra-native-build-inputs", type=comma_separated, metavar="DEP1,DEP2,...", default=[],
help="Additional dependencies to add to the generated Nix expressions",
)
parser.add_argument( parser.add_argument(
"--flake", "--flake",
action="store_true", action="store_true",
help="Generate top-level flake.nix instead of default.nix. " help="Generate top-level flake.nix instead of default.nix. "
"Use with --fetch if some package.xml files are outside of the flake repo.", "Use with --fetch if some package.xml files are outside of the flake repo",
) )
parser.add_argument( parser.add_argument(
"--nixfmt", "--nixfmt",
@ -326,10 +347,10 @@ def ros2nix(args):
licenses=map(NixLicense, pkg.licenses), licenses=map(NixLicense, pkg.licenses),
distro_name=args.distro, distro_name=args.distro,
build_type=pkg.get_build_type(), build_type=pkg.get_build_type(),
build_inputs=build_inputs, build_inputs=build_inputs | set(args.extra_build_inputs),
propagated_build_inputs=propagated_build_inputs, propagated_build_inputs=propagated_build_inputs | set(args.extra_propagated_build_inputs),
check_inputs=check_inputs, check_inputs=check_inputs | set(args.extra_check_inputs),
native_build_inputs=native_build_inputs, native_build_inputs=native_build_inputs | set(args.extra_native_build_inputs),
**kwargs, **kwargs,
) )