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

Limit Task.Sources to only targeting subfolders of the enclosing module that are not in sub-modules #4447

Open
lihaoyi opened this issue Feb 1, 2025 · 2 comments
Milestone

Comments

@lihaoyi
Copy link
Member

lihaoyi commented Feb 1, 2025

This is a limitation that Bazel has, and it's worth considering if we should as well. There's some trickiness with things like cross modules that can share the millSourcePath, but overall I think we might be able to make it work.

@lihaoyi lihaoyi added this to the 0.13.0 milestone Feb 1, 2025
@lefou
Copy link
Member

lefou commented Feb 2, 2025

So, what we want here is a new exclude feature in PathRef?

@lihaoyi
Copy link
Member Author

lihaoyi commented Feb 2, 2025

@lefou no, what I mean is to make both of these fail

object foo extends Module{
  def bar = Task.Source(millSourcePath / "../bar")
}
object foo extends Module{
  object bar extends Module{}
  def qux = Task.Source(millSourcePath / "bar/qqux")
}

Both currently work: Task.Source can refer to anywhere and millSourcePath is just a helper, so you can refer to paths outside your millSourcePath (first example) and paths within a nested module's millSourcePath (second example). This ticket would be to make Task.Source only able to refer to things within its enclosing module and not within any child enclosing modules

@lihaoyi lihaoyi changed the title Limit Task.Sources to only watching subfolders of the enclosing module that are not in sub-modules Limit Task.Sources to only targeting subfolders of the enclosing module that are not in sub-modules Feb 6, 2025
lihaoyi added a commit that referenced this issue Feb 6, 2025
…bpath string literals (#4486)

First step in #4447, by
providing an alternative to the previous `os.Path` APIs.

Effectively this allows us to replace

```scala
def mainScript = Task.Source { millSourcePath / "src/foo.py" }
```

with

```scala
def mainScript = Task.Source { "src/foo.py" }
```

Pulls in com-lihaoyi/os-lib#353 from upstream to
make constructing `os.SubPath`s more ergonomic by eliding the lead
`os.sub /` prefix in the case of literal strings while still maintaining
a degree of safety:

* "outer" paths starting with `..`s and absolute paths starting with `/`
are rejected at compile time
* Only literal strings are converted implicitly, anything non-literal
needs to be an explicit `os.SubPath`


For now we provide this as an alternative to passing in an absolute
`os.Path`, but probably 99% of scenarios should be using this sub-path
API rather than absolute paths since (a) it's more concise and (b) your
sources should be within your `millSourcePath` anyway. I'm not sure we
can get rid of the `os.Path`-taking API entirely, but we can definitely
de-prioritize it and call it `SourcesUnsafe` or something so that anyone
who needs it can use it but most people won't use it accidentally
lihaoyi added a commit that referenced this issue Feb 6, 2025
…tly from subpath string literals (#4487)

First step in #4447, by
providing an alternative to the previous `os.Path` APIs.

Effectively this allows us to replace

```scala
def mainScript = Task.Source { millSourcePath / "src/foo.py" }
```

with

```scala
def mainScript = Task.Source { "src/foo.py" }
```

Pulls in com-lihaoyi/os-lib#353 from upstream to
make constructing `os.SubPath`s more ergonomic by eliding the lead
`os.sub /` prefix in the case of literal strings while still maintaining
a degree of safety:

* "outer" paths starting with `..`s and absolute paths starting with `/`
are rejected at compile time
* Only literal strings are converted implicitly, anything non-literal
needs to be an explicit `os.SubPath`


For now we provide this as an alternative to passing in an absolute
`os.Path`, but probably 99% of scenarios should be using this sub-path
API rather than absolute paths since (a) it's more concise and (b) your
sources should be within your `millSourcePath` anyway. I'm not sure we
can get rid of the `os.Path`-taking API entirely, but we can definitely
de-prioritize it and call it `SourcesUnsafe` or something so that anyone
who needs it can use it but most people won't use it accidentally
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

No branches or pull requests

2 participants