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

Add export --json option #1840

Merged
merged 5 commits into from
Feb 21, 2023

Conversation

MaciejG604
Copy link
Contributor

No description provided.

@MaciejG604 MaciejG604 requested a review from lwronski February 8, 2023 15:21
@MaciejG604 MaciejG604 self-assigned this Feb 8, 2023
@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch 2 times, most recently from 0d6f8c3 to f3a9b66 Compare February 9, 2023 13:49
@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch 2 times, most recently from 4c3caa1 to 7f6a5fa Compare February 13, 2023 10:12
@MaciejG604 MaciejG604 marked this pull request as ready for review February 13, 2023 10:12
@MaciejG604 MaciejG604 requested a review from Gedochao February 13, 2023 10:13
@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch 2 times, most recently from a6dc18d to 007c04c Compare February 13, 2023 12:27
@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch from 007c04c to 978748a Compare February 13, 2023 14:33
Copy link
Contributor

@Gedochao Gedochao left a comment

Choose a reason for hiding this comment

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

NIT it'd be good to extract the refactor changes to a separate NIT commit
aside from the nitpicks, LGTM

modules/cli/src/main/scala/scala/cli/exportCmd/Json.scala Outdated Show resolved Hide resolved
@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch 3 times, most recently from 38fce1d to f33651a Compare February 14, 2023 11:08
@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch from f33651a to 07048ab Compare February 16, 2023 08:31
@MaciejG604 MaciejG604 marked this pull request as draft February 16, 2023 08:32
@MaciejG604
Copy link
Contributor Author

MaciejG604 commented Feb 16, 2023

After consideration I think this PR should focus on exporting basic information about the project and mostly on what has been requested, so the list of dependencies and resolvers. The discussion on the cross-compilation for platforms and scala versions should be moved to a follow-up issue.

For now the export --json result contains the following information about the project:

  • projectName
  • scalaVersion that's visible in the Main scope
  • platform only one that's visible in the Main scope
  • scalacOptions
  • scalaCompilerPlugins presented as Strings with ':' as delimiters
  • scalaJsVersion that's visible in the Main scope, only if the platform is JS
  • scalaNativeVersion that's visible in the Main scope, only if the platform is Native
  • mainClass
  • extraDecls contains jsModuleKind information
  • scope specific infromation:
    • scopeName, e.g. "main", "test"
    • sources list of subpaths to the source files
    • dependencies presented as Strings with ':' as delimiters
    • resolvers presented as URL for Maven and ivy:pattern for Ivy
    • resourceDirs
    • extraDecls contains custom jars added to the project

Follow-ups to consider:

  • cross-compilation
  • resolver authentication

@MaciejG604
Copy link
Contributor Author

@fthomas, @ckipp01
Is this format okay?

@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch from 07048ab to 8862a40 Compare February 16, 2023 11:08
@MaciejG604 MaciejG604 marked this pull request as ready for review February 16, 2023 11:11
@ckipp01
Copy link
Contributor

ckipp01 commented Feb 16, 2023

Is this format okay?

Just took a look. Really happy you're working on this! One thing I did notice though, which @prolativ already mentioned is that I like the more structured output than the concise string. By doing the concise string you're now forcing every consumer of this output to have to both know how and to manually parse that output to their needs instead of having it already structured. I'm not really sure what the benefit of the concise string is. Having it structured like you originally had it is much more flexible imo.

@prolativ
Copy link

  1. Showing only the configuration for the current/default platform seems reasonable. We could later (as an independent improvement) add --cross flag to return a json list/object with configurations for different platforms and scala versions.
  2. One can have different scalacOptions for main and test so these should be split. I assume this is true also for scalaCompilerPlugins
  3. is extraDecls supposed to be dependent on the platform (e.g. can it hold some options for scala-native?) or is it scala-js only? In the latter case why isn't it called explicitly jsModuleKind? And why is this property both top-level and separately for main/test?
  4. If we specify scalaJsVersion and scalaNativeVersion, shouldn't we also include e.g. the version of js itself or JVM, if it's specified explicitly?
  5. Maybe scopes should be a Map rather than a list? Then scopeName wouldn't be necessary and extracting a desired scope from the json structure would be easier

@MaciejG604
Copy link
Contributor Author

@prolativ

  • is extraDecls supposed to be dependent on the platform (e.g. can it hold some options for scala-native?) or is it scala-js only? In the latter case why isn't it called explicitly jsModuleKind? And why is this property both top-level and separately for main/test?

I would delete this field altogether and leave scala-j/scala-native options for follow-up PRs if needed. WDYT?

  • If we specify scalaJsVersion and scalaNativeVersion, shouldn't we also include e.g. the version of js itself or JVM, if it's specified explicitly?

By "the version of js itself" do you mean Scala.js ECMA Script version?

@MaciejG604
Copy link
Contributor Author

MaciejG604 commented Feb 17, 2023

[UPDATE]
Added structured dependency json objects, moved scalacOptions and scalaCompilerPlugins to scopes.
Added jvmVersion and jsEsVersion field.

For now the export --json result contains the following information about the project:

  • projectName
  • scalaVersion that's visible in the Main scope
  • platform only one that's visible in the Main scope
  • jvmVersion only if declared explicitly
  • scalaJsVersion that's visible in the Main scope, only if the platform is JS
  • jsEsVersion only if declared explicitly
  • scalaNativeVersion that's visible in the Main scope, only if the platform is Native
  • mainClass
  • scope specific infromation as a map of (scope name -> following information):
    • sources list of subpaths to the source files
    • scalacOptions
    • scalaCompilerPlugins as structured json
    • dependencies as structured json
    • resolvers presented as URL for Maven and ivy:pattern for Ivy
    • resourceDirs
    • customJarsDecls contains custom jars added to the project

Follow-ups to consider:

  • cross-compilation
  • resolver authentication
  • scala-js/scala-native options

@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch from 2aee549 to 07095e7 Compare February 17, 2023 15:47
Copy link

@prolativ prolativ left a comment

Choose a reason for hiding this comment

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

LGTM in general.
Personally I'm not a big fan of jsEsVersion, because:

  • this name is not very intuitive IMO
  • ECMAScript seems to be the standard of the language rather than its implementation but for JVM we can specify that we want to use e.g. --jvm adopt:1.8.0-232 specifically rather than just --jvm 8.
    But at least it seems consistent with the name of the command line option

@MaciejG604 MaciejG604 force-pushed the export-data-from-project branch from 07095e7 to 0b2297d Compare February 20, 2023 09:11
This was linked to issues Feb 20, 2023
@MaciejG604 MaciejG604 merged commit 648755d into VirtusLab:main Feb 21, 2023
@Gedochao Gedochao added the enhancement New feature or request label Feb 22, 2023
@kubukoz
Copy link
Contributor

kubukoz commented Feb 24, 2023

Just curious, what was the motivation for this change? I like it, might be very useful for packaging in Nix, just wanted to know what other usecases you had :)

@tgodzik
Copy link
Member

tgodzik commented Feb 24, 2023

The main use case we were thinking about is Scala Steward support, since there was a suggestion that export to sbt might be used as intermediary, which scared me a bit 😅

@fthomas
Copy link
Contributor

fthomas commented Feb 27, 2023

That suggestion turned quickly into reality: scala-steward-org/scala-steward#2933 🙈 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export information about the project project subcommand
9 participants