Improve argument name for per-package-src

Co-authored-by: Michal Sojka <michal.sojka@cvut.cz>
This commit is contained in:
Max Beutelspacher 2025-02-08 14:15:57 +01:00 committed by Michal Sojka
parent f2893e44b9
commit 3567e9e85a
2 changed files with 14 additions and 15 deletions

View file

@ -113,7 +113,7 @@ the [Autoware][] project as an example.
``` ```
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] [--use-package-git-hash] [--output-dir OUTPUT_DIR] [--fetch] [--use-per-package-src]
[--patches | --no-patches] [--distro DISTRO] [--patches | --no-patches] [--distro DISTRO]
[--src-param SRC_PARAM] [--source-root SOURCE_ROOT] [--src-param SRC_PARAM] [--source-root SOURCE_ROOT]
[--do-check] [--extra-build-inputs DEP1,DEP2,...] [--do-check] [--extra-build-inputs DEP1,DEP2,...]
@ -149,13 +149,12 @@ options:
determined from the local git work tree. sourceRoot determined from the local git work tree. sourceRoot
attribute is set if needed and not overridden by attribute is set if needed and not overridden by
--source-root. (default: False) --source-root. (default: False)
--use-package-git-hash --use-per-package-src
When using --fetch, use the git hash of the package When using --fetch, fetch only the package sub-
sub-directory instead of the one of the upstream directory instead of the whole repo. For repos with
repo.This will lead to longer generation time and multiple packages, this will avoid rebuilds of
multiple source checkouts when building but will safe unchanged packages at the cost of longer generation
rebuilds of packages that have not changed. (default: time. (default: False)
False)
--patches, --no-patches --patches, --no-patches
Add local git commits not present in git remote named Add local git commits not present in git remote named
"origin" to patches in the generated Nix expression. "origin" to patches in the generated Nix expression.

View file

@ -252,10 +252,10 @@ def ros2nix(args):
) )
parser.add_argument( parser.add_argument(
"--use-package-git-hash", "--use-per-package-src",
action="store_true", action="store_true",
help="When using --fetch, use the git hash of the package sub-directory instead of the one of the upstream repo." help="When using --fetch, fetch only the package sub-directory instead of the whole repo. "
"This will lead to longer generation time and multiple source checkouts when building but will safe rebuilds of packages that have not changed." "For repos with multiple packages, this will avoid rebuilds of unchanged packages at the cost of longer generation time."
) )
parser.add_argument( parser.add_argument(
"--patches", "--patches",
@ -412,12 +412,12 @@ def ros2nix(args):
def merge_base_to_upstream(commit: str) -> str: def merge_base_to_upstream(commit: str) -> str:
return subprocess.check_output(f"git merge-base {head} $(git for-each-ref refs/remotes/origin --format='%(objectname)')", cwd=srcdir,shell=True).decode().strip() return subprocess.check_output(f"git merge-base {head} $(git for-each-ref refs/remotes/origin --format='%(objectname)')", cwd=srcdir,shell=True).decode().strip()
if args.use_package_git_hash: if args.use_per_package_src:
# we need to get merge_base again to filter out applied patches from the package git hash # we need to get merge_base again to filter out applied patches from the package git hash
merge_base = merge_base_to_upstream(head) merge_base = merge_base_to_upstream(head)
head = check_output(f"git rev-list {merge_base} -1 -- .".split()) head = check_output(f"git rev-list {merge_base} -1 -- .".split())
if not args.use_package_git_hash and toplevel in git_cache: #only use cache if not using separate checkout per package if not args.use_per_package_src and toplevel in git_cache: # only use cache if not using separate checkout per package
info = git_cache[toplevel] info = git_cache[toplevel]
upstream_rev = info["rev"] upstream_rev = info["rev"]
else: else:
@ -431,7 +431,7 @@ def ros2nix(args):
["nix-prefetch-git", "--quiet"] ["nix-prefetch-git", "--quiet"]
+ ( + (
["--sparse-checkout", prefix] ["--sparse-checkout", prefix]
if prefix and args.use_package_git_hash if prefix and args.use_per_package_src
else [] else []
) )
+ [toplevel, upstream_rev], + [toplevel, upstream_rev],
@ -440,7 +440,7 @@ def ros2nix(args):
git_cache[toplevel] = info git_cache[toplevel] = info
match = re.match("https://github.com/(?P<owner>[^/]*)/(?P<repo>.*?)(.git|/.*)?$", url) match = re.match("https://github.com/(?P<owner>[^/]*)/(?P<repo>.*?)(.git|/.*)?$", url)
sparse_checkout = f"sparseCheckout = [\"{prefix}\"];" if (prefix and args.use_package_git_hash) else "" sparse_checkout = f"sparseCheckout = [\"{prefix}\"];" if (prefix and args.use_per_package_src) else ""
if match is not None: if match is not None:
kwargs["src_param"] = "fetchFromGitHub" kwargs["src_param"] = "fetchFromGitHub"
kwargs["src_expr"] = strip_empty_lines(dedent(f''' kwargs["src_expr"] = strip_empty_lines(dedent(f'''