-
-
Notifications
You must be signed in to change notification settings - Fork 428
Add resolvedMvnDepsSources task to simplify looking up source files
#6537
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ case class MillCliConfig( | |
| @arg(name = "version", short = 'v', doc = "Show mill version information and exit.") | ||
| showVersion: Flag = Flag(), | ||
| @arg( | ||
| hidden = true, | ||
| name = "bell", | ||
| short = 'b', | ||
| doc = "Ring the bell once if the run completes successfully, twice if it fails." | ||
|
|
@@ -21,7 +22,7 @@ case class MillCliConfig( | |
| tasks and where each log line came from""" | ||
| ) | ||
| ticker: Option[Boolean] = None, | ||
| @arg(name = "debug", short = 'd', doc = "Show debug output on STDOUT") | ||
| @arg(hidden = true, name = "debug", short = 'd', doc = "Show debug output on STDOUT") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is that hidden now? This option is useful. Why do we hide it from the user. |
||
| debugLog: Flag = Flag(), | ||
| @arg( | ||
| short = 'k', | ||
|
|
@@ -64,6 +65,7 @@ case class MillCliConfig( | |
| @arg(short = 'w', doc = "Watch and re-run the given tasks when when their inputs change.") | ||
| watch: Flag = Flag(), | ||
| @arg( | ||
| hidden = true, | ||
| name = "notify-watch", | ||
| doc = "Use filesystem based file watching instead of polling based one (defaults to true)." | ||
| ) | ||
|
|
@@ -72,7 +74,7 @@ case class MillCliConfig( | |
| leftoverArgs: Leftover[String] = Leftover(), | ||
| @arg(doc = | ||
| """Toggle colored output; by default enabled only if the console is interactive | ||
| or FORCE_COLOR environment variable is set, and NO_COLOR environment variable is not set""" | ||
| or FORCE_COLOR environment variable is set, and NO_COLOR is not set""" | ||
| ) | ||
| color: Option[Boolean] = None, | ||
| @arg( | ||
|
|
@@ -84,7 +86,7 @@ case class MillCliConfig( | |
| metaLevel: Option[Int] = None, | ||
|
|
||
| // ==================== ADVANCED CLI FLAGS ==================== | ||
| @arg(doc = "Allows command args to be passed positionally without `--arg` by default") | ||
| @arg(hidden = true, doc = "Allows command args to be passed positionally without `--arg` by default") | ||
| allowPositional: Flag = Flag(), | ||
| @arg( | ||
| hidden = true, | ||
|
|
@@ -113,6 +115,7 @@ case class MillCliConfig( | |
| ) | ||
| noWaitForBuildLock: Flag = Flag(), | ||
| @arg( | ||
| hidden = true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this visible again. |
||
| doc = """ | ||
| Try to work offline. | ||
| This tells modules that support it to work offline and avoid any access to the internet. | ||
|
|
@@ -122,6 +125,7 @@ case class MillCliConfig( | |
| ) | ||
| offline: Flag = Flag(), | ||
| @arg( | ||
| hidden = true, | ||
| doc = """ | ||
| Globally disables the checks that prevent you from reading and writing to disallowed | ||
| files or folders during evaluation. Useful as an escape hatch in case you desperately | ||
|
|
@@ -139,6 +143,7 @@ case class MillCliConfig( | |
| ) | ||
| useFileLocks: Flag = Flag(), | ||
| @arg( | ||
| hidden = true, | ||
| doc = """Runs Mill in tab-completion mode""" | ||
| ) | ||
| tabComplete: Flag = Flag(), | ||
|
|
@@ -163,8 +168,7 @@ case class MillCliConfig( | |
| disableTicker: Flag, | ||
| @arg( | ||
| doc = """Open a JShell REPL with the classpath of the meta-level 1 build module (mill-build/). | ||
| This is useful for interactively testing and debugging your build logic. | ||
| Implies options `--meta-level 1` and `--no-server`.""" | ||
| This is useful for interactively testing and debugging your build logic.""" | ||
| ) | ||
| jshell: Flag = Flag() | ||
| ) { | ||
|
|
@@ -203,6 +207,8 @@ Task cheat sheet: | |
| mill foo.test + bar.test # run tests in the `foo` module and `bar` module | ||
| mill '{foo,bar,qux}.test' # run tests in the `foo` module, `bar` module, and `qux` module | ||
|
|
||
| mill foo.resolvedMvnSources # resolve `foo`'s third-party dependencies' source code for browsing | ||
|
|
||
| mill foo.assembly # generate an executable assembly of the module `foo` | ||
| mill show foo.assembly # print the output path of the assembly of module `foo` | ||
| mill inspect foo.assembly # show docs and metadata for the `assembly` task on module `foo` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,19 +7,12 @@ import coursier.params.ResolutionParams | |
| import coursier.parse.{JavaOrScalaModule, ModuleParser} | ||
| import coursier.util.{EitherT, ModuleMatcher, Monad} | ||
| import mainargs.Flag | ||
| import mill.api.{MillException, Result} | ||
| import mill.api.{BuildCtx, DefaultTaskModule, MillException, ModuleRef, PathRef, Result, Segment, Task, TaskCtx} | ||
| import mill.api.daemon.internal.{EvaluatorApi, JavaModuleApi, internal} | ||
| import mill.api.daemon.internal.bsp.{ | ||
| BspBuildTarget, | ||
| BspJavaModuleApi, | ||
| BspModuleApi, | ||
| BspUri, | ||
| JvmBuildTarget | ||
| } | ||
| import mill.api.daemon.internal.bsp.{BspBuildTarget, BspJavaModuleApi, BspModuleApi, BspUri, JvmBuildTarget} | ||
| import mill.api.daemon.internal.eclipse.GenEclipseInternalApi | ||
| import mill.javalib.* | ||
| import mill.api.daemon.internal.idea.GenIdeaInternalApi | ||
| import mill.api.{DefaultTaskModule, ModuleRef, PathRef, Segment, Task, TaskCtx} | ||
| import mill.javalib.api.CompilationResult | ||
| import mill.javalib.api.internal.{JavaCompilerOptions, ZincOp} | ||
| import mill.javalib.bsp.{BspJavaModule, BspModule} | ||
|
|
@@ -1058,15 +1051,7 @@ trait JavaModule | |
| compileResources() ++ unmanagedClasspath() | ||
| } | ||
|
|
||
| /** | ||
| * Resolved dependencies | ||
| */ | ||
| def resolvedMvnDeps: T[Seq[PathRef]] = Task { | ||
| if (resolvedDepsWarnNonPlatform()) { | ||
| Dep.validatePlatformDeps(platformSuffix(), mvnDeps()).pipe(warn => | ||
| if (warn.nonEmpty) Task.log.warn(warn.mkString("\n")) | ||
| ) | ||
| } | ||
| private def resolvedMvnDeps0(sources: Boolean) = Task.Anon { | ||
| millResolver().classpath( | ||
| Seq( | ||
| BoundDep( | ||
|
|
@@ -1075,7 +1060,8 @@ trait JavaModule | |
| ), | ||
| BoundDep(coursierDependencyTask(), force = false) | ||
| ), | ||
| artifactTypes = Some(artifactTypes()), | ||
| sources = sources, | ||
| artifactTypes = if (sources) None else Some(artifactTypes()), | ||
| resolutionParamsMapOpt = | ||
| Some { params => | ||
| params | ||
|
|
@@ -1091,6 +1077,32 @@ trait JavaModule | |
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Resolved dependencies | ||
| */ | ||
| def resolvedMvnDeps: T[Seq[PathRef]] = Task { | ||
| if (resolvedDepsWarnNonPlatform()) { | ||
| Dep.validatePlatformDeps(platformSuffix(), mvnDeps()).pipe(warn => | ||
| if (warn.nonEmpty) Task.log.warn(warn.mkString("\n")) | ||
| ) | ||
| } | ||
| resolvedMvnDeps0(sources = false)() | ||
| } | ||
|
|
||
| /** | ||
| * Resolved dependency sources, unpacked into a single directory. Useful to quickly | ||
| * look up the sources of the dependencies on your classpath so you can find the | ||
| * exact source code you are compiling and running against. | ||
| */ | ||
| def resolvedMvnSources: T[PathRef] = Task { | ||
| for (jar <- resolvedMvnDeps0(sources = true)()) { | ||
| val jarName = jar.path.last.stripSuffix(".jar") | ||
| os.unzip(jar.path, Task.dest / jarName) | ||
| } | ||
| println(s"Unpacked sources of transitive third-party dependencies into ${Task.dest.relativeTo(BuildCtx.workspaceRoot)} for browsing") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to make it a |
||
| PathRef(Task.dest) | ||
| } | ||
|
|
||
| override def upstreamIvyAssemblyClasspath: T[Seq[PathRef]] = Task { | ||
| resolvedRunMvnDeps() | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package mill.util | |
|
|
||
| import mill.* | ||
| import mill.api.PathRef | ||
| import mill.util.Jvm.jdkTool | ||
|
|
||
| /** | ||
| * A trait providing convenient access to common JDK command-line tools. | ||
|
|
@@ -17,38 +18,48 @@ trait JdkCommandsModule extends mill.api.Module { | |
| */ | ||
| def jdkCommandsJavaHome: Task[Option[PathRef]] = Task.Anon { None } | ||
|
|
||
| private def callJdk(toolName: String, javaHome: Option[PathRef], args: Seq[String]): Int = { | ||
| os.call( | ||
| cmd = Seq(jdkTool(toolName, javaHome.map(_.path))) ++ args, | ||
| stdin = os.Inherit, | ||
| stdout = os.Inherit, | ||
| check = false | ||
| ) | ||
| .exitCode | ||
| } | ||
|
|
||
| /** | ||
| * Runs the `java` command from this module's [[jdkCommandsJavaHome]]. | ||
| * Renamed to `java` on the command line. | ||
| */ | ||
| @Task.rename("java") | ||
| @mainargs.main(name = "java") | ||
| def javaRun(args: String*): Command[Unit] = Task.Command(exclusive = true) { | ||
| Jvm.callJdkTool("java", args, jdkCommandsJavaHome().map(_.path)) | ||
| Task.ctx().systemExit(callJdk("java", jdkCommandsJavaHome(), args)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should stop the Mill process. It is enough to signal the status code via the task success value. Same for the other occurences.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to propagate the existing JDK exit code, the task success/failure only lets you return 1 or 0 now and would stomp over any other code
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't see the value in those specific tasks, as they are not generic. I could very well live with some special entry point to wrap all kind of thirdparty dev tools, since we have all infrastructure to provide them, but having a dedicated task for each of them doesn't scale. Making it generic like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving with |
||
| } | ||
|
|
||
| /** Runs the `javac` command from this module's [[jdkCommandsJavaHome]] */ | ||
| def javac(args: String*): Command[Unit] = Task.Command(exclusive = true) { | ||
| Jvm.callJdkTool("javac", args, jdkCommandsJavaHome().map(_.path)) | ||
| Task.ctx().systemExit(callJdk("javac", jdkCommandsJavaHome(), args)) | ||
| } | ||
|
|
||
| /** Runs the `javap` command from this module's [[jdkCommandsJavaHome]] */ | ||
| def javap(args: String*): Command[Unit] = Task.Command(exclusive = true) { | ||
| Jvm.callJdkTool("javap", args, jdkCommandsJavaHome().map(_.path)) | ||
| Task.ctx().systemExit(callJdk("javap", jdkCommandsJavaHome(), args)) | ||
| } | ||
|
|
||
| /** Runs the `jstack` command from this module's [[jdkCommandsJavaHome]] */ | ||
| def jstack(args: String*): Command[Unit] = Task.Command(exclusive = true) { | ||
| Jvm.callJdkTool("jstack", args, jdkCommandsJavaHome().map(_.path)) | ||
| Task.ctx().systemExit(callJdk("jstack", jdkCommandsJavaHome(), args)) | ||
| } | ||
|
|
||
| /** Runs the `jps` command from this module's [[jdkCommandsJavaHome]] */ | ||
| def jps(args: String*): Command[Unit] = Task.Command(exclusive = true) { | ||
| Jvm.callJdkTool("jps", args, jdkCommandsJavaHome().map(_.path)) | ||
| Task.ctx().systemExit(callJdk("jps", jdkCommandsJavaHome(), args)) | ||
| } | ||
|
|
||
| /** Runs the `jfr` command from this module's [[jdkCommandsJavaHome]] */ | ||
| def jfr(args: String*): Command[Unit] = Task.Command(exclusive = true) { | ||
| Jvm.callJdkTool("jfr", args, jdkCommandsJavaHome().map(_.path)) | ||
| Task.ctx().systemExit(callJdk("jfr", jdkCommandsJavaHome(), args)) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that?