-
Notifications
You must be signed in to change notification settings - Fork 28
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
Use Mutex to prevent simultaneous SCSS compilation for multi target projects #218
Conversation
Using a Mutex is only necessary for projects targeting multiple frameworks, in all other cases the compilation happens directly like before. Including the hashed arguments in the Mutex name makes sure the compilation for different projects (using different arguments) can still happen simultaneously.
Thanks a lot for your efforts. Looking good. I just think it would be safer to serialize only on the arguments and not bypass the mutex for single framework builds. |
Just to check are the arguments fully qualified paths? |
The Mutex should be used if a project targeting multiple frameworks is being built for a single framework due to it being a project reference of another project that is only targeting a single framework because |
Understood . But if For the record I totally understand you wanting to preserve the current code path for the majority of cases. I don't think a mutex is harmful though. It just means it's always thread safe in all scenarios. And lastly I really appreciate your efforts and time as I really didn't want to fork the project. It's not technically challenging but I would rather support the project in this repo. |
The reason I asked about whether the arguments being fully qualifies (path wise) was because it is conceivable that 2 projects use the same unqualified paths |
OK I traced the code back and the arguments do get fully qualified so the mutex should be different for different projects with the same |
So my only lasting comment is do we really need to restrict the mutex to |
Those are the arguments when compiling the SCSS for So as you found out already, everything is fully qualified. |
What is the benefit of using a Two examples:
One of the reason I was so reluctant to add a All in all I would suggest we proceed as follows: wait until this PR is merged and a new release of |
Obviously for us it would be a great addition since our contributors are reporting the occasional file lock which breaks the build. Yes, it does feel like a workaround. One I already used for over a year in our I understand skipping the Mutex for project without a However, until the day comes when it is an issue this PR LGTM. Thanks again for all your time on this. |
@@ -30,6 +32,10 @@ public string Snapshot | |||
|
|||
public string Configuration { get; set; } | |||
|
|||
public string TargetFramework { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now ...
<CompileSass AppsettingsFile="$(SassCompilerAppsettingsJson)" | ||
SassCompilerFile="$(SassCompilerSassCompilerJson)" | ||
Command="$(SassCompilerBuildCommand)" | ||
Snapshot="$(SassCompilerBuildSnapshot)" | ||
Configuration="$(SassCompilerConfiguration)"> | ||
Configuration="$(SassCompilerConfiguration)" | ||
TargetFramework="$(TargetFramework)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now ...
Sounds good to me. There is a PR pending to update dart-sass to 1.83.1, so we can merge that after this PR is merged to directly publish a new version. |
Looks good for merge 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work!
@adiessl After all the efforts I am sorry to report that after the mutex, it seems build order is sometimes affected for net8 net9. I think we also need an unconditional output for the Task. This is how it works in our |
@mikes-gh I'm sorry to hear that it still didn't fully solve the problem you're having. Based on what you described there is one thing that comes to my mind why it would only work for one of the target frameworks. To include the generated css files in the item group, the custom msbuild task returns the filenames that have been generated by dart-sass, by looking at the output of the sass command execution. This will be fine for whichever target frameworks is the first to acquire the mutex, but any after that won't actually generate new css files because the files that exist will be up to date. The problem is when a css file is already up to date, the sass executable doesn't log this, so in the second build we won't know which files would have been generated by the first build and thus can't update the item group respectively. The best solution for that would be if dart sass could log a message that the css file is already up to date, but last time I checked this didn't exist. Another solution, which feels more hacky, could be that we write out a list of files that were generated to a file before releasing the mutex in the first compilation, then after acquiring the mutex for the second target framework we read that file and add those files to the output of the task. |
@sleeuwen Thank you for the reply. Your thinking is along the same lines as me. Having something always in the output. I guess this is a limitation of dart-sass. In the case of a single file destination we could probably assume if the exit code of dart-sass is ok then the output would be the Destination in sasscompiler.json config. For folder to folder it might be more complex though. Generally, if the builds weren't running concurrently the content is picked up from the project directory anyway. Its only if the destination file doesn't exist when the compile statrts that we need to include it. |
I think it would be better if you opened a new issue regarding this matter, @mikes-gh. Ideally you would also include detailed information about the exact workflow that leads to the new problem you are facing (I am assuming you run A reason why the Sass executable does not return the already compiled files might be that the
Maybe not doing so would help? |
This is the third (and final) attempt to fix #209 (first attempt is #215, second is #217).
The other attempts have unfortunately shown that there are various problems when trying to compile SCSS files only once for multi target projects. Using a Mutex as @mikes-gh suggested to prevent simultaneous compilation for such projects seems to be the only viable option.
This PR wraps the SCSS compilation for projects targeting multiple frameworks with a Mutex to prevent simultaneous execution, in all other cases the compilation happens directly (without Mutex) like before.
Including the hashed arguments in the Mutex name makes sure the compilation for different projects (using different arguments) can still happen simultaneously.