Skip to content

Conversation

@JordanMartinez
Copy link
Contributor

Description of the change

Fixes #4525.


Checklist:

  • Added a file to CHANGELOG.d for this PR (see CHANGELOG.d/README.md)
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@JordanMartinez JordanMartinez changed the title Jam/4525 globs file Add support for --source-globs CLI arg in purs compile Jan 23, 2024
@JordanMartinez
Copy link
Contributor Author

glob-test.sh outputs the following:

$ stack exec bash glob-test.sh 
env info
0.15.14 [development build; commit: e25c476c08c2e134f5d369326060be2f0d9ef583 DIRTY]
z
├── Foo.purs
├── globsAll
├── globsNoFoo
└── src
    ├── Bar
    │   └── Baz.purs
    └── Bar.purs

2 directories, 5 files
---
module Foo where
foo = 1 :: Int
---
module Bar where
bar = 1 :: Int
---
module Bar.Baz where
baz = 1 :: Int
---
Result
z/out1
├── Bar.Baz
│   ├── externs.cbor
│   └── index.js
├── cache-db.json
├── Foo
│   ├── externs.cbor
│   └── index.js
└── package.json

2 directories, 6 files
z/out2
├── Bar
│   ├── externs.cbor
│   └── index.js
├── Bar.Baz
│   ├── externs.cbor
│   └── index.js
├── cache-db.json
├── Foo
│   ├── externs.cbor
│   └── index.js
└── package.json

3 directories, 8 files
z/out3
├── Bar
│   ├── externs.cbor
│   └── index.js
├── Bar.Baz
│   ├── externs.cbor
│   └── index.js
├── cache-db.json
├── Foo
│   ├── externs.cbor
│   └── index.js
└── package.json

3 directories, 8 files
z/out4
├── Bar
│   ├── externs.cbor
│   └── index.js
├── Bar.Baz
│   ├── externs.cbor
│   └── index.js
├── cache-db.json
├── Foo
│   ├── externs.cbor
│   └── index.js
└── package.json

3 directories, 8 files
SOURCE_GLOBS output different from EXPECTED
Expected: purs compile: No files found using pattern: z/test/**/*.purs
[1 of 2] Compiling Bar.Baz
[2 of 2] Compiling Foo
SOURCE_GLOBS: purs compile: No files found using pattern: z/test/**/*.purs
[1 of 3] Compiling Foo
[2 of 3] Compiling Bar
[3 of 3] Compiling Bar.Baz

I tried this script on master and the EXPECTED globs also exclude the [2 of 3] Compiling Bar line. I think there's a bug in the glob handling.

@JordanMartinez
Copy link
Contributor Author

The above issue was due to z/src/**/*.purs being expanded by the shell to z/src/Bar/Baz.purs before the compiler ever received the glob. Wrapping that in single quotes disables that behavior, such that the compiler receives the full glob correctly.

@JordanMartinez
Copy link
Contributor Author

This PR is ready for an initial review now.

However, I noticed an issue somewhat related to this PR with how we produce our globs. In #4480, we added the option to exclude files from the initial set of files produced by the globs. However, this change was only done in the compile command. So, other commands that use globs like docs, graph, hierarchy, and repl don't support the exclude-files flag.

Moreover, should the format of the glob file added here also include some code for the excldue-files globs, such that one could write something like the following where lines prefixed with + act like our current input globs and - act like the exclude-files arg?

+ src/**/*.purs
- src/Spec/**/*.purs

@f-f
Copy link
Member

f-f commented Feb 2, 2024

Moreover, should the format of the glob file added here also include some code for the excldue-files globs, such that one could write something like the following where lines prefixed with + act like our current input globs and - act like the exclude-files arg?

I think we should ship the feature as implemented, and we can issue a future patch if there's the need for covering more scope. I don't think the exclude-files feature is in high usage at the moment.

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

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

The patch is good, but what about the glob-test.sh file? We should either use it from a test suite, or remove it since it will rot if not machine-checked regularly.

@JordanMartinez
Copy link
Contributor Author

The patch is good, but what about the glob-test.sh file? We should either use it from a test suite, or remove it since it will rot if not machine-checked regularly.

I've added it to our tests, but made it only run on Linux.

@JordanMartinez
Copy link
Contributor Author

However, I noticed an issue somewhat related to this PR with how we produce our globs. In #4480, we added the option to exclude files from the initial set of files produced by the globs. However, this change was only done in the compile command. So, other commands that use globs like docs, graph, hierarchy, and repl don't support the exclude-files flag.

I've updated this PR to also add --exclude-files and --source-globs to more commands.

@JordanMartinez
Copy link
Contributor Author

Now that CI builds, can this get another review due to adding both --source-globs and --exclude-files to the other commands?

@JordanMartinez
Copy link
Contributor Author

Anything else? Or is this good to merge?

Copy link
Member

@rhendric rhendric left a comment

Choose a reason for hiding this comment

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

Just a bunch of nits; merge once you've dealt with the ones you think are worth dealing with.

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

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

I left one nit in the changelog, but otherwise it's good to go - thanks @JordanMartinez!


In the command...
```
purs compile inputGlob1 inputGlob2 --source-globs-file inputGlobsFoundInFile --exclude-files excludeGlob1
Copy link
Member

Choose a reason for hiding this comment

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

(github suggestions break in the presence of ```, so I'll comment line by line)

This is a bit of a nit, but I would rephrase this slightly:

Suggested change
purs compile inputGlob1 inputGlob2 --source-globs-file inputGlobsFoundInFile --exclude-files excludeGlob1
purs compile inputGlob1 inputGlob2 --source-globs-file fileWithMoreGlobs --exclude-files excludeGlob1

In the command...
```
purs compile inputGlob1 inputGlob2 --source-globs-file inputGlobsFoundInFile --exclude-files excludeGlob1
``````
Copy link
Member

Choose a reason for hiding this comment

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

typo here?

There should be only three `

purs compile inputGlob1 inputGlob2 --source-globs-file inputGlobsFoundInFile --exclude-files excludeGlob1
``````
the files passed to the compiler are: all the files found by
`inputGlob1`, `inputGlob2`, and `inputGlobsFoundinFile`
Copy link
Member

Choose a reason for hiding this comment

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

(continued from above)

Suggested change
`inputGlob1`, `inputGlob2`, and `inputGlobsFoundinFile`
`inputGlob1`, `inputGlob2`, and all the globs listed in `fileWithMoreGlobs`,

@JordanMartinez
Copy link
Contributor Author

I left one nit in the changelog, but otherwise it's good to go.

Fixed!

@JordanMartinez JordanMartinez changed the title Add support for --source-globs CLI arg in purs compile Add support for --source-globs-file CLI arg in relevant purs commands Feb 7, 2024
@JordanMartinez JordanMartinez merged commit 5dcd000 into master Feb 7, 2024
@JordanMartinez JordanMartinez deleted the jam/4525-globs-file branch February 7, 2024 16:02
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.

Support --source-globs FILE argument due to Windows' cmd.exe character limitation

4 participants