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

BSP: Provide mill source files #1029

Merged
merged 2 commits into from
Dec 4, 2020
Merged

BSP: Provide mill source files #1029

merged 2 commits into from
Dec 4, 2020

Conversation

joan38
Copy link
Collaborator

@joan38 joan38 commented Dec 3, 2020

Not sure why the following does not bring in the dependencies anymore since 0.9.x:

val classpath = Try(evaluator.rootModule.getClass.getClassLoader.asInstanceOf[SpecialClassLoader]).fold(
  _ => Seq.empty,
  _.allJars
)

So this is resolving the source files directly. Let me know if you have a better idea.

@joan38
Copy link
Collaborator Author

joan38 commented Dec 4, 2020

@lefou this is ready for review

Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

I suspect the SpecialClassLoader never carried the mill API. But, maybe it's a good thing to be more verbose in case we don't get a SpecialClassLoader.

I made some comments below.

Comment on lines 89 to 90
val repos = Evaluator
.evalOrElse(evaluator, T.task(T.traverse(modules)(_.repositoriesTask)()), Seq.empty)
Copy link
Member

Choose a reason for hiding this comment

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

The T.task is probably redundant. T.traverse already produces a task.

@@ -36,7 +36,7 @@ object Lib{
depToDependency: Dep => coursier.Dependency,
deps: TraversableOnce[Dep],
mapDependencies: Option[Dependency => Dependency] = None,
ctx: Option[mill.util.Ctx.Log] = None) = {
ctx: Option[mill.util.Ctx.Log] = None): (Seq[Dependency], Resolution) = {
Copy link
Member

Choose a reason for hiding this comment

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

👍 for explicit return type.

Agg(
ivy"com.lihaoyi::mill-main:$millVersion",
ivy"com.lihaoyi::mill-scalalib:$millVersion",
ivy"com.lihaoyi::mill-scalajslib:$millVersion",
ivy"com.lihaoyi::mill-scalanativelib:$millVersion"
),
sources = sources
Copy link
Member

Choose a reason for hiding this comment

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

I think these deps were never there before, at least all my experiments with mill-bsp resulted in missing mill API when editing build.sc. But, we should not bury such a hardcoded list here. Instead, this is knowledge best located in the buildfile (build.sc). We could generate a Scala file there (generateSources or BuildInfo plugin) and use it here. We have this exactly hard-coded list also in GenIdeaImpl, and I think this is an opportunity to fix both places the right way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Excellent idea! Check out the new commit.

val millJars = resolveDependencies(
Resolve.defaultRepositories,
depToDependency(_, BuildInfo.scalaVersion),
BuildInfo.millEmbeddedModules.map(module => ivy"com.lihaoyi::mill-$module:${BuildInfo.millVersion}"),
Copy link
Member

Choose a reason for hiding this comment

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

I think using full ivy artifact is the way to go (using module.publishSelfDependency() when generating the BuildInfo). Less assumptions about the deps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Check out the new commit.

Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

@joan38 I'm sorry when it appears as nitpicking. I think keeping the generated file dependency free is a good thing, so I suggest to use a plain string to transport the dependency. I added suggestions to show what I have in mind. Don't know if it compiles though.

If tests work, this looks good to me! Looking forward to try that out.

build.sc Outdated
@@ -260,6 +261,8 @@ object scalalib extends MillModule {
| val ammonite = "${Deps.ammonite.dep.version}"
| /** Version of Zinc. */
| val zinc = "${Deps.zinc.dep.version}"
| /** Dependency artifacts embedded in mill by default. */
| val millEmbeddedDeps = ${artifacts.map(artifact => s"""ivy"${artifact.group}::${artifact.id}:${artifact.version}"""")}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| val millEmbeddedDeps = ${artifacts.map(artifact => s"""ivy"${artifact.group}::${artifact.id}:${artifact.version}"""")}
| val millEmbeddedDeps = ${artifacts.map(artifact => s""""${artifact.group}:${artifact.id}:${artifact.version}"""")}

Artitfact ID is already platform-resolved. Also I'd rather just use the string.

for(name <- artifactNames)
yield ivy"com.lihaoyi::mill-$name:${sys.props("MILL_VERSION")}",
false,
Versions.millEmbeddedDeps,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Versions.millEmbeddedDeps,
Versions.millEmbeddedDeps.map(d => ivy"$d"),

val millJars = resolveDependencies(
Resolve.defaultRepositories,
depToDependency(_, BuildInfo.scalaVersion),
Versions.millEmbeddedDeps,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Versions.millEmbeddedDeps,
Versions.millEmbeddedDeps.map(d => ivy"$d"),

@lefou
Copy link
Member

lefou commented Dec 4, 2020

@joan38, since our move to GitHub Actions, there is no longer the need to rebase or force-pushg all PRs to latest master to let tests pass. We can squash when merging.

@joan38
Copy link
Collaborator Author

joan38 commented Dec 4, 2020

Your suggestions are good @lefou, keep on nitpicking that's how we achieve perfection :)

Do you recommend moving this back to BuildInfo in core since we don't need access to Dep in scalalib?

I'm just used to amend force pushing but would incremental commits better help incremental reviewing?

@lefou
Copy link
Member

lefou commented Dec 4, 2020

Your suggestions are good @lefou, keep on nitpicking that's how we achieve perfection :)

You asked for it. ;-)

Do you recommend moving this back to BuildInfo in core since we don't need access to Dep in scalalib?

Yes.

I'm just used to amend force pushing but would incremental commits better help incremental reviewing?

Yeah, avoiding forced pushes would greatly help, esp. in the Github UI.

@joan38 joan38 merged commit 3f8afc2 into com-lihaoyi:master Dec 4, 2020
@joan38 joan38 deleted the bsp branch December 4, 2020 19:00
@lefou lefou added this to the after 0.9.3 milestone Dec 5, 2020
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.

2 participants