GithubHelp home page GithubHelp logo

Comments (6)

nightroman avatar nightroman commented on May 26, 2024

Looks like the conditional in task Build2 is evaluated before invoking task
Build1 even though Build2 depends on Build1. Is this by design?

Yes, this is by design that a condition is evaluated first, that is before
referenced tasks.

The whole idea is that if a condition evaluates to false then the task and
its references are not invoked.

Let's take a look at the similar MSBuild example:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Test" Condition="Exists ('z.tmp')" DependsOnTargets="Target1">
        <Message Text="In Test"/>
    </Target>
    <Target Name="Target1">
      <Message Text="In Target1"/>
      <Copy SourceFiles="z.txt" DestinationFiles="z.tmp"/>
    </Target>
</Project>

Example explained:

  • Test depends on Target1.
  • Target1 is supposed to create z.tmp.
  • Test is invoked only if z.tmp exists.
  • Deadlock...

That means MSBuild evaluates conditions before referenced targets.
And Invoke-Build evaluates conditions before referenced tasks.

from invoke-build.

nightroman avatar nightroman commented on May 26, 2024

All in all, I think we can close the issue.
UPDATE: see the next comment, though...

Could you describe your real case? I am sure we can find some suitable solution together.

A side note (ignore it if your choice is deliberate). Parameters Before and After are designed for special cases, normally when we cannot define references explicitly, e.g. for imported tasks. These parameters can be used in other cases, too, this is legit. I just think that scripts with excessive Before and After are rather difficult to understand.

from invoke-build.

nightroman avatar nightroman commented on May 26, 2024

I have just found some weird difference between MSBuild and Invoke-Build. But
even with this difference we can see that the condition is evaluated before
other tasks are invoked.

Example is similar to the above but instead of DependsOnTargets="Target1" on Test
we use BeforeTargets="Test" on Target1.

In Invoke-Build, such a swap makes no difference (except the order of some tasks).

In MSBuild, this swap makes Target1 invoked. But the condition is still checked before
and, as a result, the target Test is actually skipped.

Given we have z.txt and we do not have z.tmp in the script directory,
invoke this MSBuild script:

We can see

  • Target "Test" skipped, due to false condition.
  • We can see In Target1, it is invoked
  • We cannot see In Test, it is skipped, even though at this point its condition would get true.

In other words, in Invoke-Build (unlike in MSBuild) these two scripts are equivalent:

# script1
task Build1 {...}
task Build2 -If {...} Build1, {...}

# script2
task Build1 -Before Build2 {...}
task Build2 -If {...} {...}

This is by design and I think it is correct to keep it this way.
I will mention the difference at Comparison-with-MSBuild.

But even with this difference, both MSBuild and Invoke-Build evaluate
conditions before other involved tasks/targets.

from invoke-build.

nightroman avatar nightroman commented on May 26, 2024

To your example.

  1. Here it is (not working as we want):
    task buildA -before  BuildB,BuildC { $script:invokeBuildB = $true } # or $false
    task buildB -if {$script:invokeBuildB} -Before BuildD { }
    task buildC -if {!$script:invokeBuildB} -Before BuildD { }
    task BuildD { }
  1. It is identical to (still not working as we want)
    task buildA { $script:invokeBuildB = $true } # or $false
    task buildB -if {$script:invokeBuildB} buildA, { }
    task buildC -if {!$script:invokeBuildB} buildA, { }
    task buildD buildB, buildC, { }
  1. This works as we want
    task buildA { $script:invokeBuildB = $true } # or $false
    task buildB buildA, {
        if ($script:invokeBuildB) { } else { }
    }
    task buildD buildB, { }

If (3) is not suitable, please tell why and we will find something else.

In other words, as far as one and only one of the tasks B and C is invoked after A, then logically we do not have two tasks. We have one task "do A and process its results". That is what we do in (3).

from invoke-build.

kapilmb avatar kapilmb commented on May 26, 2024

@nightroman Thanks for the detailed explanation! I understand the rationale behind the behavior now. I was playing with invokebuild and was wondering about the situation for which I created the issue. As of now I do not have a concrete situation where I would need this. Thanks again!

from invoke-build.

nightroman avatar nightroman commented on May 26, 2024

@kapilmb No problem! It was useful to look at this again. In particular, a not yet known difference between MSBuild and IB was found. I documented it in Comparison-with-MSBuild. I do not know what scenarios are covered by MSBuild and how useful they are. The IB's way looks practical and convenient.

from invoke-build.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.