Skip to content

feat(taskfiles): Add cmake-install-remote-tar; Fix optional lists to properly default to an empty list.#22

Merged
Bill-hbrhbr merged 6 commits into
y-scope:mainfrom
davidlion:cmake-download-func
Feb 13, 2025
Merged

feat(taskfiles): Add cmake-install-remote-tar; Fix optional lists to properly default to an empty list.#22
Bill-hbrhbr merged 6 commits into
y-scope:mainfrom
davidlion:cmake-download-func

Conversation

@davidlion

@davidlion davidlion commented Feb 12, 2025

Copy link
Copy Markdown
Member

Description

This PR adds a task that downloads a tar file containing a CMake project and then generates, builds, and installs the project. This task is useful when handling dependencies in C++ projects.
The original idea/design is from @Bill-hbrhbr.

Additionally, it adds small fixes to ensure optional list variables default to an empty list. This protects against the case where an optional list ends up defaulting to nil instead of [] by accident, which leads to an error from task/go.
Here is some pseudo code to help explain the issue:

install-my-dep:
  - cmds:
    - task: "utils:cmake-install-remote-tar"
      vars:
        GEN_ARGS: ['-DMSGPACK_CXX20="ON"']

cmake-install-remote-tar:
  - task: "cmake-generate"
    vars:
      EXTRA_ARGS:
        ref: .GEN_ARGS  // GEN_ARGS exist and has no issues
  - task: "cmake-build"
    vars:
      EXTRA_ARGS:
        ref: .BUILD_ARGS  // BUILD_ARGS doesn't exist and EXTRA_ARGS will ref nil

cmake-build:
  - cmds: >-
    {{- range .EXTRA_ARGS}}  // EXTRA_ARGS is nil and spits out an error

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

The new task was tested in ffi-go, but the list handling changes were also verified to cause no issues in clp.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a remote installation option that downloads, verifies, and installs CMake projects from tar archives.
  • Refactor
    • Enhanced variable handling across build, generate, install, and clean tasks for improved consistency.

@coderabbitai

coderabbitai Bot commented Feb 12, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@davidlion has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a109a0b and 22b89be.

📒 Files selected for processing (1)
  • taskfiles/utils-cmake.yaml (5 hunks)

Walkthrough

This pull request modifies the taskfiles/utils-cmake.yaml file. It updates the cmake-build, cmake-generate, and cmake-install tasks by introducing a new vars section that explicitly references default values for EXTRA_ARGS (and TARGETS where applicable). The cmake-clean task has a simplified reference to EXTRA_ARGS. A new task, cmake-install-remote-tar, has been added to download a remote CMake project tar file, generate the build system, build the project, and install it, with a dependency on the download-and-extract-tar task.

Changes

File Change Summary
taskfiles/utils-cmake.yaml • Updated cmake-build, cmake-generate, and cmake-install tasks by adding a vars section with default references for EXTRA_ARGS and TARGETS where applicable.
• Simplified the EXTRA_ARGS reference in the cmake-clean task.
• Added the cmake-install-remote-tar task to handle remote tar download, build generation, building, and installation.

Possibly related PRs

Suggested reviewers

  • kirkrodrigues

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
taskfiles/utils-cmake.yaml (1)

125-164: Consider adding URL validation and cleanup.

Two potential improvements:

  1. Add URL format validation before downloading
  2. Consider adding an optional cleanup step to remove temporary directories after installation

Example implementation for URL validation:

 cmake-install-remote-tar:
   internal: true
   label: "{{.TASK}}:{{.NAME}}-{{.URL}}-{{.INSTALL_PREFIX}}"
