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 component is executed twice when adding dependency with TryDependentFor #1000

Open
Sam13 opened this issue Aug 17, 2022 · 3 comments
Open

Comments

@Sam13
Copy link
Contributor

Sam13 commented Aug 17, 2022

Usage Information

Nuke v6.1.2, .NET SDK 6.0.400, .NET 6, all OS

Description

Given the following Nuke build:
https://github.com/Sam13/nuke-build-components-dependencies-investigation/blob/5d17ee622887607c41f694d3a2f4f9a4f0984b09/build/Build.cs

I have generic IRestore and ICompile components which have two different implementations each.
Considered the rare use case for which I want to execute both implementations for one build component (e.g. IRestore) the restore build component is executed twice when having a TryDependentFor to the other build component.

Nuke summary output:

═══════════════════════════════════════════════
Target                     Status      Duration
───────────────────────────────────────────────
Restore                    Succeeded     < 1sec
Restore                    Succeeded     < 1sec
AdditionalLegacyRestore    Succeeded     < 1sec
Compile                    Succeeded     < 1sec
───────────────────────────────────────────────
Total                                    < 1sec
═══════════════════════════════════════════════

Removal of TryDependentFor https://github.com/Sam13/nuke-build-components-dependencies-investigation/blob/5d17ee622887607c41f694d3a2f4f9a4f0984b09/build/Build.cs#L23 fixes the problem.
Also other declaration of build component interface implementations will fix the problem (see commits 68d969e22843171b4073d5cb359300e3844a62fe, 999f1e1ef70d61d16860f92cf04ed9e05d3290c9).

Is this a bug or incorrect usage of build components?

Reproduction Steps

Execute https://raw.githubusercontent.com/Sam13/nuke-build-components-dependencies-investigation/5d17ee622887607c41f694d3a2f4f9a4f0984b09/build/Build.cs

Expected Behavior

Build component Restore only executed once

Actual Behavior

Build component Restore executed twice (different implementations)

Regression?

Don't know

Known Workarounds

https://github.com/Sam13/nuke-build-components-dependencies-investigation/blob/68d969e22843171b4073d5cb359300e3844a62fe/build/Build.cs

or

https://github.com/Sam13/nuke-build-components-dependencies-investigation/blob/999f1e1ef70d61d16860f92cf04ed9e05d3290c9/build/Build.cs

@Sam13 Sam13 added the bug 🪲 label Aug 17, 2022
@ron-myers
Copy link

Hey @Sam13 - I haven't traced the issue but would propose you look at the Nuke build project and at the implementation in the Nuke.Components package for the patterns used there. And how the interplay of IRestore, ICompile(link) works

I see it as the intention for your restore case is to:

  • build your interface for your use case say IAdditionalLegacyRestore
  • have that interface inherit from IRestore
  • have that interface call DependsOn<Restore>()
  • include it in your project Build class inheritance list with any other components

If that interface isn't included in the Build class - it will not be included in the build. Which I think is the key overall approach to components.

Alternatively if it is more of a one off thing, think of your additional restore step as Clean is handled in the Nuke Build project.

I am on Discord if you want to DM me and discuss this more.

Not dismissing that this might be a bug - but pushing you towards the approach the library is using itself.

@Sam13
Copy link
Contributor Author

Sam13 commented Aug 18, 2022

Hello @ron-myers
Thanks for your help. I will definitely go through the documentation again.
I found this awkward behavior while implementing other more complicated build components and decided to create a reproducible example because this behavior seemed quite strange to me...

@Sam13
Copy link
Contributor Author

Sam13 commented Aug 23, 2022

Also happens with Nuke v6.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants