Skip to content

build: Keep system headers out of the generated .dd files on gcc's continuation lines - #853

Merged
krlmlr merged 3 commits into
mainfrom
claude/dd-gcc-continuation
Nov 13, 2026
Merged

krlmlr merged 3 commits into
mainfrom
claude/dd-gcc-continuation

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

The filter that turns the compiler's dependency output into the checked-in src/*.dd files drops system headers only from lines indented by two spaces, which is how clang writes continuation lines. gcc indents them by one space, so a build with gcc kept absolute system header paths (and vendor/ and .. paths) in every regenerated .dd file, and the CI step "Auto-update from GitHub Actions" then committed that bloat. The rule in src/Makevars.deps now first joins continuation lines of any indentation into one line, and the existing splitting and filtering run on the result, so both compilers give the same files. It is the same fix as commit 95de00b of the old Arrow stack, without the regenerated .dd files, because on main the checked-in files are already clean.

This fixes only part of #836, so it does not close it. The issue also asks to keep vendor/extensions/ dependencies in the .dd files so that an incremental build notices edits to the bundled extensions, and the filter still drops every vendor path by design. That needs a decision on which vendor paths to keep and a regeneration of the .dd files, and is left for a separate pull request. This one is the second checkbox of the issue.

Tested at main (3b7bea3) with gcc 13.3.0: touching all src/*.c and src/*.cpp files and running pkgbuild::compile_dll() regenerates the .dd files. Without the change, git status shows 26 modified .dd files, with about 13,500 added lines, 4,606 of them absolute /usr or /opt paths. With the change, the same rebuild leaves no .dd file modified. With clang (CC=clang, CXX=clang++) the same rebuild also leaves the .dd files unchanged. R CMD check --no-manual (without vignettes) passes with one NOTE about a hidden .git entry, which comes from building in a git worktree.

A second commit changes LOCALE=C sort in the same rule to LC_ALL=C sort, because sort ignores LOCALE, so under a locale such as en_US.UTF-8 a rebuild reordered the entries of 19 .dd files (39 lines); with it, rebuilds under en_US.UTF-8, de_CH.UTF-8 and C.UTF-8 all leave the .dd files unchanged.

A third commit, asked for by the maintainer, makes the rule resilient against CRLF line endings. A .d file with CRLF endings, as a compiler on Windows may write, left a \r before each line end, so the continuation-line join did not fire, the filter kept system headers, and stray \r bytes ended up in the generated .dd file. The rule now pipes the .d file through tr -d '\r' before the sed calls; \r is a POSIX escape for tr, so this works with GNU, BSD/macOS and Rtools' tr alike, whereas \r in a sed regular expression is a GNU extension that BSD sed reads as a literal r. Tested by running the rule (make on a wrapper Makefile including src/Makevars.deps) on hand-written gcc-style (one-space continuation lines) and clang-style (two-space) .d files with absolute system headers, vendor and .. paths, each with LF and with CRLF endings: with the change, CRLF and LF give byte-identical .dd files with LF endings, no \r and no absolute paths, and the LF output is byte-identical to that of the previous rule; before it, the CRLF output differed, carried \r bytes and kept a /usr path. A full R CMD INSTALL with gcc after touching all sources regenerated all 27 .dd files and left none modified.

The full CI matrix, dispatched by hand for 71d9fb8 (run 43414159767), passes on every job: Ubuntu x86 and ARM with R 4.2 to devel, macOS with R 4.5 and 4.6, and Windows x86 and ARM with R 4.5, 4.6 and devel. A dispatched run fails when the build changes a tracked file, so this also shows that no .dd file changes on any of these platforms.

The fix comes from the old Arrow stack (95de00b in #795); the plan to rework that stack splits it out as a separate pull request from main, since nothing else depends on it. Reviewed in a clean review, which found nothing above Low; see the accepted limitations.

https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE

https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn


Generated by Claude Code

…continuation lines

gcc wraps long dependency lists with a single leading space on continuation lines.
The filter in `src/Makevars.deps` only dropped lines starting with two spaces, which is clang's style, so absolute paths survived.
Join continuation lines of any indentation before splitting, so that every entry is normalised to the two-space form.
The absolute, Windows drive, `vendor` and `..` filters then apply on every line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE

krlmlr commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Review of this pull request at e71d033, by a Claude Code reviewer with clean context that read the description, the diff against main at 3b7bea3 (the rule in src/Makevars.deps and one comment), src/Makevars, R's .c.d and .cpp.d rules in the Unix and Windows Makeconf, Apple's sed sources, #836 and the experiment record from #849; built the pull request and its base in place with gcc and with clang, ran the test suite at both, ran R CMD check at the pull request, and ran reproducers of its own. I posted nothing myself.

What was run

  • At the pull request and at the base, once with gcc 13.3.0 and once with clang 18.1.3: every src/*.c and src/*.cpp touched, R CMD INSTALL in place, then git status and cmp of all 27 regenerated src/*.dd files against the checked-in ones.
  • The rule alone (make -f Makevars.deps x.dd), old and new, on 13 hand-written .d files and on the real g++ -M and clang++ -M output for cpp11.cpp; the new join step also under GNU sed --posix with POSIXLY_CORRECT=1, and the whole rule with a stand-in sed that rejects -r.
  • An incremental build: after a no-op build, a comment appended to affinity.h, DbColumnStorage.h and SqliteResultImpl.h in turn, each followed by a rebuild, then a rebuild after restoring it.
  • A regeneration of src/cpp11.dd under LC_ALL=en_US.UTF-8.
  • devtools::test() with NOT_CRAN=true at both commits; R CMD build --no-build-vignettes and R CMD check --no-manual --ignore-vignettes at the pull request. No test changed, so there was no test_that() block to run on its own.

What holds

  • The new src/Makevars.deps is byte-identical to the one at 95de00b, as the description says. No src/*.dd file changes, so none gains absolute paths.
  • At the base with gcc, 26 of the 27 files change, with 13,496 added lines, 4,606 of them under /usr or /opt (plus 438 under the library that holds cpp11's headers), as the description reports. At the base with clang, and at the pull request with either compiler, all 27 files come out byte-identical to the checked-in ones.
  • On the hand-written inputs the new rule gives the right list for gcc's one-space and clang's two-space continuation lines, dependencies on the first line, a target alone on its first line, a target with no dependencies or only its source, and a file without a trailing newline whether a local or a system header comes last. Where the old rule was right (clang style, no continuation lines) the output is unchanged; on gcc-style input the old rule kept /usr and vendor paths and mis-sorted entries that started a continuation line. The 711-line gcc output for cpp11.cpp takes 0.05 s.
  • Each header edit recompiled exactly the objects whose .dd file lists that header, and nothing else, and restoring the header did the same.
  • When the rule runs: only in a build from a checkout. .Rbuildignore drops src/Makevars.deps and src/*.dd (the built tarball holds only src/Makevars, and an empty Makevars.deps is made at install), so CRAN, R CMD check and tarball installs never run it. In a checkout, make remakes X.dd whenever X.c or X.cpp is newer, through R's .c.d or .cpp.d suffix rule to an intermediate X.d that it deletes afterwards, so no .d file has to exist beforehand: each build above logged 27 making X.d lines and left no .d file behind. Editing only a header regenerates nothing.
  • Platforms: the old rule already needed sed -r and \n in a replacement. By reading Apple's sources, its sed has both since text_cmds-106, the macOS 11 release; text_cmds-101 (macOS 10.15) rejects -r, and there, as the stand-in shows, the old and the new rule alike write a .dd file that stops make with "missing separator". The new join step needs only POSIX sed: each label ends with its -e, and N, \n in a regular expression and {} are POSIX. GNU sed --posix gives the same output on every input except a file whose last line ends in a backslash, which no compiler writes. Apple's parser (labels read to the end of the line, ; accepted after N and s, \n in a regular expression) accepts the same script (by reading). On Windows, R's Makeconf has the same suffix rules and Rtools ships MSYS2's GNU sed, so the join works; with CRLF input the join does not fire and the output equals the old rule's, so it is no worse (I could not check whether Rtools' gcc writes CRLF).
  • The tests give the same result at both commits: the three known test-httpvfs.R errors (test: Run the HTTP VFS tests for real, and make their errors fail the check #832, testthat hides a test's error when the test records another result after it #837), and "interrupt in busy handler", which loads the installed package and passes with the pull request's build on R_LIBS. R CMD check gives one NOTE, about the hidden .git entry of the worktree, as the description says.
  • The description matches the code, the title matches the scope, and the pull request leaves Incremental builds miss changes to bundled extensions under src/vendor/extensions/ #836 open for the vendor/extensions/ part.

High

None.

Medium

None.

Low

  1. The rewritten line still sorts in the caller's locale, so a regeneration reorders .dd files outside a C locale.
    sed -e ':a' -e '/\\$$/{N;s/ *\\\n */ /;ba' -e '}' $< | sed -r 's/([^ ]) ([^ \\])/\1 \\\n \2/g' | sed -r '/^ ([/]|[A-Za-z]:[/\\]|vendor|[.][.])/D;$$s/([^\\])$$/\1 \\/' | { echo "# Generated by Makevars.deps, do not edit by hand and do not add dependencies to system headers"; read -r header; printf '%s\n' "$$header"; LOCALE=C sort; echo " .Rconfig"; } > $@
    LOCALE=C sort sets a variable that sort does not read; collation comes from LC_ALL, LC_COLLATE or LANG. (Confirmed) At the pull request with gcc, touching src/cpp11.cpp and building under LC_ALL=en_US.UTF-8 rewrites src/cpp11.dd with cpp11.cpp first and SqliteResult.h after sqlite3-cpp.h; under C.UTF-8, as on CI, it does not. This predates the pull request, but it defeats its aim of a clean tree after a rebuild on machines with an English UTF-8 locale, as a typical macOS setup has. Suggested fix: LC_ALL=C sort in the same line, here or in a follow-up.

Generated by Claude Code

`LOCALE=C sort` sets a variable that `sort` ignores, so the order followed the caller's locale.
Under `en_US.UTF-8` a rebuild reordered the entries of 19 checked-in `.dd` files.
Use `LC_ALL=C`, so that the output is the same in every locale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE

krlmlr commented Nov 12, 2026 •

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review found nothing above Low; its one Low, LOCALE=C sort (which sort ignores, so a rebuild under en_US.UTF-8 reordered 19 .dd files), is fixed in fd43e3d with LC_ALL=C sort, checked under en_US.utf8, C.utf8 and de_CH.utf8. These remain:

  • src/Makevars.deps#L10: the filter still drops every vendor path, so an incremental build from a checkout does not notice an edit to a bundled extension under vendor/extensions/; that is the open part of Incremental builds miss changes to bundled extensions under src/vendor/extensions/ #836, which this pull request does not close. Relevance: low (developer builds only; .Rbuildignore keeps the rule out of the tarball); reviewer's confidence: high.
  • src/Makevars.deps#L10: like the old rule, the split step uses sed -r and \n in a replacement, which macOS's sed supports only from macOS 11; the new joining step is POSIX. On Windows, Rtools ships GNU sed; if Rtools' gcc writes CRLF line endings, the joining step leaves the lines as the old rule did. Checked by reading, not run. Relevance: low; reviewer's confidence: medium.

Generated by Claude Code

@krlmlr

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Make the sed calls resilient against CRLF.

A `.d` file with CRLF line endings, as a compiler on Windows may write,
left a `\r` before each line end,
so the continuation-line join did not fire,
the filter kept system headers,
and the `\r` ended up in the generated `.dd` file.
The rule now pipes the `.d` file through `tr -d '\r'` first,
which POSIX `tr`, BSD `tr` and GNU `tr` all accept,
so CRLF and LF input give the same `.dd` file with LF line endings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Review of the CRLF commit of this pull request, 71d9fb8, by a Claude Code reviewer with clean context that read the description of #853 and git diff fd43e3df 71d9fb81 (one recipe line and one comment in src/Makevars.deps), ran the old and new rule on hand-written and compiler-generated .d files with LF and CRLF endings, and ran a full R CMD INSTALL with gcc after touching all sources. I posted nothing on GitHub and changed no branch.

What was run

  • GNU make 4.3 with a wrapper Makefile that includes src/Makevars.deps from detached worktrees at fd43e3d and 71d9fb8, under the default /bin/sh (dash) and with SHELL=/bin/bash.
  • Test .d files: gcc-style (one-space continuation lines), clang-style (two-space), a Windows-style file with C:/…, C:\R\include\R.h, d:/… and an escaped-space path my\ dir/x.h, and a file whose last line has no newline. Each came with LF endings and with CRLF endings (\r on every line, including the unterminated last one).
  • A real g++ -MM output for DbConnection.cpp, as LF and as CRLF, compared with the checked-in src/DbConnection.dd.
  • touch src/*.c src/*.cpp, then R CMD INSTALL with ccache gcc 13 into a separate library, then git status.

What holds

  • For all four shapes, the CRLF output at 71d9fb8 is byte-identical to the LF output, with LF endings and no \r byte (Confirmed). At fd43e3d the CRLF output differed: it kept \r, failed to join continuation lines and kept /opt/R/include/R.h and ../inst/include/RSQLite.h (Confirmed).
  • The LF output at 71d9fb8 is byte-identical to that at fd43e3d for all four shapes (Confirmed). This is expected, because tr -d '\r' is a no-op on LF input and GNU sed gives the same result whether it reads a file or stdin.
  • The real g++ -MM output for DbConnection.cpp gives the same .dd file for LF and CRLF, identical to the checked-in file (Confirmed).
  • read -r header now sees no \r, because the \r is removed before the first sed. No other part of the rule is still sensitive to CRLF (Confirmed by the byte comparisons).
  • Quoting: make passes '\r' to the shell unchanged, because make expands only $. The single quotes hand tr the two characters \ and r, and \r is one of the escapes POSIX defines for tr. It worked in dash and bash (Confirmed). GNU coreutils tr, which Rtools/MSYS2 ships, and BSD tr on macOS both document \r (by reading; I did not run either platform). There is no Makevars.win, so Windows uses the same rule.
  • The full install with gcc regenerated all 27 .dd files and left git status clean, so no file was modified and none gained an absolute path (Confirmed).
  • The description matches the diff. The new comment line explains the step.

High

None.

Medium

None.

Low

  1. Dependency paths with escaped spaces (\ ) are still split into two broken entries, before and after this commit. src/Makevars.deps#L11. my\ dir/x.h comes out as my\ \ and dir/x.h, identically for LF and CRLF and at fd43e3d (Confirmed). The splitting sed, s/([^ ]) ([^ \\])/…/, does not treat \ as part of a name. The commit did not introduce this, and no RSQLite source path has spaces today, so it does not block this commit. Suggested fix: none needed here. If such paths ever matter, protect \ in the splitting expression, for example by swapping it for a placeholder before the split and restoring it after.

Generated by Claude Code

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Question: should the .dd rule also work with macOS's sed before macOS 11?

Part of the second box of the earlier "Accepted limitations", which is unchecked. Its CRLF part is fixed in 71d9fb8, reviewed. Its other part remains: the split step of the rule (src/Makevars.deps#L11) uses sed -r and \n in a replacement, as the rule on main already does; macOS's sed supports both only from macOS 11 (2020). The rule only runs in developer builds from a checkout (.Rbuildignore keeps it out of the tarball).

  • Accept: developer builds need macOS 11 or later, as on main today (recommended)
  • Make the split step POSIX, e.g. with awk, in this pull request (about one line, plus a test against the current output)

Kirill decides. If nobody decides, the rule stays as it is, which is no worse than main.


Generated by Claude Code

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The first clean review found nothing above Low; its Low (LOCALE=C sort) is fixed in fd43e3d. The CRLF line endings asked for here are handled in 71d9fb8, whose clean review found nothing above Low: CRLF and LF .d files give byte-identical .dd files, the LF output is unchanged, and a full gcc build leaves every .dd file unmodified. The part of the earlier second box about macOS's sed before macOS 11 is now a question. These remain:

  • src/Makevars.deps#L11: the filter still drops every vendor path, so an incremental build from a checkout does not notice an edit to a bundled extension under vendor/extensions/; that is the open part of Incremental builds miss changes to bundled extensions under src/vendor/extensions/ #836, which this pull request does not close. Relevance: low (developer builds only); reviewer's confidence: high.
  • src/Makevars.deps#L11: a dependency path with an escaped space (my\ dir/x.h) is split into two broken entries, as on main; no path in RSQLite has a space. Relevance: low; reviewer's confidence: high.
  • tr -d '\r' was run with GNU tr under dash and bash; BSD tr (macOS) and Rtools' GNU tr document the same escape, checked by reading. Relevance: low; reviewer's confidence: medium.

Generated by Claude Code

@krlmlr

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Accepting macOS >= 11. Any changes needed for that?

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

No changes needed. The .dd rule lives in src/Makevars.deps, which .Rbuildignore keeps out of the tarball (an empty file takes its place, see src/Makevars), so users installing from CRAN or a built tarball never run it; only developer builds from a checkout do. Those already need macOS 11 or later on main, since the split step's sed -r and \n in a replacement are unchanged from main, and this pull request adds nothing that needs more (tr -d '\r' is POSIX). The accepted limitations stay as they are; the macOS question is settled by your tick.


Generated by Claude Code

@krlmlr
krlmlr merged commit 23943ac into main Nov 13, 2026
25 checks passed
@krlmlr
krlmlr deleted the claude/dd-gcc-continuation branch November 13, 2026 13:02
krlmlr pushed a commit that referenced this pull request Nov 13, 2026
Bring in #853 (gcc continuation lines in the generated `.dd` files)
and #869 (no query text or SQLite message as a `printf()` format, `fetch_blob()` guarded against `NULL`).

The conflict in `SqliteResultImpl::raise_sqlite_exception()` keeps this branch's
`throw std::runtime_error(sqlite3_errmsg(conn))`:
a failed prepare reaches R at cpp11's entry point like every other step error here,
and cpp11 passes the message through `"%s"`, so it is not a format string either.
The `.dd` files regenerated with the new `src/Makevars.deps` are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
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.

2 participants