Skip to content

Input/output file environment variables are not exposed to build tool plugin commands #8916

Open
@evnik

Description

@evnik

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

  1. Create a package containing a build tool plugin.
  2. Return a buildCommand from the BuildToolPlugin.createBuildCommands(context:target:) implementation.
  3. Provide a non-empty list of inputFiles with the buildCommand.
  4. Build the package in Xcode 16.2 or earlier.
  5. In Xcode build log observe PhaseScriptExecution entry, which exports bunch of environment variables to the generated shell script, which also exposed to the invocation of executable passed to the buildCommand.
    Depending on the passed inputFiles/outputFiles arguments of the buildCommand, that might include SCRIPT_INPUT_FILE_COUNT, SCRIPT_INPUT_FILE_#, SCRIPT_OUTPUT_FILE_COUNT and SCRIPT_OUTPUT_FILE_# variables, so build command executable can also read those environment variables.
  6. If built in Xcode 16.4, a CustomTask entry could be found in build log, which doesn't generate a shell script and doesn't expose those environment variables.
  7. The same behavior is observed if built with SwiftPM CLI by running swift build or swift build --build-system=native.
  8. If built with swift build --build-system=xcode, build tool plugin seems to be not invoked at all.

Expected behavior

Xcode 16.4 and SwiftPM CLI allow to preserve behavior of Xcode 16.2 and earlier, exposing environment variables to build tool plugin commands

Actual behavior

No response

Steps to reproduce

  1. Clone https://github.com/evnik/PluginTest example project
  2. Run swift build in the project directory
  3. Observe Error: SCRIPT_INPUT_FILE_COUNT variable not set
  4. Run swift build --build-system=xcode in the project directory
  5. Observe Build succeeded
  6. Open and built the project in Xcode 16.2 or earlier.
  7. Observe build tool plugin is successfully invoked and produces the next SwiftLint error:
    <RedactedPath>/PluginTest/Sources/PluginTest/PluginTest.swift:2:9: error: Identifier Name Violation: Variable name 'i' should be between 3 and 40 characters long (identifier_name)
    

Swift Package Manager version/commit hash

6.1.0

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
Darwin m-tqvvvn2y4k 24.4.0 Darwin Kernel Version 24.4.0: Wed Mar 19 21:17:25 PDT 2025; root:xnu-11417.101.15~1/RELEASE_ARM64_T6020 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions