Skip to content

Commit

Permalink
chore: update mk_all script and use it in CI (#11849)
Browse files Browse the repository at this point in the history
Prompted by [this Zulip message](https://leanprover.zulipchat.com/#narrow/stream/116290-rss/topic/Recent.20Commits.20to.20mathlib4.3Amaster/near/430753770), I unified all the uses that I could find of "list all files in some dir and create an 'import file' for them".

In the process, I added a slight flexibility to the `mk_all` script: if you pass it a space-separated list of target dirs, it will produce 'import files' for each dir in the list.
  • Loading branch information
adomani authored and callesonne committed Jun 4, 2024
1 parent 0e249c5 commit 613a154
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 75 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,9 @@ jobs:
- uses: actions/checkout@v4

- name: update Mathlib.lean
run: |
git ls-files 'Mathlib/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
- name: update Mathlib/Tactic.lean
run: |
git ls-files 'Mathlib/Tactic/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib/Tactic.lean
- name: update Counterexamples.lean
run: |
git ls-files 'Counterexamples/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Counterexamples.lean
- name: update Archive.lean
- name: update import-only files in {Mathlib Mathlib/Tactic Counterexamples Archive}.lean
run: |
git ls-files 'Archive/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Archive.lean
./scripts/mk_all.sh
- name: check that all files are imported
run: git diff --exit-code
Expand Down Expand Up @@ -164,7 +152,7 @@ jobs:
# but verify that this didn't change anything in the `check_imported` job.
- name: update Mathlib.lean
run: |
find Mathlib -name "*.lean" | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
./scripts/mk_all.sh Mathlib
- name: If using a lean-pr-release toolchain, uninstall
run: |
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,9 @@ jobs:
- uses: actions/checkout@v4

- name: update Mathlib.lean
run: |
git ls-files 'Mathlib/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
- name: update Mathlib/Tactic.lean
run: |
git ls-files 'Mathlib/Tactic/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib/Tactic.lean
- name: update Counterexamples.lean
run: |
git ls-files 'Counterexamples/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Counterexamples.lean
- name: update Archive.lean
- name: update import-only files in {Mathlib Mathlib/Tactic Counterexamples Archive}.lean
run: |
git ls-files 'Archive/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Archive.lean
./scripts/mk_all.sh
- name: check that all files are imported
run: git diff --exit-code
Expand Down Expand Up @@ -171,7 +159,7 @@ jobs:
# but verify that this didn't change anything in the `check_imported` job.
- name: update Mathlib.lean
run: |
find Mathlib -name "*.lean" | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
./scripts/mk_all.sh Mathlib
- name: If using a lean-pr-release toolchain, uninstall
run: |
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/build.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,9 @@ jobs:

- uses: actions/checkout@v4

- name: update Mathlib.lean
run: |
git ls-files 'Mathlib/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean

- name: update Mathlib/Tactic.lean
run: |
git ls-files 'Mathlib/Tactic/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib/Tactic.lean

- name: update Counterexamples.lean
run: |
git ls-files 'Counterexamples/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Counterexamples.lean

- name: update Archive.lean
- name: update import-only files in {Mathlib Mathlib/Tactic Counterexamples Archive}.lean
run: |
git ls-files 'Archive/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Archive.lean
./scripts/mk_all.sh

- name: check that all files are imported
run: git diff --exit-code
Expand Down Expand Up @@ -150,7 +138,7 @@ jobs:
# but verify that this didn't change anything in the `check_imported` job.
- name: update Mathlib.lean
run: |
find Mathlib -name "*.lean" | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
./scripts/mk_all.sh Mathlib

- name: If using a lean-pr-release toolchain, uninstall
run: |
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/build_fork.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,9 @@ jobs:
- uses: actions/checkout@v4

- name: update Mathlib.lean
run: |
git ls-files 'Mathlib/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
- name: update Mathlib/Tactic.lean
run: |
git ls-files 'Mathlib/Tactic/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib/Tactic.lean
- name: update Counterexamples.lean
run: |
git ls-files 'Counterexamples/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Counterexamples.lean
- name: update Archive.lean
- name: update import-only files in {Mathlib Mathlib/Tactic Counterexamples Archive}.lean
run: |
git ls-files 'Archive/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Archive.lean
./scripts/mk_all.sh
- name: check that all files are imported
run: git diff --exit-code
Expand Down Expand Up @@ -168,7 +156,7 @@ jobs:
# but verify that this didn't change anything in the `check_imported` job.
- name: update Mathlib.lean
run: |
find Mathlib -name "*.lean" | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
./scripts/mk_all.sh Mathlib
- name: If using a lean-pr-release toolchain, uninstall
run: |
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/lint_and_suggest_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,9 @@ jobs:
- uses: actions/checkout@v4

- name: update Mathlib.lean
- name: import files in {Mathlib Mathlib/Tactic Counterexamples Archive}.lean
run: |
git ls-files 'Mathlib/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib.lean
- name: update Mathlib/Tactic.lean
run: |
git ls-files 'Mathlib/Tactic/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Mathlib/Tactic.lean
- name: update Counterexamples.lean
run: |
git ls-files 'Counterexamples/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Counterexamples.lean
- name: update Archive.lean
run: |
git ls-files 'Archive/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Archive.lean
./scripts/mk_all.sh
- name: suggester / import list
uses: reviewdog/action-suggester@v1
Expand Down
33 changes: 32 additions & 1 deletion scripts/mk_all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
#! /usr/bin/env bash

# Generate a file importing all the files of a Lean folder.
# By default, it generates the files for the libraries
# `Mathlib.lean`, `Mathlib/Tactic.lean`, `Archive.lean` and `Counterexamples.lean`.

## Standard use:
## ./scripts/mk_all.sh
##
## updates `Mathlib` `Mathlib/Tactic` `Counterexamples` `Archive`
##
## Advanced use:
## ./scripts/mk_all.sh <space_separated_list_of_dirs>
##
## for each dir in <space_separated_list_of_dirs>, create a file with all the imports of the dir
##
## The two commands
## ./scripts/mk_all.sh
## ./scripts/mk_all.sh Mathlib Mathlib/Tactic Counterexamples Archive
##
## are equivalent.

cd "$(git rev-parse --show-toplevel)" || exit 1
for gp in Mathlib Mathlib/Tactic Counterexamples Archive

# assign `targets` to be the input if provided, default to "the usual Mathlib suspects" otherwise
if [ -n "${*}" ]
then
targets=${*}
else
targets="Mathlib Mathlib/Tactic Counterexamples Archive"
fi

## Note: *no* quotes around `${targets}`, since we want the spaces to matter
for gp in ${targets}
do
git ls-files "$gp/*.lean" | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > "$gp.lean"
done

0 comments on commit 613a154

Please sign in to comment.