Skip to content

[release/10.0] tempDir: unbound variable at end of build #5403

Description

@omajid

Describe the Bug

When building .NET 10 on some not-so-recent Linux distributions (RHEL 8 and 9), I get this error:

         Copying file from "/dotnet/artifacts/staging/artifacts/assets/Release/Private.SourceBuilt.Artifacts.10.0.100-rtm.25523.111.rhel.9-x64.tar.gz" to "/dotnet/artifacts/assets/Release/Private.SourceBuilt.Artifacts.10.0.100-rtm.25523.111.rhel.9-x64.tar.gz".
    37>Done Building Project "/dotnet/.packages/BootstrapPackages/microsoft.dotnet.arcade.sdk/10.0.0-beta.25502.107/tools/Publish.proj" (Publish target(s)).
     1>Done Building Project "/dotnet/.packages/BootstrapPackages/microsoft.dotnet.arcade.sdk/10.0.0-beta.25502.107/tools/Build.proj" (default targets).
Build succeeded.
    0 Warning(s)
    0 Error(s)
Time Elapsed 00:32:40.26
/dotnet/eng/common/tools.sh: line 1: tempDir: unbound variable
+ exit_code=1
+ [[ 1 != 0 ]]
+ [[ 0 != 0 ]]
+ set -e
+ return 1

As you can see, the entire build is done at this point, even the PSB artifacts are produced and then the build fails.

tools.sh doesn't contain any use of tempDir, so the error seems surprising.

The culprit seems to be this trap use:

https://github.com/dotnet/dotnet/blob/8ebb400ec2c5327a543f9f5a08f6f7acedd0803c/eng/source-build-toolset-init.sh#L74

  local tempDir=""
...
      tempDir="$(mktemp -d)"
      trap 'rm -rf "${tempDir}"' EXIT

tempDir is a local variable, so it's probably not defined at the time this function has exited and trap is called when the build.sh is successful?

I am using this as a workaround before building:

sed -i -E 's/trap.*tempDir.*EXIT//' eng/source-build-toolset-init.sh

Steps to Reproduce

<TODO>

Other Information

Systems where I see this behaviour and build fails:

  • bash 4.4.20

Systems where build works:

  • bash 5.2.26
  • bash 5.3.0

Metadata

Metadata

Assignees

Labels

area-infraSource-build infrastructure and reporting

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions