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

Using directive to configure sources / source directories #934

Closed
romanowski opened this issue Apr 25, 2022 · 2 comments · Fixed by #1260
Closed

Using directive to configure sources / source directories #934

romanowski opened this issue Apr 25, 2022 · 2 comments · Fixed by #1260
Assignees
Labels
enhancement New feature or request UX

Comments

@romanowski
Copy link
Member

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

In some cases, one may want to configure sources to compile a given source within a source (e.g. script with she-bang or define a non-breakable dependency or to create sbt/mill like project).

Additionally, we should have a default file name (e.g. project.scala) that will be a recommended place to put most using directives (dependencies, etc). When no inputs are provided, scala-cli should assume this file is an input if present in CWD, so it would be possible to run scala-cli compile or scala-cli test for projects that wants to have more predefined structure (e.g. libraries)>

@lwronski
Copy link
Contributor

lwronski commented Jul 20, 2022

From version 0.1.10 it is available to define sources/sources in using directives with this syntax:

//> using file hello.sc

//> using files Utils.scala, Helper.scala …

Added in #1157

@wleczny
Copy link
Contributor

wleczny commented Aug 3, 2022

Suggested solution for configuration file

When running scala-cli with passed inputs, Scala CLI will work as follows:

  1. In the begging Scala CLI creates an empty list for found project.settings.scala files.

  2. Scala CLI looks for the project.settings.scala file for every passed input (in the same order in which inputs were passed):

    • If the project.settings.scala file is passed explicitly as a source, Scala CLI adds this file to the list.
    • If the input is a directory, Scala CLI looks for the project.settings.scala inside this directory. If the file is found, Scala CLI adds this file to the list.
  3. Scala CLI sets the root directory for the project:

    • If the list of found settings files is not empty, Scala CLI takes first one of them and sets its parent directory as the root directory. If more than one project.settings.scala file is found, Scala CLI raises the warning saying that more than one project.settings.scala file has been found and which one of them has been set as the project root directory.
    • If the list of found settings files is empty, Scala CLI sets the root directory based on the first file/directory input. If the input is a directory, it is set as the root directory for this build. If it is a file, Scala CLI sets its parent directory as the root directory. If more then one file/directory input has ben passed Scala CLI raises the warning saying which directory has been set as the project root directory.
    • If the list of found settings files is empty and no file/directory inputs have been passed, Scala CLI sets the cwd as the project root directory and raises the warning saying that cwd has been set as the project root directory.
  4. Scala CLI precesses all passed inputs.

Example

Let's say we have the following file structure:

project
│   project.settings.scala
│
└───dir1
│   │   file1.scala
│   │
│   └───dir2
│       │   project.settings.scala
│       │   file2.scala
│   
└───dir3
    │   project.settings.scala
    │   file3.scala

And user runs the following command:

project> scala-cli dir1/file1.scala dir1/dir2 dir3/project.settings.scala

Scala CLI will find 2 project.settings.scala files:

  • inside dir2, since this directory was passed as an input and it has project.settings.scala inside.
  • inside dir3, since dir3/project.settings.scala was passed explicitly as a source

dir1/dir2 was passed before dir3/project.settings.scala, so dir2 will be set as the root directory for this build.

Since more than one project.settings.scala has been found, Scala CLI will raise the warning saying that more than one project.settings.scala file has been found and dir1/dir2 has been set as the project root directory.

At the end Scala CLI will process all passed inputs.

@wleczny wleczny closed this as completed Aug 3, 2022
@wleczny wleczny reopened this Aug 3, 2022
@wleczny wleczny linked a pull request Aug 17, 2022 that will close this issue
@lwronski lwronski removed their assignment Aug 18, 2022
@tgodzik tgodzik moved this to Done in Scala CLI Board Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request UX
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants