Skip to content

Create temporary directories lazily and do not exec single-task compilations when cleanup is required - #2237

Open
artemcm wants to merge 2 commits into
swiftlang:mainfrom
artemcm:LazyTempDir
Open

artemcm wants to merge 2 commits into
swiftlang:mainfrom
artemcm:LazyTempDir

Conversation

@artemcm

@artemcm artemcm commented Oct 20, 2026

Copy link
Copy Markdown
Contributor
  1. Create ArgsResolver's temporary directory lazily
    ArgsResolver created its default temporary directory on initialization, whether or not any job used it. When the driver execs a job in place, the process is replaced and the cleanup in Driver.run never runs, so every swiftc -print-target-info, -version, or single-job invocation left an empty temporary directory behind.
    Create the directory on first use instead: when a temporary path is resolved or a response file is written. A caller-supplied directory is still created eagerly.

  2. Don't exec a single job that leaves temporaries behind
    When the driver has a single job, it execs that job in place of itself and its temporary-directory cleanup never runs. A job that writes a file list or a response file therefore leaked its temporary directory.
    Port the legacy driver's check: exec only if the temporary directory doesn't exist yet and resolving the job won't create it, or if -save-temps keeps the files anyway. Otherwise run the job as a child process. Likewise don't exec when -driver-warn-unused-options is passed, since its warnings are printed after the job finishes.

Resolves #2049

ArgsResolver created its default temporary directory on initialization, whether or not any job used it. When the driver execs a job in place, the process is replaced and the cleanup in `Driver.run` never runs, so every `swiftc -print-target-info`, `-version`, or single-job invocation left an empty temporary directory behind.

Create the directory on first use instead: when a temporary path is resolved or a response file is written. A caller-supplied directory is still created eagerly.

Fixes swiftlang#2049
When the driver has a single job, it execs that job in place of itself and its temporary-directory cleanup never runs. A job that writes a file list or a response file therefore leaked its temporary directory.

Port the legacy driver's check: exec only if the temporary directory doesn't exist yet and resolving the job won't create it, or if `-save-temps` keeps the files anyway. Otherwise run the job as a child process. Likewise don't exec when `-driver-warn-unused-options` is passed, since its warnings are printed after the job finishes.

Fixes swiftlang#2049
@artemcm

artemcm commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@artemcm

artemcm commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci test Windows

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.

print-target-info: Temporary Directory isn't cleaned up on Linux/FreeBSD

2 participants