Skip to content

fix: Ensure dart sdk path is found correctly from compiled code as well - #4480

Merged
nielsenko merged 2 commits into
serverpod:mainfrom
nielsenko:fix-install
Dec 19, 2025
Merged

nielsenko merged 2 commits into
serverpod:mainfrom
nielsenko:fix-install

Conversation

@nielsenko

@nielsenko nielsenko commented Dec 18, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Fix Dart SDK discovery for AOT-compiled serverpod CLI.

  • AnalysisContextCollection cannot auto-detect SDK when running as compiled executable
  • Add _findDartSdk() to explicitly locate SDK path
  • Try Platform.resolvedExecutable first (works when running via dart run)
  • Fall back to DART_SDK and FLUTTER_ROOT env vars
  • Final fallback: locate dart via PATH and resolve symlinks
  • Handles both pure Dart (sdk/bin/dart) and Flutter (flutter/bin/cache/dart-sdk) layouts

Fixes #4481

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else.
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

None.

Summary by CodeRabbit

  • Improvements
    • Enhanced Dart SDK detection in CLI analysis tools, now automatically resolving SDK paths from multiple sources across all supported platforms. The analyzer intelligently searches for SDK in environment variables, resolved executables, Flutter installations, and system PATH, improving cross-platform compatibility and tool initialization reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

@nielsenko nielsenko self-assigned this Dec 18, 2025
@nielsenko

Copy link
Copy Markdown
Collaborator Author

Tests will follow in #4475

@nielsenko
nielsenko requested a review from a team December 18, 2025 16:55
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 18, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Dec 18, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds dynamic Dart SDK discovery and validation to the endpoints analyzer by implementing multiple fallback strategies: resolving from the running dart executable, checking environment variables (DART_SDK, FLUTTER_ROOT), and searching PATH. These utilities enable analysis context initialization with an explicit SDK path to support installations via dart install.

Changes

Cohort / File(s) Summary
Dart SDK Discovery Enhancement
tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
Adds SDK path parameter to AnalysisContextCollection initialization. Implements _findDartSdk() to discover SDK via resolved executable, environment variables, and PATH lookup. Introduces _sdkPathFromDartExe() to derive SDK path from dart binary (handling Flutter/pure Dart variants) and _isValidSdk() to validate SDK presence via version file check.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Cross-platform SDK resolution logic: Verify correctness of Platform.resolvedExecutable usage, where/which command invocation, and symlink resolution across Windows and Unix-like systems
  • Fallback chain reliability: Ensure the sequence of SDK discovery attempts (executable → DART_SDK → FLUTTER_ROOT → PATH) covers all expected installation scenarios and edge cases
  • SDK validation: Confirm that version file existence check is a robust indicator of a valid SDK across Dart versions and installation types
  • Null handling: Verify existing behavior is preserved when no SDK is found (returning null leaves sdkPath unset)

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing Dart SDK path discovery to work correctly when the CLI is running as compiled code.
Description check ✅ Passed The description includes a clear explanation of the problem, solution details, the fixed issue number, and a completed pre-launch checklist with only one item unchecked (new tests).
Linked Issues check ✅ Passed The PR directly addresses issue #4481 by implementing dynamic Dart SDK discovery that allows the serverpod CLI to work correctly when installed as a compiled executable via dart install.
Out of Scope Changes check ✅ Passed All changes are scoped to the SDK discovery mechanism in endpoints_analyzer.dart, directly addressing the stated objective of fixing SDK detection for compiled executables.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bff7722 and aca308f.

📒 Files selected for processing (1)
  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.dart

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.dart: Follow Dart formatting conventions with dart format command
Run 'dart format .' to format all code before committing
Run 'melos lint_strict' or 'util/run_tests_analyze' to check code quality before committing, ensuring compliance with CI strict mode

Files:

  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
🧠 Learnings (2)
📓 Common learnings
Learnt from: tp
Repo: serverpod/serverpod PR: 3721
File: util/pub_get_all:0-0
Timestamp: 2025-06-27T08:39:36.440Z
Learning: In the Serverpod project, `dart pub get` commands work fine on Flutter packages both locally and in CI environments, even when the package has `flutter: sdk: flutter` dependencies in pubspec.yaml. The technical constraint of Flutter SDK dependencies causing `dart pub` failures may not apply in all environments or recent Dart versions.
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-11T03:56:54.151Z
Learning: Verify example projects still work before submitting PR by running example servers with 'dart bin/main.dart --apply-migrations'
📚 Learning: 2025-06-27T08:39:36.440Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3721
File: util/pub_get_all:0-0
Timestamp: 2025-06-27T08:39:36.440Z
Learning: In the Serverpod project, `dart pub get` commands work fine on Flutter packages both locally and in CI environments, even when the package has `flutter: sdk: flutter` dependencies in pubspec.yaml. The technical constraint of Flutter SDK dependencies causing `dart pub` failures may not apply in all environments or recent Dart versions.

Applied to files:

  • tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: Unit tests IO (3.32.0, windows-latest)
  • GitHub Check: Bootstrap tests (3.38.4, windows-latest, tests/bootstrap_project)
  • GitHub Check: Bootstrap tests (3.32.0, windows-latest, tests/bootstrap_project)
  • GitHub Check: Serverpod E2E web tests (3.32.0)
  • GitHub Check: Migration e2e tests (3.38.4)
  • GitHub Check: Bootstrap tests (3.38.4, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: Migration e2e tests (3.32.0)
  • GitHub Check: Serverpod E2E web tests (3.38.4)
  • GitHub Check: CLI e2e tests (3.32.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Bootstrap tests (3.32.0, ubuntu-latest, tests/bootstrap_project)
  • GitHub Check: CLI e2e tests (3.38.4, ubuntu-latest, tests/serverpod_cli_e2e_test)
  • GitHub Check: Serverpod integration tests (server) (3.32.0)
  • GitHub Check: Serverpod integration tests (server) (3.38.4)
  • GitHub Check: dart analyze (3.32.0, windows-latest)
  • GitHub Check: dart analyze downgrade (3.38.4, windows-latest)
  • GitHub Check: dart analyze downgrade (3.32.0, windows-latest)
🔇 Additional comments (3)
tools/serverpod_cli/lib/src/analyzer/dart/endpoints_analyzer.dart (3)

32-32: LGTM! Clean integration of SDK discovery.

The sdkPath parameter correctly uses the nullable return value from _findDartSdk(), allowing the analyzer to fall back to default SDK discovery when needed.


366-378: LGTM! Correct handling of Flutter and pure Dart SDK layouts.

The function properly:

  • Uses basenameWithoutExtension to handle dart.exe on Windows
  • Checks Flutter layout (bin/cache/dart-sdk) before pure Dart layout
  • Returns null when the executable isn't named 'dart' or SDK isn't found

380-380: SDK validation approach is sound and comprehensive.

The implementation correctly validates SDK existence by checking for the version file, which is a standard marker in all Dart SDK installations. The broader SDK discovery logic already handles cross-platform scenarios and multiple installation methods: it checks DART_SDK and FLUTTER_ROOT environment variables, falls back to PATH using platform-specific commands (which on Unix, where on Windows), resolves symlinks properly, and handles both Flutter-bundled and pure Dart installations. No further verification needed.

@nielsenko
nielsenko marked this pull request as ready for review December 18, 2025 17:04
@nielsenko

Copy link
Copy Markdown
Collaborator Author

Remember ..

Tests will follow in #4475

@SandPod SandPod 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.

Good catch 🧤 ⚾

@SandPod SandPod 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.

👍

@nielsenko
nielsenko merged commit dd6b58c into serverpod:main Dec 19, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serverpod don't work with dart install.

2 participants