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

Classpath problem in MDocModule.mdoc #5

Open
hmf opened this issue Sep 23, 2022 · 2 comments
Open

Classpath problem in MDocModule.mdoc #5

hmf opened this issue Sep 23, 2022 · 2 comments

Comments

@hmf
Copy link

hmf commented Sep 23, 2022

While trying to use this module I got an error in the imports. After some some searching I noticed that MDoc's --classpath is not being used in the call to Jvm.runLocal. More concretely the command line arguments should be changed.

Here is my working version that I use as an override:

  override def mdoc : T[PathRef] = T {
  
    val cp = runClasspath().map(_.path)
    val separator = java.io.File.pathSeparatorChar
  
    val dir = T.dest.toIO.getAbsolutePath
    val dirParams = mdocSources().map(pr => Seq(
        "--classpath", cp.mkString(s"$separator"),
        "--in", pr.path.toIO.getAbsolutePath, 
        "--out",  dir)
      ).iterator.flatten.toSeq
  
    Jvm.runLocal("mdoc.Main", cp, dirParams)
  
    PathRef(T.dest)
  }

Two additional notes:

  • The original code uses a s"--in" but string interpolation is not used
  • We do not really need to add all of the applications classpath via the cp parameter. I think here we should just add MDoc and its dependencies.
@hmf
Copy link
Author

hmf commented Sep 24, 2022

After getting help (see com-lihaoyi/mill#2045) I suggest the following changes to execute MDoc:

  def mdocDep: Task[Agg[Dep]] = T.task{ Agg(scalaMdocDep()) } 
  def mDocLibs = T{ resolveDeps(mdocDep)  }
  val separator = java.io.File.pathSeparatorChar
  def toArgument(p: Agg[os.Path]) = p.mkString(s"$separator")

  override def mdoc : T[PathRef] = T {
  
    val rp = mDocLibs().map(_.path)
    val cp = runClasspath().map(_.path)

    val dir = T.dest.toIO.getAbsolutePath
    val dirParams = mdocSources().map(pr => Seq(
        "--classpath", toArgument(cp),
        "--in", pr.path.toIO.getAbsolutePath, 
        "--out",  dir)
      ).iterator.flatten.toSeq
  
    Jvm.runLocal("mdoc.Main", rp, dirParams)
  
    PathRef(T.dest)
  }

The project's dependencies now need not include the MDoc library, for example (see issue #4 on need to add MDoc to the Ivy deps):

  override def ivyDeps = Agg(
      ivy"org.tensorflow:tensorflow-core-api:${tensorflowVersion}",
      ivy"org.tensorflow:tensorflow-core-api:${tensorflowVersion};classifier=${javaCPPPlatform()}"
  )

@hmf
Copy link
Author

hmf commented Sep 26, 2022

Additional errors were detected with the proposed solution above. For more information see this issue. See this for a working example (we need to add the correct Scala compiler).

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

No branches or pull requests

1 participant