+  preconditions:
+    - sh: >-
+        [[ "{{.URL}}" =~ ^https?:// ]] || (echo "URL must start with http:// or https://" && exit 1)
+    - msg: "Invalid URL format"
   vars:
     BUILD_DIR: >-
       {{default (printf "%s/%s-build" .WORK_DIR .NAME) .BUILD_DIR}}

Would you like me to propose a complete implementation for the cleanup functionality as well?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ca3a56 and 654f01f.

📒 Files selected for processing (1)
  • taskfiles/utils-cmake.yaml (5 hunks)
🔇 Additional comments (2)
taskfiles/utils-cmake.yaml (2)

19-23: LGTM! Consistent handling of optional list variables.

The changes standardize how optional list variables are handled across all CMake tasks, ensuring they properly default to an empty list when not provided. The implementation is consistent and well-structured.

Also applies to: 51-52, 65-67, 89-91


103-124: LGTM! Well-documented and secure implementation.

The task is thoroughly documented and implements proper security measures by requiring SHA256 verification. The directory structure is logical, and the task effectively reuses existing functionality.

@Bill-hbrhbr Bill-hbrhbr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick scan through of the code.

Comment thread taskfiles/utils-cmake.yaml Outdated
WORK_DIR: >-
{{default .TASK_DIR .WORK_DIR}}
requires:
vars: ["NAME", "FILE_SHA256", "URL", "WORK_DIR"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think WORK_DIR is not required since it has a default value based on the task description

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I missed this when I made it optional.

Comment thread taskfiles/utils-cmake.yaml Outdated
Comment on lines +128 to +135
BUILD_DIR: >-
{{default (printf "%s/%s-build" .WORK_DIR .NAME) .BUILD_DIR}}
INSTALL_PREFIX: >-
{{default (printf "%s/%s-install" .WORK_DIR .NAME) .INSTALL_PREFIX}}
SOURCE_DIR: >-
{{default (printf "%s/%s-src" .WORK_DIR .NAME) .SOURCE_DIR}}
WORK_DIR: >-
{{default .TASK_DIR .WORK_DIR}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the order matters here when WORK_DIR is not specified and defaulted to TASK_DIR. Taskfile may treat WORK_DIR as an empty string when trying to assign default values to BUILD_DIR, INSTALL_PREFIX and SOURCE_DIR.
Taskfile is very weird in these situations.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let me check.

Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
# project. We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it
# should perform any actions. However, the download and extraction will be skipped if unnecessary.
#
# @param {string} NAME Project name used for directory names.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you change this to DEP or DEP_NAME it will keep the required args alphabetical with DEP* being the first arg.
But this is really unnecessary

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, the cmake project doesn't need to be a dependency so I think it is better to leave it as NAME.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
taskfiles/utils-cmake.yaml (1)

108-182: Consider adding validation and cleanup

The task implementation looks good, but consider these improvements:

  1. Add validation for the FILE_SHA256 format to prevent invalid hashes
  2. Consider adding an optional cleanup flag to remove temporary directories after successful installation

Would you like me to propose an implementation for these improvements?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b912171 and e8cb853.

📒 Files selected for processing (1)
  • taskfiles/utils-cmake.yaml (5 hunks)
🔇 Additional comments (4)
taskfiles/utils-cmake.yaml (4)

19-25: LGTM! Improved variable handling in cmake-build task

The addition of explicit variable defaults enhances reliability by ensuring proper initialization of optional parameters.


47-49: LGTM! Simplified variable handling in cmake-clean task

The changes maintain consistency with other tasks while reducing redundancy in variable references.

Also applies to: 57-57


70-72: LGTM! Enhanced variable handling in cmake-generate task

The addition of explicit variable defaults aligns with the improvements made to other tasks.


94-96: LGTM! Improved variable handling in cmake-install task

The changes maintain consistency with the variable handling improvements across all tasks.

Comment on lines +134 to +135
WORK_DIR: >-
{{default .ROOT_DIR .WORK_DIR}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix WORK_DIR default value

The default value uses .ROOT_DIR but the documentation states it should default to .TASK_DIR.

Apply this diff to fix the default value:

-        {{default .ROOT_DIR .WORK_DIR}}
+        {{default .TASK_DIR .WORK_DIR}}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
WORK_DIR: >-
{{default .ROOT_DIR .WORK_DIR}}
WORK_DIR: >-
{{default .TASK_DIR .WORK_DIR}}

Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Comment thread taskfiles/utils-cmake.yaml Outdated
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
taskfiles/utils-cmake.yaml (1)

134-135: ⚠️ Potential issue

Fix WORK_DIR default value.

The default value uses .ROOT_DIR but the documentation states it should default to .TASK_DIR.

Apply this diff to fix the default value:

-        {{default .ROOT_DIR .WORK_DIR}}
+        {{default .TASK_DIR .WORK_DIR}}
🧹 Nitpick comments (1)
taskfiles/utils-cmake.yaml (1)

130-130: Consider making this task public.

This task appears to be a utility for users to install CMake projects from remote tarballs. Consider removing the internal: true flag to make it accessible as a public utility.

Apply this diff:

-    internal: true
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8cb853 and a109a0b.

📒 Files selected for processing (1)
  • taskfiles/utils-cmake.yaml (5 hunks)
🔇 Additional comments (2)
taskfiles/utils-cmake.yaml (2)

19-25: LGTM! Improved handling of optional list arguments.

The changes enhance reliability by explicitly defaulting optional list arguments and using consistent reference syntax across all tasks.

Also applies to: 47-49, 70-72, 94-96


108-182: LGTM! Well-structured implementation.

The new task is well-designed with:

  • Clear separation of paths and optional arguments
  • Proper reuse of existing tasks
  • Thorough documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants