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

collapse common logic into run-format formula #119

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

pjjw
Copy link
Contributor

@pjjw pjjw commented Jan 26, 2024

took a crack at parallelizing the formatter script, i think this works OK.


Type of change

  • New feature or functionality (change which adds functionality)
  • Performance (a code change that improves performance)

Test plan

  • Patched this into another repository where rules_lint is in use, kicked the tires, made sure output was the same, it ran faster, and deviations were caught.

@IamXander
Copy link

I would not call myself a bash expert by any means but if what you said in the title works this is an amazing change and I would love to see it merged.

@@ -45,7 +51,7 @@ function ls-files {
'SQL') patterns=('*.sql' '*.cql' '*.ddl' '*.inc' '*.mysql' '*.prc' '*.tab' '*.udf' '*.viw') ;;
'Scala') patterns=('*.scala' '*.kojo' '*.sbt' '*.sc') ;;
'Shell') patterns=('.bash_aliases' '.bash_functions' '.bash_history' '.bash_logout' '.bash_profile' '.bashrc' '.cshrc' '.flaskenv' '.kshrc' '.login' '.profile' '.zlogin' '.zlogout' '.zprofile' '.zshenv' '.zshrc' '9fs' 'PKGBUILD' 'bash_aliases' 'bash_logout' 'bash_profile' 'bashrc' 'cshrc' 'gradlew' 'kshrc' 'login' 'man' 'profile' 'zlogin' 'zlogout' 'zprofile' 'zshenv' 'zshrc' '*.sh' '*.bash' '*.bats' '*.cgi' '*.command' '*.fcgi' '*.ksh' '*.sh.in' '*.tmux' '*.tool' '*.trigger' '*.zsh' '*.zsh-theme') ;;
'Starlark') patterns=('BUCK' 'BUILD' 'BUILD.bazel' 'MODULE.bazel' 'Tiltfile' 'WORKSPACE' 'WORKSPACE.bazel' '*.bzl' '*.star') ;;
'Starlark') patterns=('BUCK' '**/BUCK' 'BUILD' '**/BUILD' 'BUILD.bazel' '**/BUILD.bazel' 'MODULE.bazel' 'Tiltfile' '**/Tiltfile' 'WORKSPACE' 'WORKSPACE.bazel' '*.bzl' '*.star') ;;

Choose a reason for hiding this comment

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

You will be able to get rid of the "**" and replace it with "*" once #124 lands for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the ** isn't to prevent the accidental glob expansion by bash addressed in #124 (that problem is fixed on line 71 by wrapping the pattern array expansion in quotes), but to get git ls-files to recurse in searches. there does appear to be some inconsistencies in pattern matching in git- this is what i found to work correctly.

@pjjw pjjw force-pushed the pjjw/parallel-format branch 6 times, most recently from 008c75e to 5720029 Compare January 31, 2024 18:47
@pjjw
Copy link
Contributor Author

pjjw commented Jan 31, 2024

updated to pass tests

@pjjw
Copy link
Contributor Author

pjjw commented Feb 6, 2024

@alexeagle got a moment to give this a once-over, or at least let me know if there's interest?

@alexeagle
Copy link
Member

Yes! sorry for the radio silence, this is indeed an important improvement.

How is the output handled? My biggest concern is that we shouldn't interleave outputs in a confusing way, rather each background job has to buffer and then we print the buffer after that job has completed.

Copy link
Member

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

pulled this down and tried it, and yeah the output is interleaved in a way that I don't think is desirable.

format/private/format.sh Show resolved Hide resolved
( echo "$files" | tr \\n \\0 | JAVA_RUNFILES="${RUNFILES_MANIFEST_FILE%_manifest}" xargs -0 "$bin" $args >&2 ; times ) | (read _ _ ; read tuser tsys; echo "Formatted ${lang} in ${tuser}" )
;;
Swift)
# for any linter that must be silenced
Copy link
Member

Choose a reason for hiding this comment

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

nit: linter -> formatter ?

format/private/format.sh Show resolved Hide resolved
done
fi
(
trap "kill 0" SIGINT
Copy link
Member

Choose a reason for hiding this comment

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

could we break this up into two PRs please?

Let's land the refactoring to introduce the run-lints function first, but not run them in parallel yet. That way you don't get stuck with any messy rebases while we figure out how to buffer the output properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have removed the parallelization for the moment. kind of nice how little difference there is.

@pjjw
Copy link
Contributor Author

pjjw commented Feb 6, 2024

got any suggestions as to how you'd like it to look?

@alexeagle
Copy link
Member

I think we can't print anything like "Formatting x with y..." because those will all appear at the top as the subshells are spawned in the background.

And when a tool completes I think we want to print the full buffer it produced.
I'll look around a bit for some example we can follow.

@alexeagle
Copy link
Member

Right, so the simple thing in Bash is to redirect the stdout/stderr of the individual tools to a file. Then when the tool is finished we can cat the file along with the line we print about what we ran and how long it took.

It's tempting to rewrite it in a language where there's a nice terminal experience available in some library, like superconsole. It would be a big effort though.

@alexeagle
Copy link
Member

sorry, merge conflicts now. would be nice to get the refactor in first :)

@pjjw
Copy link
Contributor Author

pjjw commented Feb 12, 2024 via email

@pjjw pjjw changed the title run formatters concurrently collapse common logic into run-format formula Feb 13, 2024
@pjjw pjjw force-pushed the pjjw/parallel-format branch 2 times, most recently from abafa1f to d00b0d8 Compare February 13, 2024 01:34
step on the road to parallelizing the formatters
@alexeagle alexeagle merged commit e9b90bd into aspect-build:main Feb 13, 2024
8 checks passed
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.

3 participants