Skip to content

Conversation

NielsKSchjoedt
Copy link

@NielsKSchjoedt NielsKSchjoedt commented Sep 26, 2025

Summary

  • normalize ragel detection in ext/unicorn_http/extconf.rb so --with-ragel without a path falls back to PATH lookup

Testing

  • ruby ext/unicorn_http/extconf.rb

https://chatgpt.com/codex/tasks/task_b_68d6ee1a3904832aaef4059154f6bc2b

Summary by CodeRabbit

  • Documentation
    • Updated installation instructions to require Ragel for git-based installs.
    • Added steps to verify and regenerate the HTTP parser, with clearer error guidance if Ragel is missing.
  • Chores
    • Build now auto-generates the HTTP parser during native extension setup and fails fast with a helpful message when Ragel isn’t available, improving installation reliability and diagnostics.

Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

Adds Ragel dependency notes to README for git-based installs and documents regeneration of the HTTP parser. Updates ext/unicorn_http/extconf.rb to auto-generate unicorn_http.c via Ragel when missing, aborting if Ragel is unavailable. The new helper runs before makefile generation without altering existing feature checks.

Changes

Cohort / File(s) Summary
Docs: Install requirements and steps
README
Clarifies Ragel requirement for git installs, adds verification/regeneration instructions for ext/unicorn_http/unicorn_http.c, and notes error behavior if Ragel is missing.
Build: Ragel-based C source generation
ext/unicorn_http/extconf.rb
Adds generate_ragel_source to create unicorn_http.c with Ragel if absent; resolves Ragel path from config or PATH, runs generation with flags, and aborts on failures; invoked at top-level before existing checks.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Ruby as ruby ext/unicorn_http/extconf.rb
  participant Ext as extconf.rb
  participant FS as Filesystem
  participant Ragel as ragel

  Dev->>Ruby: Run extconf.rb
  Ruby->>Ext: Execute
  Ext->>FS: Check unicorn_http.c exists?
  alt C exists
    Ext-->>Ruby: Skip generation
  else C missing
    Ext->>Ext: Resolve ragel path (config or PATH)
    alt Ragel found
      Ext->>Ragel: Generate unicorn_http.c (-G2 -T0 ...)
      Ragel-->>Ext: Exit status
      alt Success
        Ext->>FS: Write unicorn_http.c
      else Failure
        Ext-->>Ruby: abort("ragel failed")
      end
    else Ragel missing
      Ext-->>Ruby: abort("ragel not found")
    end
  end
  Ruby-->>Dev: Continue makefile generation or abort
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws—new builds in sight,
Ragel rustles, lines take flight.
A C file sprouts where none had grown,
extconf checks, then carves the stone.
Docs now whisper, “Bring your gear.”
Hippity-hop—clean compile, clear! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change in the pull request by indicating that ragel configuration handling is being normalized within the extconf script. It directly reflects the core update to how the build script locates or applies the Ragel tool without including extraneous details. This phrasing is specific enough for readers to understand the main purpose at a glance.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-deployment-errors-with-unicorn-gem-fork-9ygk38

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

Copy link

@coderabbitai coderabbitai bot left a comment

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 (4)
ext/unicorn_http/extconf.rb (3)

9-16: Handle dir/relative values and validate executability for --with-ragel

If users pass a directory (e.g., --with-ragel=/usr/local/bin) or a non-absolute/relative path, we should resolve it and ensure it’s an executable. This also tightens validation before falling back to PATH.

Apply this diff:

   ragel_cfg = with_config('ragel') { find_executable('ragel') }
   ragel = if ragel_cfg.respond_to?(:strip)
     ragel_cfg = ragel_cfg.strip
     ragel_cfg unless ragel_cfg.empty? ||
                    (ragel_cfg.is_a?(String) && ragel_cfg !~ %r{\A/})
   end
-  ragel ||= find_executable('ragel')
+  # If a directory is provided, look for 'ragel' inside it
+  if ragel && File.directory?(ragel)
+    ragel = File.join(ragel, 'ragel')
+  end
+  # Only accept a real executable; otherwise fall back to PATH lookup
+  ragel = nil unless ragel && File.file?(ragel) && File.executable?(ragel)
+  ragel ||= find_executable('ragel')

5-8: Regenerate only when unicorn_http.c is missing or stale

Currently we skip regeneration if unicorn_http.c exists, even if unicorn_http.rl is newer. Consider basic mtime check to avoid stale parser sources.

 def generate_ragel_source
   src = File.expand_path('unicorn_http.c', __dir__)
-  return if File.exist?(src)
+  rl  = File.expand_path('unicorn_http.rl', __dir__)
+  return if File.exist?(src) && (!File.exist?(rl) || File.mtime(src) >= File.mtime(rl))

17-23: Augment error with a direct --with-ragel usage hint

Small UX improvement: tell users how to pass an absolute path/dir to ragel, in addition to gmake/package manager guidance.

   unless ragel
     abort <<~MSG
       ragel(1) is required to generate ext/unicorn_http/unicorn_http.c.

       Install ragel (e.g. via your package manager) or run `gmake ragel`
       from the repository root before installing unicorn from git.
+      Alternatively, point extconf at your ragel via:
+        ruby ext/unicorn_http/extconf.rb --with-ragel=/path/to/ragel
+        ruby ext/unicorn_http/extconf.rb --with-ragel=/path/to/bin
     MSG
   end
README (1)

94-100: Clarify regeneration behavior to avoid confusion

extconf regenerates only if the C source is missing (or stale, if we add the mtime check). Wording “will regenerate” may imply it always does. Suggest softening to “(re)generate if needed”.

-`ruby ext/unicorn_http/extconf.rb`, which will regenerate
-`ext/unicorn_http/unicorn_http.c` and report an error if Ragel is
-missing.
+`ruby ext/unicorn_http/extconf.rb`, which will (re)generate
+`ext/unicorn_http/unicorn_http.c` if needed and report an error if Ragel is
+missing.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7ddab3c and 6979c1b.

📒 Files selected for processing (2)
  • README (1 hunks)
  • ext/unicorn_http/extconf.rb (1 hunks)
🧰 Additional context used
🪛 RuboCop (1.80.2)
ext/unicorn_http/extconf.rb

[convention] 5-30: Cyclomatic complexity for generate_ragel_source is too high. [9/7]

(Metrics/CyclomaticComplexity)


[convention] 5-30: Perceived complexity for generate_ragel_source is too high. [9/8]

(Metrics/PerceivedComplexity)

🔇 Additional comments (1)
ext/unicorn_http/extconf.rb (1)

5-30: LGTM: PATH fallback when passing bare --with-ragel

The normalization works: boolean/empty --with-ragel falls back to PATH; absolute paths are honored; shell injection is avoided via system(*cmd).

Please verify the following manual scenarios:

  • No args (ragel in PATH): extconf generates when .c is missing.
  • --with-ragel (boolean): same as above (PATH lookup).
  • --with-ragel=/absolute/path/to/ragel: uses that binary.
  • --with-ragel=/some/bin (dir): after applying the suggested refactor, uses /some/bin/ragel.

@NielsKSchjoedt NielsKSchjoedt merged commit 305d45e into master Sep 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant