Skip to content

Explicit handling of paths in using directives #1098

Closed
@prolativ

Description

@prolativ

Is your feature request related to a problem? Please describe.

Some using directives take paths as arguments. These might be some directives specific to scala-cli itself or something that is passed further to some other tool (e.g. options passed to the compiler or a compiler plugin). When relative paths are used it might be unclear if the programmer's intent was to:

  1. pass the relative path unmodified to the underlying tool
    2a) treat the path as relative to the file in which the directive is located
    2b) treat the path as relative to the root of the build (e.g. foo/bar for scala-cli run foo/bar)
    2c) treat the path as relative to the current working directory (where scala-cli is run from)

Describe the solution you'd like
To avoid the confusion, file paths in using directives could be represented with some special syntax distinct from bare string literals. This would make it clear whether a user meant 1 or 2. Potentially a distinction between the subcases of 2 could be made if we find it useful to support all of them, although IMO it would be enough for most use cases to support only 2a.

Taking #1072 as an example, the problematic directive

//> using options  "-Ycheck:instrumentCoverage", "-coverage-out:.", "-sourceroot:."

could be replaced with something like

//> using options  "-Ycheck:instrumentCoverage", "-coverage-out:"${.}, "-sourceroot:"${.}

although I'm not insisting on ${...} as the proper syntax - this is just to show the concept.
Then ${.} would get substituted by scala-cli with the absolute path of the directory containing the file with the using directive (assuming we're considering 2a) and the option containing the absolute path would get passed to the compiler. Paths defined as quoted strings wouldn't be modified in any way.
The example also shows that we would need some way to concatenate the resolved paths with some string literals to form proper options for the compiler or some other tool.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions