Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test targets that depend on macros and swift-testing #7508

Merged

Conversation

grynspan
Copy link
Contributor

After #7353 landed, I noticed that the build products for test targets were not being emitted correctly. swift-testing and XCTest produce separate build products (with distinct names) but this wasn't happening as intended. It turns out that the changes to split buildParameters into productsBuildParameters and toolsBuildParameters weren't fully propagated to our testing infrastructure.

I also noticed SWIFT_PM_SUPPORTS_SWIFT_TESTING wasn't being set correctly anymore (same root cause) although we've decided to ignore that flag over in swift-testing anyway (see swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g. here) with the telltale failure signature:

/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests: /Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests: cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build product is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere in swift test and swift build that needs them and resolves the issue.

After #7353 landed, I noticed that the build products for test targets were not
being emitted correctly. swift-testing and XCTest produce separate build
products (with distinct names) but this wasn't happening as intended. It turns
out that the changes to split `buildParameters` into `productsBuildParameters`
and `toolsBuildParameters` weren't fully propagated to our testing
infrastructure.

I also noticed `SWIFT_PM_SUPPORTS_SWIFT_TESTING` wasn't being set correctly
anymore (same root cause) although we've decided to ignore that flag over in
swift-testing anyway (see swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g. [here](https://ci.swift.org/job/pr-swift-testing-macos/663/console))
with the telltale failure signature:

> /Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests: /Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests: cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build product
is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere in
`swift test` and `swift build` that needs them and resolves the issue.
@grynspan grynspan added bug cross-compilation build system Changes to interactions with build systems swift test Changes impacting `swift test` tool swift build Changes impacting `swift build` labels Apr 26, 2024
@grynspan grynspan self-assigned this Apr 26, 2024
@MaxDesiatov MaxDesiatov added the needs tests This change needs test coverage label Apr 26, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@MaxDesiatov MaxDesiatov changed the title Resolve an issue building test products. Fix test targets that depend on macros and swift-testing Apr 26, 2024
grynspan and others added 2 commits April 26, 2024 14:37
Co-authored-by: Max Desiatov <m_desiatov@apple.com>
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test Windows

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) April 26, 2024 18:55
@MaxDesiatov MaxDesiatov merged commit 5a4c024 into main Apr 26, 2024
4 of 5 checks passed
@MaxDesiatov MaxDesiatov deleted the jgrynspan/fix-test-products-with-cross-compilation-support branch April 26, 2024 21:15
furby-tm pushed a commit to wabiverse/swift-package-manager that referenced this pull request May 15, 2024
…#7508)

After swiftlang#7353 landed, I noticed that the build products for test targets
were not being emitted correctly. swift-testing and XCTest produce
separate build products (with distinct names) but this wasn't happening
as intended. It turns out that the changes to split `buildParameters`
into `productsBuildParameters` and `toolsBuildParameters` weren't fully
propagated to our testing infrastructure.

I also noticed `SWIFT_PM_SUPPORTS_SWIFT_TESTING` wasn't being set
correctly anymore (same root cause) although we've decided to ignore
that flag over in swift-testing anyway (see
swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g.
[here](https://ci.swift.org/job/pr-swift-testing-macos/663/console))
with the telltale failure signature:

>
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build
product is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere
in `swift test` and `swift build` that needs them and resolves the
issue.

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
grynspan added a commit that referenced this pull request May 15, 2024
After #7353 landed, I noticed that the build products for test targets
were not being emitted correctly. swift-testing and XCTest produce
separate build products (with distinct names) but this wasn't happening
as intended. It turns out that the changes to split `buildParameters`
into `productsBuildParameters` and `toolsBuildParameters` weren't fully
propagated to our testing infrastructure.

I also noticed `SWIFT_PM_SUPPORTS_SWIFT_TESTING` wasn't being set
correctly anymore (same root cause) although we've decided to ignore
that flag over in swift-testing anyway (see
swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g.
[here](https://ci.swift.org/job/pr-swift-testing-macos/663/console))
with the telltale failure signature:

>
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build
product is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere
in `swift test` and `swift build` that needs them and resolves the
issue.

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
grynspan added a commit that referenced this pull request May 15, 2024
Explanation: Add `--enable-code-coverage` to `swift build`. This flag
allows enabling code coverage when splitting a test run between `swift
build` and `swift test --skip-build`.
Scope: New option for the `swift build` command.
Original PR: #7508 (partial), #7518
Risk: Low. Behaviour is identical for `swift build` without the new
flag, and the new flag must be explicitly specified.
Testing: Ran `swift build` unit tests at desk and in CI.
Reviewer: @bnbarham, @MaxDesiatov, @stmontgomery

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
furby-tm pushed a commit to wabiverse/swift-package-manager that referenced this pull request May 15, 2024
…#7508)

After swiftlang#7353 landed, I noticed that the build products for test targets
were not being emitted correctly. swift-testing and XCTest produce
separate build products (with distinct names) but this wasn't happening
as intended. It turns out that the changes to split `buildParameters`
into `productsBuildParameters` and `toolsBuildParameters` weren't fully
propagated to our testing infrastructure.

I also noticed `SWIFT_PM_SUPPORTS_SWIFT_TESTING` wasn't being set
correctly anymore (same root cause) although we've decided to ignore
that flag over in swift-testing anyway (see
swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g.
[here](https://ci.swift.org/job/pr-swift-testing-macos/663/console))
with the telltale failure signature:

>
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build
product is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere
in `swift test` and `swift build` that needs them and resolves the
issue.

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
MaxDesiatov pushed a commit that referenced this pull request Jun 6, 2024
After #7353 landed, I noticed that the build products for test targets
were not being emitted correctly. swift-testing and XCTest produce
separate build products (with distinct names) but this wasn't happening
as intended. It turns out that the changes to split `buildParameters`
into `productsBuildParameters` and `toolsBuildParameters` weren't fully
propagated to our testing infrastructure.

I also noticed `SWIFT_PM_SUPPORTS_SWIFT_TESTING` wasn't being set
correctly anymore (same root cause) although we've decided to ignore
that flag over in swift-testing anyway (see
swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g.
[here](https://ci.swift.org/job/pr-swift-testing-macos/663/console))
with the telltale failure signature:

>
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build
product is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere
in `swift test` and `swift build` that needs them and resolves the
issue.

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
(cherry picked from commit 5a4c024)

# Conflicts:
#	Sources/Commands/SwiftBuildCommand.swift
#	Sources/Commands/SwiftTestCommand.swift
#	Sources/Commands/Utilities/TestingSupport.swift
xedin added a commit that referenced this pull request Jun 10, 2024
**Explanation**: Macros cross-compiled by SwiftPM with Swift SDKs should
be correctly built, loaded, and evaluated for the host triple.
**Scope**: isolated to modules dependency resolution and llbuild, does
not impact code related to XCBuild.
**Risk**: medium, known issues were addressed on `main` and are
cherry-picked here, with no new issues reported for a few weeks now.
**Testing**: added unit tests, manual end-to-end testing done with
existing Swift SDKs.
**Issue**: rdar://105991372
**Reviewers**: @bnbarham @xedin @neonichu

(cherry picked from commit cb3b085,
#7353)

```
# Conflicts:
#	CHANGELOG.md
#	Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift
#	Sources/Build/BuildManifest/LLBuildManifestBuilder.swift
#	Sources/Build/BuildPlan/BuildPlan.swift
#	Sources/Commands/SwiftTestCommand.swift
#	Sources/Commands/Utilities/PluginDelegate.swift
#	Sources/Commands/Utilities/TestingSupport.swift
#	Sources/PackageGraph/ModulesGraph+Loading.swift
#	Sources/PackageGraph/ModulesGraph.swift
#	Sources/SPMTestSupport/MockBuildTestHelper.swift
#	Sources/SPMTestSupport/MockPackageGraphs.swift
#	Sources/SPMTestSupport/PackageGraphTester.swift
#	Sources/SPMTestSupport/ResolvedTarget+Mock.swift
#	Tests/BuildTests/ClangTargetBuildDescriptionTests.swift
#	Tests/BuildTests/CrossCompilationBuildPlanTests.swift
#	Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift
```

(cherry picked from commit b9eb3c1,
#7493)

```
# Conflicts:
#	Sources/PackageGraph/ModulesGraph+Loading.swift
#	Sources/PackageGraph/Resolution/ResolvedPackage.swift
```
(cherry picked from commit 5a4c024,
#7508)

```
# Conflicts:
#	Sources/Commands/SwiftBuildCommand.swift
#	Sources/Commands/SwiftTestCommand.swift
#	Sources/Commands/Utilities/TestingSupport.swift
```

(cherry picked from commit 8db2401,
#7519)

```
# Conflicts:
#	Tests/BuildTests/CrossCompilationBuildPlanTests.swift
```

---------

Co-authored-by: Jonathan Grynspan <jgrynspan@apple.com>
Co-authored-by: Ben Barham <ben_barham@apple.com>
Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
Co-authored-by: Pavel Yaskevich <xedin@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build system Changes to interactions with build systems cross-compilation needs tests This change needs test coverage swift build Changes impacting `swift build` swift test Changes impacting `swift test` tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants