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

Build: avoid unnecessary warnings for build tool inputs #7300

Merged
merged 12 commits into from
Feb 5, 2024

Conversation

pusukuri
Copy link
Contributor

@pusukuri pusukuri commented Jan 26, 2024

Consider plugin build command input files into consideration and don't emit unnecessary warnings

Motivation:

Starting with 5.9 SwiftPM produces warnings for unhandled files but doesn’t take plugin build command input files into consideration. Consider plugin build command input files into consideration and don't emit unnecessary warnings.

Resolves rdar://113256834

@pusukuri
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov changed the title Consider plugin build command input files into consideration and don't emit unnecessary warnings rdar://113256834 Consider plugin build command input files and don't emit unnecessary warnings Jan 26, 2024
@MaxDesiatov MaxDesiatov changed the title Consider plugin build command input files and don't emit unnecessary warnings Build: Consider plugin build command input files, avoid unnecessary warnings Jan 26, 2024
@MaxDesiatov
Copy link
Member

@swift-ci test macos

@MaxDesiatov MaxDesiatov added bug plugins build system Changes to interactions with build systems labels Jan 26, 2024
@pusukuri
Copy link
Contributor Author

@swift-ci test macos

Copy link
Member

@neonichu neonichu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to expand the test case here to include a deliberately unhandled resource that we should continue to warn about, e.g. Fixtures/Miscellaneous/Plugins/MySourceGenPluginNoPreBuildCommands/Tests/MySourceGenPluginNoPreBuildCommandsTests/lunch.txt.

I'm seeing inconsistent behavior if I do this and I think that's related to the fact that if we are planning for plugins, we'll use a subset, but if we don't need to do that, we don't. We need to figure out how to solve that, likely this will involve not emitting the diagnostics as part of planning but at some other stage or it would involve changing how we do the build for executables needed for plugins.

@pusukuri
Copy link
Contributor Author

@swift-ci test

@pusukuri
Copy link
Contributor Author

pusukuri commented Jan 30, 2024

@neonichu: I have addressed your comment. Please take a look. Thank you.

@pusukuri
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov MaxDesiatov changed the title Build: Consider plugin build command input files, avoid unnecessary warnings Build: avoid unnecessary warnings for build tool inputs Feb 5, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How exactly does this fixture differ from other similar fixtures? I find that Sample source generator tool in main.swift has been copied over at least a few times in Fixtures/Miscellaneous/Plugins. Can we reduce that duplication? If not, I would love to see a README.md added to Fixtures/Miscellaneous/Plugins directory that describes available fixtures related to plugins and difference between them.

@@ -34,6 +34,15 @@ class PluginTests: XCTestCase {
}
}

func testUseOfBuildToolPluginTargetNoPreBuildCommandsByExecutableInSamePackage() throws {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is too long and difficult to read. Would we be able to come up with a more concise name that still uniquely identifies the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diagnosticsEmitter.emit(warning: warning)
// rdar://113256834 This fix works for the plugins that do not have PreBuildCommands.
let targetsToConsider: [ResolvedTarget]
if let subset = subset, let recursiveDependencies = try subset.recursiveDependencies(for: graph, observabilityScope: observabilityScope) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length nit. In the future, you can run ./Utilities/soundness.sh in the root of a SwiftPM clone before committing to fix these formatting issues automatically, which may require some final manual vetting and tweaking after that.

Suggested change
if let subset = subset, let recursiveDependencies = try subset.recursiveDependencies(for: graph, observabilityScope: observabilityScope) {
if let subset = subset, let recursiveDependencies = try subset.recursiveDependencies(
for: graph,
observabilityScope: observabilityScope
) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done @MaxDesiatov Thank you

@pusukuri
Copy link
Contributor Author

pusukuri commented Feb 5, 2024

@swift-ci test

metadata.targetName = target.name
return metadata
}
var warning = "found \(unhandledFiles.count) file(s) which are unhandled; explicitly declare them as resources or exclude from the target\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a multiline string work here? It would also make line length warnings for formatters and linters go away.

Suggested change
var warning = "found \(unhandledFiles.count) file(s) which are unhandled; explicitly declare them as resources or exclude from the target\n"
var warning = """
found \(unhandledFiles.count) file(s) which are unhandled; explicitly declare them \
as resources or exclude from the target\n
"""

@@ -782,6 +792,27 @@ extension BuildDescription {
}

extension BuildSubset {
func recursiveDependencies(for graph: PackageGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedTarget]? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func recursiveDependencies(for graph: PackageGraph, observabilityScope: ObservabilityScope) throws -> [ResolvedTarget]? {
func recursiveDependencies(
for graph: PackageGraph,
observabilityScope: ObservabilityScope
) throws -> [ResolvedTarget]? {

@@ -34,6 +34,15 @@ class PluginTests: XCTestCase {
}
}

func testUseOfBuildToolPluginTargetNoPreBuildCommands() throws {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func testUseOfBuildToolPluginTargetNoPreBuildCommands() throws {
func testBuildToolWithoutPreBuildCommands() throws {

@@ -34,6 +34,15 @@ class PluginTests: XCTestCase {
}
}

func testUseOfBuildToolPluginTargetNoPreBuildCommands() throws {
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
// Only run the test if the environment in which we're running actually supports Swift concurrency (which
// the plugin APIs require).

Copy link
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor line length nits remaining, probably ok to fix those in a separate formatter pass in other PR. LGTM

@pusukuri
Copy link
Contributor Author

pusukuri commented Feb 5, 2024

@swift-ci test windows

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 plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants