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

Added support for skipping bicep build in MSBuild targets #11916

Merged
merged 3 commits into from
Sep 26, 2023

Conversation

majastrz
Copy link
Member

@majastrz majastrz commented Sep 23, 2023

The Incremental build logic in our MSBuild targets currently doesn't track references to modules, which means that we do not rebuild parent modules if only the child is modified.

The correct fix would be to allow the MSBuild targets to run the SourceFileGroupingBuilder to figure out the dependencies of each file. However, there are challenges with making Bicep.Core a dependency of our MSBuild task due to various issues with how MSBuild itself handles transitive task dependencies. Another option would be to call the Bicep CLI and have it return the list of dependencies for a file (could be a new verb). This would mean a process would need to be invoked every time the MSBuild project build is attempted, which defeats the point of incremental build. The startup overhead could be optimized away by wrapping it in a shared service instantiated by any concurrently running Bicep MSBuild tasks (Roslyn does it this way), but the solution is very expensive and not currently planned.

There is a much simpler option that will allow the users of our MSBuild task to unblock themselves by simply declaring the child modules in the Bicep project just like they do the parent modules. If building child modules is not desired, I've introduced a new NoBuild metadata to the Bicep item type that will cause us to skip bicep build for that file however we will still count the file as an input as far as MSBuild is concerned. This will allow MSBuild to build the parent modules even if only the child module changes. The credit for this idea goes to @abatishchev ❤️.

Microsoft Reviewers: Open in CodeFlow

@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 2023

Test this change out locally with the following install scripts (Action run 6316092085)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 6316092085
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 6316092085"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 6316092085
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 6316092085"

@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 2023

Test Results

     132 files  ±0       132 suites  ±0   3h 12m 19s ⏱️ - 7m 15s
10 553 tests ±0  10 553 ✔️ ±0  0 💤 ±0  0 ±0 
50 763 runs  ±0  50 763 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit f456f7f. ± Comparison against base commit 9a8ed5a.

♻️ This comment has been updated with latest results.

@abatishchev
Copy link

How would a working example look like? And I think the test are missing a case with two bicep files which must be compiled (or three, and one must be not)

@majastrz
Copy link
Member Author

How would a working example look like? And I think the test are missing a case with two bicep files which must be compiled (or three, and one must be not)

You just add NoBuild="true" metadata to any Bicep file that you don't want to build but still want to consider as input.

Good pt on adding a test with multiple files. Technically, the change relies only on item conditions so cardinality shouldn't matter, but I'll add one to be safe.

@abatishchev
Copy link

Awesome! Would there be a nightly build or a pre-release version me to try out?

@majastrz
Copy link
Member Author

Awesome! Would there be a nightly build or a pre-release version me to try out?

Yeah. Once it's merged, you can grab the built package from the main branch build. Until then, you'd have to pull my branch and dotnet pack the Bicep.MSBuild project to produce the NuGet package. (You'd just need the MSBuild one. It'll work with the official CLI NuGet package.)

@majastrz majastrz merged commit 4f24f39 into main Sep 26, 2023
47 checks passed
@majastrz majastrz deleted the majastrz/msbuild-dependencies branch September 26, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants