Skip to content

Build Snap Package - #81

Merged
christianhelle merged 56 commits into
masterfrom
snap
May 11, 2025
Merged

christianhelle merged 56 commits into
masterfrom
snap

Conversation

@christianhelle

@christianhelle christianhelle commented May 10, 2025 •

Copy link
Copy Markdown
Owner

This pull request introduces support for building and packaging the SQLiteQueryAnalyzer as a Snap package for Linux, along with several related improvements to the build system and configuration files. The changes include updates to workflows, build scripts, and CMake configurations to ensure compatibility with Snapcraft and older Qt versions.

Snap Package Support and Workflow Enhancements:

  • Added Snapcraft configuration in src/project/snapcraft.yaml to define the Snap package metadata, dependencies, and build instructions.
  • Updated .github/workflows/linux-template.yml to include Snapcraft installation, build steps, and artifact publishing for Snap packages. [1] [2]
  • Modified .github/workflows/release.yml to upload Snap packages as release assets.

Build System Improvements:

  • Introduced build.sh as a cross-platform build script with support for Snap packaging and installation.
  • Enhanced build.ps1 to align Linux build steps with Snapcraft requirements and removed the Install switch. [1] [2]

CMake Configuration Updates:

  • Added support for setting a custom executable name via the EXECUTABLE_NAME parameter in CMakeLists.txt.
  • Implemented fallback logic in CMakeLists.txt to handle older Qt versions by replacing qt_add_executable and qt_standard_project_setup with manual configurations.
  • Updated installation and deployment targets in CMakeLists.txt to use the new APP_NAME variable.

Additional Improvements:

  • Created a desktop entry file (sqlitequery.desktop) for the Snap package to integrate with Linux desktop environments.
  • Adjusted the workflow trigger in .github/workflows/linux.yml to match multiple Linux workflow files.

Summary by CodeRabbit

  • New Features

    • Added Linux Snap packaging support with automated Snapcraft integration and Snap package upload in releases.
    • Introduced a new build script for Linux and macOS supporting packaging and installation options.
    • Added a Linux desktop entry for easy application launch and menu integration.
  • Chores

    • Updated build and workflow configurations to support multiple package formats and improved versioning.
    • Expanded .gitignore to exclude additional Linux build artifacts and distribution files.
  • Documentation

    • Included instructions for manual Snap package creation within the build script.

@christianhelle
christianhelle requested a review from Copilot May 10, 2025 20:28
@christianhelle christianhelle self-assigned this May 10, 2025
@christianhelle christianhelle added enhancement New feature or request build CI / CD labels May 10, 2025
@coderabbitai

coderabbitai Bot commented May 10, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

This update introduces Snapcraft packaging for the Linux version of the application, adds a Snapcraft configuration and desktop entry, and expands build scripts and workflows to support Snap package creation and artifact uploading. The CMake configuration and scripts are updated for flexible executable naming and improved compatibility, while .gitignore is extended to cover new build artifacts.

Changes

File(s) Change Summary
.github/workflows/linux-template.yml, .github/workflows/linux.yml, .github/workflows/release.yml Linux workflow template now updates the Snapcraft YAML, uses a relative install prefix, adds Snapcraft build and upload steps, and expands supported package formats. The workflow trigger pattern is broadened to match multiple Linux workflow files. The release workflow uploads the Snap package as a release asset.
.gitignore Ignores Linux-specific build artifacts and package formats, including Snap, DEB, RPM, various compressed archives, and installer executables, as well as Linux binary and resource directories.
src/project/CMakeLists.txt Adds configurable executable name via EXECUTABLE_NAME, conditionally uses qt_add_executable() or add_executable() for Qt version compatibility, and updates install and deployment commands to use the new variable.
src/project/build.ps1 Removes the $Install parameter, always installs on Linux after build, updates install prefix to relative path, and adds Snapcraft packaging step after CPack. Windows/macOS logic unchanged except for parameter removal.
src/project/build.sh New build script supporting --package and --install options, with OS-specific build and packaging logic. On Linux, Snap packaging is disabled by default but instructions for manual creation are provided. Supports multiple package formats and local installation.
src/project/linux/usr/share/applications/sqlitequery.desktop New desktop entry file for Linux, defining application metadata, icon, categories, and launch command for the application menu.
src/project/snapcraft.yaml New Snapcraft configuration for packaging the application as a Snap, specifying dependencies, desktop integration, and application metadata.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant CI as GitHub Actions CI
    participant Snapcraft as Snapcraft
    participant GHRelease as GitHub Release

    Dev->>CI: Push code or tag (with Snapcraft config)
    CI->>CI: Build Linux binaries (CMake, scripts)
    CI->>CI: Package with CPack (7Z, ZIP, DEB, RPM, etc.)
    CI->>Snapcraft: Build Snap package (snapcraft)
    CI->>CI: Collect artifacts (including .snap)
    CI->>GHRelease: Upload release assets (all packages, including Snap)
Loading

Possibly related PRs

  • christianhelle/sqlitequery#78: Introduced CPack packaging and CMake-based Linux builds, related as both PRs modify Linux build and packaging workflows.
  • christianhelle/sqlitequery#79: Added the Linux workflow template, which is further extended in this PR to support Snapcraft packaging and artifact uploads.

Poem

🐇
A Snap appeared upon the scene,
With scripts and YAML, crisp and clean.
Now Linux builds in many ways,
With CPack, Snap, and desktop praise.
Artifacts hop to the cloud with glee—
The rabbit’s work, for all to see!

"""

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

Copilot AI 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.

Pull Request Overview

This pull request introduces support for building and packaging the SQLiteQueryAnalyzer as a Snap package and includes several build system and configuration enhancements.

  • Added Snapcraft configuration and modifications to workflows for Snap package building and artifact publishing.
  • Introduced cross-platform build scripts with updated behavior for Linux and macOS builds.
  • Updated CMake configurations to support a custom executable name and fallback logic for older Qt versions.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/project/snapcraft.yaml New Snapcraft configuration file with package metadata and dependencies.
src/project/linux/usr/share/applications/sqlitequery.desktop Desktop entry file for Linux integration.
src/project/build.sh Bash build script updated for Snap packaging and installation steps.
src/project/build.ps1 PowerShell build script streamlined by removing the Install switch and integrating snapcraft.
src/project/CMakeLists.txt Updates to allow a custom executable name and to provide fallback logic for older Qt versions.
.github/workflows/release.yml Added step to upload the Snap package as a release asset.
.github/workflows/linux.yml Revised file path filters for workflow triggers.
.github/workflows/linux-template.yml Updated version replacements and added a Snapcraft step in the workflow.
Comments suppressed due to low confidence (1)

src/project/build.ps1:29

  • [nitpick] The removal of the '$Install' switch in favor of directly invoking 'snapcraft' may affect local installation workflows. Verify that this change aligns with the intended behavior for Linux environments.
snapcraft

Comment thread src/project/build.sh Outdated

@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: 4

🔭 Outside diff range comments (2)
src/project/CMakeLists.txt (2)

159-163: ⚠️ Potential issue

Fix hard-coded target name for widget linking.
The target_link_libraries call uses SQLiteQueryAnalyzer instead of ${APP_NAME}, breaking custom names. Update to:

if(QT_VERSION_MAJOR GREATER 4)
  target_link_libraries(${APP_NAME} PRIVATE Qt::Widgets)
endif()

165-168: ⚠️ Potential issue

Use ${APP_NAME} in install command.
The install(TARGETS ...) stanza still references SQLiteQueryAnalyzer directly. It must use ${APP_NAME}:

install(TARGETS ${APP_NAME}
  BUNDLE DESTINATION .
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
🧹 Nitpick comments (10)
src/project/build.ps1 (1)

35-39: Consider using relative path for macOS too

While the Linux section now uses a relative path for the install prefix, the macOS section still uses an absolute path. Consider using a relative path here as well for consistency.

-    cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/sqlitequery
+    cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./macos
src/project/linux/usr/share/applications/sqlitequery.desktop (2)

8-8: Review desktop file categories.
The Qt category is not part of the Freedesktop standard and may be ignored by some desktop environments. Consider using recognized categories like:
Categories=Development;Database;
or adding Utility if appropriate.


1-10: Enhance desktop integration with additional fields.
To improve user experience, consider adding:
• StartupNotify=true
• Placeholder %F for file opening, e.g. Exec=sqlitequery %F
• MimeType=application/x-sqlite3;
These can help with startup feedback and file associations.

src/project/CMakeLists.txt (3)

15-20: Use a cached CMake option for EXECUTABLE_NAME.
Instead of checking only if EXECUTABLE_NAME is defined, declare it as a cache variable with a default to expose it in GUIs and CLI:

set(EXECUTABLE_NAME "SQLiteQueryAnalyzer" CACHE STRING "Name of the application executable")
set(APP_NAME ${EXECUTABLE_NAME})

This documents the variable and makes overrides via -DEXECUTABLE_NAME more discoverable.


170-175: Group deploy script generation with target.
While qt_generate_deploy_app_script correctly references ${APP_NAME}, consider moving the install(SCRIPT ${deploy_script}) call immediately after script generation for clarity and logical grouping.


177-187: Parameterize CPack settings with ${APP_NAME}.
Hard-coding SQLiteQueryAnalyzer in CPACK_PACKAGE_NAME, CPACK_PACKAGE_INSTALL_DIRECTORY, etc., will desynchronize if the executable name changes. Use:

set(CPACK_PACKAGE_NAME ${APP_NAME})
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${APP_NAME})

and similar for maintainer fields if needed.

src/project/snapcraft.yaml (1)

7-7: Remove trailing whitespace.
YAML lint flags trailing spaces on lines 7 and 10. Please delete the extra spaces at end of these lines to satisfy linting.

Also applies to: 10-10

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 7-7: trailing spaces

(trailing-spaces)

src/project/build.sh (3)

45-55: DRY up repeated CPack invocations.
Multiple cpack -G <GEN> calls can be simplified:

for GEN in 7Z ZIP TBZ2 TGZ TXZ TZ DEB RPM; do
  cpack -G "$GEN" --config ./build/CPackConfig.cmake
done

57-102: Remove unreachable snap creation code.
The if true; then … else … fi always takes the first branch, making the alternative snap-setup path dead code. Clean up or drive this logic with an explicit flag.


109-112: Quote sysctl output to avoid word splitting.
ShellCheck (SC2046) warns about unquoted $(sysctl -n hw.ncpu). Change to:

-cmake --build build --config Release --parallel $(sysctl -n hw.ncpu)
+cmake --build build --config Release --parallel "$(sysctl -n hw.ncpu)"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 111-111: Quote this to prevent word splitting.

(SC2046)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b3225ed and d9d2be6.

⛔ Files ignored due to path filters (1)
  • src/project/linux/usr/share/icons/hicolor/256x256/apps/sqlitequery.png is excluded by !**/*.png
📒 Files selected for processing (9)
  • .github/workflows/linux-template.yml (3 hunks)
  • .github/workflows/linux.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .gitignore (1 hunks)
  • src/project/CMakeLists.txt (2 hunks)
  • src/project/build.ps1 (3 hunks)
  • src/project/build.sh (1 hunks)
  • src/project/linux/usr/share/applications/sqlitequery.desktop (1 hunks)
  • src/project/snapcraft.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
src/project/snapcraft.yaml

[error] 7-7: trailing spaces

(trailing-spaces)


[error] 10-10: trailing spaces

(trailing-spaces)

🪛 Shellcheck (0.10.0)
src/project/build.sh

[warning] 111-111: Quote this to prevent word splitting.

(SC2046)

🔇 Additional comments (15)
.gitignore (1)

49-63: LGTM! The gitignore additions are appropriate

The new entries correctly exclude the various Linux package formats and build artifacts that will be generated with the Snap packaging addition, including the Snap package file itself and all the supporting directories/files.

.github/workflows/release.yml (1)

134-142: Well-implemented upload step for Snap package

The new step follows the same pattern as the existing upload steps and correctly references the Snap package path using the appropriate naming convention.

.github/workflows/linux.yml (1)

8-8: LGTM! Workflow trigger pattern updated correctly

The wildcard pattern linux*.yml ensures that changes to any Linux-related workflow file (including the new template) will trigger the workflow.

.github/workflows/linux-template.yml (5)

27-28: Good version synchronization for snapcraft

Ensuring version consistency across all package definitions is important for proper release management.


40-42: Good change to use relative install path

Using a relative path (./linux) instead of an absolute path makes the build more portable and consistent across different environments.


45-55: LGTM! Well-structured packaging step

The renamed packaging step provides comprehensive package format support, which improves distribution options for Linux users.


57-64: Snapcraft integration looks good

The step properly installs the required snaps with appropriate permissions and sets the correct environment variable for host-based building.


71-72: Artifact path patterns correctly updated

The path patterns now include both the traditional package formats and the new Snap package format.

src/project/build.ps1 (3)

3-3: Simplifying parameter list is good

Removing the $Install switch simplifies the script interface while maintaining the necessary functionality.


16-18: Good updates to Linux build process

The changes to the Linux build section correctly use a relative path for installation and always perform the install step, which is required for packaging.


29-29: LGTM! Snapcraft integration added

Adding the snapcraft command to the package section ensures Snap packages are built alongside other formats.

src/project/linux/usr/share/applications/sqlitequery.desktop (1)

6-7: Validate Exec and Icon paths within snap environment.
The desktop entry uses Exec=sqlitequery, which must resolve to the snap app sqlitequery (not the raw binary). Ensure your snapcraft.yaml’s apps.sqlitequery.command aligns so that running sqlitequery in a terminal (or via the menu) invokes the correct binary inside the snap. Similarly, confirm that ${SNAP}/usr/share/icons/hicolor/256x256/apps/sqlitequery.png exists in the snap’s filesystem.

src/project/CMakeLists.txt (1)

26-29: Compatibility check for qt_standard_project_setup is sound.
Guarding qt_standard_project_setup() with if(COMMAND ...) ensures older Qt versions don’t break. The placement before executable creation is appropriate.

src/project/snapcraft.yaml (2)

25-28: Ensure desktop entry Exec matches snap app name.
Your apps.sqlitequery.command: bin/SQLiteQueryAnalyzer must align with the .desktop file’s Exec=sqlitequery. Verify that installing the snap exposes the sqlitequery command (an alias for the binary), so the desktop entry launches the correct app.


31-35: Verify source: linux directory exists and is populated.
The snapcraft.yaml part uses source: linux (local). Confirm that src/project/linux contains the built artifacts (binary, desktop file, icons) when Snapcraft runs, or adjust the path accordingly.

Comment thread src/project/CMakeLists.txt Outdated
Comment thread src/project/CMakeLists.txt
Comment thread src/project/build.sh Outdated
Comment thread src/project/build.sh Outdated
christianhelle and others added 2 commits May 11, 2025 09:51
Using 'if true;' to disable snap package creation is hard-coded and may be confusing for future maintenance. Consider using a feature flag or an environment-based check with a clear comment outlining that this is a temporary workaround.

Co-authored-by: Copilot <175728472+Copilot@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: 1

♻️ Duplicate comments (2)
src/project/build.sh (2)

32-37: ⚠️ Potential issue

Failing to build the Linux binaries: CMake commands are commented out
All core Linux build steps are disabled, so no artifacts will be produced. This is critical—uncomment or parameterize these lines to perform the actual build.

Proposed diff:

-    # cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./linux/
-    # cmake --build build --config Release --parallel $(nproc)
-    # cmake --install build
+    cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./linux/
+    cmake --build build --config Release --parallel "$(nproc)"
+    cmake --install build

Make sure $(nproc) is quoted to prevent word splitting.


38-43: ⚠️ Potential issue

Incorrect directory copying causes nested linux folder
Using cp -rf ./linux /tmp/sqlitequery will create /tmp/sqlitequery/linux/.... You likely intend to copy the contents of ./linux into /tmp/sqlitequery.

Suggested fix:

-        mkdir -p ~/.local/bin
-        cp -rf ./linux /tmp/sqlitequery
+        mkdir -p ~/.local/bin
+        rm -rf /tmp/sqlitequery
+        mkdir -p /tmp/sqlitequery
+        cp -r ./linux/* /tmp/sqlitequery/
         ln -sf /tmp/sqlitequery/bin/SQLiteQueryAnalyzer ~/.local/bin/sqlitequery
         echo "Installed to ~/.local/bin/sqlitequery"

Also quote paths if they may contain spaces.

🧹 Nitpick comments (5)
src/project/build.sh (5)

5-5: Enhance script robustness with strict mode
Currently only set -e is enabled. To catch unset variables and pipeline failures, consider adding set -o nounset -o pipefail.

 set -e
+set -o nounset -o pipefail

11-27: Improve POSIX-compliant argument parsing
Using while (( "$#" )); do relies on Bash arithmetic evaluation. For broader shell compatibility and clearer intent, consider:

-while (( "$#" )); do
+while [ "$#" -gt 0 ]; do
     case "$1" in
         --package)
             PACKAGE=true
             shift
             ;;
         --install)
             INSTALL=true
             shift
             ;;
         *)
             echo "Unknown argument: $1"
             echo "Usage: $0 [--package] [--install]"
             exit 1
             ;;
     esac
 done

This change avoids arithmetic context and makes the loop easier to read.


30-31: Normalize OS name to avoid case-sensitivity issues
OS=$(uname) may return different cases across platforms. Converting to lowercase ensures reliable comparisons:

-OS=$(uname)
+OS=$(uname | tr '[:upper:]' '[:lower:]')

Then compare against linux and darwin.


89-98: Duplicate “snap package creation is disabled” messaging in the else branch
The else block asserts the feature is disabled, yet this is the branch for when DISABLE_SNAP is not set. This is misleading.

Either remove the disabling message or repurpose this branch to perform the real snap build.


111-112: Quote command substitution to prevent word splitting (SC2046)
Unquoted $(sysctl -n hw.ncpu) may split unexpectedly if output contains whitespace.

-    cmake --build build --config Release --parallel $(sysctl -n hw.ncpu)
+    cmake --build build --config Release --parallel "$(sysctl -n hw.ncpu)"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 111-111: Quote this to prevent word splitting.

(SC2046)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9d2be6 and 8e96ba8.

📒 Files selected for processing (1)
  • src/project/build.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
src/project/build.sh

[warning] 111-111: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: macos-intel / template
  • GitHub Check: build / build
  • GitHub Check: build / template

Comment thread src/project/build.sh Outdated
cp -rf ./linux /tmp/sqlitequery will nest the linux folder inside
/tmp/sqlitequery
sing while (( "$#" )); do relies on Bash arithmetic evaluation. For
broader shell compatibility and clearer intent, consider:
Unquoted $(sysctl -n hw.ncpu) may split unexpectedly if output contains
whitespace.
The Qt category is not part of the Freedesktop standard and may be
ignored by some desktop environments
To improve user experience, consider adding:
• StartupNotify=true
• Placeholder %F for file opening, e.g. Exec=sqlitequery %F
• MimeType=application/x-sqlite3;
Multiple cpack -G <GEN> calls can be simplified

@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

♻️ Duplicate comments (2)
src/project/build.sh (2)

40-42: 🛠️ Refactor suggestion

Improve installation directory handling.

The current approach might not work correctly if target directories don't exist or if there's an existing file at the symlink location.

-    mkdir -p /tmp/sqlitequery
-    cp -rf ./linux/* /tmp/sqlitequery
-    ln -sf /tmp/sqlitequery/bin/SQLiteQueryAnalyzer ~/.local/bin/sqlitequery
+    rm -rf /tmp/sqlitequery
+    mkdir -p /tmp/sqlitequery
+    cp -rf ./linux/* /tmp/sqlitequery
+    # Remove existing symlink or file if it exists
+    rm -f ~/.local/bin/sqlitequery
+    ln -sf /tmp/sqlitequery/bin/SQLiteQueryAnalyzer ~/.local/bin/sqlitequery

52-91: 🛠️ Refactor suggestion

Clarify Snap package creation approach.

The script has two branches for Snap package handling but neither actually creates a Snap package, which is confusing. The messages themselves are clear, but the structure could be simplified.

Since both branches just provide instructions and don't build Snap packages, the environment variable check is unnecessary:

-    # Check if snap package creation is disabled via the DISABLE_SNAP environment variable
-    if [ "${DISABLE_SNAP}" = "true" ]; then
-      echo "Snap package creation is disabled (DISABLE_SNAP=true)."
-      echo "To create snap packages on a host system, use one of these approaches:"
-      echo ""
-      echo "Option 1: Use the snapcraft Docker image (recommended):"
-      echo "  docker run --rm -v \$(pwd):/build -w /build snapcore/snapcraft:stable snapcraft"
-      echo ""
-      echo "Option 2: On an Ubuntu host with snapd properly running:"
-      echo "  sudo snap install snapcraft --classic"
-      echo "  snapcraft"
-      echo ""
-    else
-      # For standard non-container environments
-      echo "Checking for snapcraft dependencies..."
-
-      # Check for snapd first
-      if ! command -v snap &>/dev/null; then
-        echo "Installing snap..."
-        sudo apt update
-        sudo apt install -y snapd
-        # Ensure snapd socket is available
-        if ! systemctl is-active snapd.socket &>/dev/null; then
-          echo "Starting snapd.socket..."
-          sudo systemctl start snapd.socket
-          sleep 2
-        fi
-      fi
-
-      echo "Snap package creation is disabled in this version of the build script."
-      echo "To create snap packages on a host system, use one of these approaches:"
-      echo ""
-      echo "Option 1: Use the snapcraft Docker image (recommended):"
-      echo "  docker run --rm -v \$(pwd):/build -w /build snapcore/snapcraft:stable snapcraft"
-      echo ""
-      echo "Option 2: On an Ubuntu host with snapd properly running:"
-      echo "  sudo snap install snapcraft --classic"
-      echo "  snapcraft"
-      echo ""
-    fi
+    echo "Snap package creation requires additional setup."
+    echo "To create snap packages on a host system, use one of these approaches:"
+    echo ""
+    echo "Option 1: Use the snapcraft Docker image (recommended):"
+    echo "  docker run --rm -v \$(pwd):/build -w /build snapcore/snapcraft:stable snapcraft"
+    echo ""
+    echo "Option 2: On an Ubuntu host with snapd properly running:"
+    echo "  sudo snap install snapcraft --classic"
+    echo "  snapcraft"
+    echo ""

Alternatively, if you want to enable actual Snap building in the future:

     # Check if snap package creation is disabled via the DISABLE_SNAP environment variable
     if [ "${DISABLE_SNAP}" = "true" ]; then
       echo "Snap package creation is disabled (DISABLE_SNAP=true)."
       echo "To create snap packages on a host system, use one of these approaches:"
       echo ""
       echo "Option 1: Use the snapcraft Docker image (recommended):"
       echo "  docker run --rm -v \$(pwd):/build -w /build snapcore/snapcraft:stable snapcraft"
       echo ""
       echo "Option 2: On an Ubuntu host with snapd properly running:"
       echo "  sudo snap install snapcraft --classic"
       echo "  snapcraft"
       echo ""
     else
       # For standard non-container environments
       echo "Checking for snapcraft dependencies..."

       # Check for snapd first
       if ! command -v snap &>/dev/null; then
         echo "Installing snap..."
         sudo apt update
         sudo apt install -y snapd
         # Ensure snapd socket is available
         if ! systemctl is-active snapd.socket &>/dev/null; then
           echo "Starting snapd.socket..."
           sudo systemctl start snapd.socket
           sleep 2
         fi
       fi

-      echo "Snap package creation is disabled in this version of the build script."
-      echo "To create snap packages on a host system, use one of these approaches:"
-      echo ""
-      echo "Option 1: Use the snapcraft Docker image (recommended):"
-      echo "  docker run --rm -v \$(pwd):/build -w /build snapcore/snapcraft:stable snapcraft"
-      echo ""
-      echo "Option 2: On an Ubuntu host with snapd properly running:"
-      echo "  sudo snap install snapcraft --classic"
-      echo "  snapcraft"
-      echo ""
+      # Install snapcraft if not available
+      if ! command -v snapcraft &>/dev/null; then
+        echo "Installing snapcraft..."
+        sudo snap install snapcraft --classic
+      fi
+      
+      echo "Building snap package..."
+      snapcraft
     fi
🧹 Nitpick comments (4)
src/project/build.ps1 (2)

33-40: Inconsistent conditional structure for macOS.

The macOS section uses a different conditional pattern than Windows and Linux sections.

-if ($IsMacOS -And $Package) {
+if ($IsMacOS) {
     cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/sqlitequery
     cmake --build build --config Release --parallel 32
     if ($Package) {
         macdeployqt build/SQLiteQueryAnalyzer.app -dmg -appstore-compliant
     }
 }

36-36: Standardize parallel build configuration.

Consider using a dynamic processor count for macOS as you did for Linux.

-    cmake --build build --config Release --parallel 32
+    cmake --build build --config Release --parallel $(sysctl -n hw.ncpu)
src/project/build.sh (2)

35-35: Fix potential word splitting in parallel build command.

The $(nproc) command output should be quoted to prevent word splitting issues.

-  cmake --build build --config Release --parallel $(nproc)
+  cmake --build build --config Release --parallel "$(nproc)"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 35-35: Quote this to prevent word splitting.

(SC2046)


32-107: Consider adding Windows support with cross-platform checks.

The script detects Linux and macOS but doesn't handle Windows. While this may be intentional for a bash script, consider adding a check for Windows with MSYS2/Git Bash environments.

 # Detect OS
 OS=$(uname)
+
+# Check for Windows with MSYS2/Git Bash
+if [[ "$OS" == MINGW* ]] || [[ "$OS" == CYGWIN* ]]; then
+  echo "This script is not designed for Windows. Please use build.ps1 instead."
+  exit 1
+fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 35-35: Quote this to prevent word splitting.

(SC2046)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e96ba8 and 4279095.

📒 Files selected for processing (4)
  • src/project/CMakeLists.txt (2 hunks)
  • src/project/build.ps1 (3 hunks)
  • src/project/build.sh (1 hunks)
  • src/project/linux/usr/share/applications/sqlitequery.desktop (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/project/linux/usr/share/applications/sqlitequery.desktop
  • src/project/CMakeLists.txt
🧰 Additional context used
🪛 Shellcheck (0.10.0)
src/project/build.sh

[warning] 35-35: Quote this to prevent word splitting.

(SC2046)

🔇 Additional comments (5)
src/project/build.ps1 (2)

3-3: Parameter simplification looks good.

Removing the $Install switch parameter and keeping only $Package streamlines the script interface.


16-18: Improvements to Linux build configuration.

The changes to use a relative install path and dynamic parallel build are good improvements:

  1. Using ./linux/ as the install prefix aligns with the new cross-platform build approach
  2. Using $(nproc) for parallelism ensures optimal performance across different Linux systems
  3. Unconditionally running the install step simplifies the workflow
src/project/build.sh (3)

1-31: Well-structured script initialization.

The script has a clean organization with proper error handling (set -e), clear argument parsing, and OS detection. The usage instructions are helpful for users.


48-50: Efficient package generation with loop.

Good use of a loop to generate multiple package formats efficiently.


100-100: Consistent quoting of command substitution.

Good use of quotes around the command substitution for macOS CPU count.

Comment thread src/project/build.ps1 Outdated
The script directly calls snapcraft without checking if it's installed,
which could cause build failures.
The current approach might not work correctly if target directories
don't exist or if there's an existing file at the symlink location.
The script detects Linux and macOS but doesn't handle Windows. While
this may be intentional for a bash script, consider adding a check for
Windows with MSYS2/Git Bash environments.
@sonarqubecloud

Copy link
Copy Markdown

@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 (2)
src/project/build.ps1 (1)

30-35: Well-implemented snapcraft availability check.

This is a good implementation of the snapcraft verification. The script now properly checks if snapcraft is available before attempting to run it and provides helpful messages for installation if it's missing.

src/project/build.sh (1)

60-102: ⚠️ Potential issue

Snap package creation is disabled in the script.

While the script has good handling for the DISABLE_SNAP environment variable, both branches explicitly disable actual Snap package creation. This contradicts the PR objective of adding Snap packaging support.

The script should actually invoke snapcraft in the else branch (line 89-98). Consider replacing:

-      echo "Snap package creation is disabled in this version of the build script."
-      echo "To create snap packages on a host system, use one of these approaches:"
-      echo ""
-      echo "Option 1: Use the snapcraft Docker image (recommended):"
-      echo "  docker run --rm -v \$(pwd):/build -w /build snapcore/snapcraft:stable snapcraft"
-      echo ""
-      echo "Option 2: On an Ubuntu host with snapd properly running:"
-      echo "  sudo snap install snapcraft --classic"
-      echo "  snapcraft"
-      echo ""
+      echo "Installing snapcraft and creating snap package..."
+      sudo snap install snapcraft --classic
+      snapcraft --destructive-mode

This change would align the script with the PowerShell version and the PR objectives.

🧹 Nitpick comments (1)
src/project/build.sh (1)

41-41: Fix potential word splitting issue.

The command substitution in the parallel flag should be quoted to prevent word splitting.

-  cmake --build build --config Release --parallel $(nproc)
+  cmake --build build --config Release --parallel "$(nproc)"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 41-41: Quote this to prevent word splitting.

(SC2046)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4279095 and 1109b3c.

📒 Files selected for processing (2)
  • src/project/build.ps1 (3 hunks)
  • src/project/build.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
src/project/build.sh

[warning] 41-41: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: macos-intel / template
  • GitHub Check: build / template
  • GitHub Check: build / build
🔇 Additional comments (4)
src/project/build.ps1 (1)

16-18: Good improvements to the Linux build configuration!

The changes to use a relative install prefix (./linux/) and dynamic CPU core detection ($(nproc)) make the build process more flexible and efficient. These modifications properly align with the Snap packaging requirements.

src/project/build.sh (3)

4-5: Good error handling setup.

Using set -e ensures the script will exit immediately if any command fails, which is a good practice for build scripts.


48-48: Installation directory copying looks correct.

The script now properly creates the destination directory before copying files, ensuring the files are copied correctly into /tmp/sqlitequery.


107-108: Good use of dynamic CPU detection on macOS.

Using $(sysctl -n hw.ncpu) to detect available CPU cores for parallelism is an excellent practice for optimizing build performance on macOS.

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

Labels

build CI / CD enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants