Skip to content

Script to run compiler #10

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

Closed
wants to merge 6 commits into from
Closed

Script to run compiler #10

wants to merge 6 commits into from

Conversation

DarkDimius
Copy link
Contributor

Added a script to run compiler.
Though it still fails to compile even a single empty class.
review @VladUreche

Added a script to run compiler
@xeno-by
Copy link

xeno-by commented Feb 12, 2014

I really recommend having a more intelligent runner like the one I took from Paul: https://github.com/xeno-by/dotx/blob/master/scala-runner. This one can later be symlinked to scala, scalac, scaladoc, etc.

then
echo "The script is going to build the required jar file $1 by running \"sbt $2\" [5s until build]"
sleep 5
cd $MINIBOXING_PATH
Copy link
Member

Choose a reason for hiding this comment

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

MINIBOXING_PATH?

@VladUreche
Copy link
Contributor

Just to summarize the discussion we just had:

  • the script fails due to the Scala library being on the classpath but not bootclasspath
  • it is impossible to inject bootclasspath in a jar manifest

So, the course of action should be:

  • see if Scala also has this bootclasspath restriction
  • if so, check with scala-internals if this is a security measure
  • if not, let dotty get the scala library from the classpath

@lrytz
Copy link
Member

lrytz commented Feb 12, 2014

I don't fully understand yet.. You are saying that scala-library.jar needs to be on the bootclasspath to execute scalac, i.e., scala.tools.nsc.Main?

What does this have to do with dotty?

Also there might be confusion about the (JVM) classpath used to run scalac, and the classpath that scalac reads dependencies from. The two are independent. Only if you use -usejavacp, the scala compiler will put everything on the JVM classpath into its own classpath.

@DarkDimius
Copy link
Contributor Author

@lrytz yes. scalac requires either scala-library.jar on bootclasspath or flag -Dscala.usejavacp=true (later is provided by default scalac script)
-usejavacp indeed works for scalac, but doesn't for dotty. I'm currenlty trying to find why
@VladUreche i believe it was done not as a security measure but to reduce time needed to find classes commonly used by compiler.

@lrytz
Copy link
Member

lrytz commented Feb 12, 2014

The bootclasspath was only used because startup time was faster. For scalac / dotc it should not matter whether the scala library is on the boot classpath or on the normal (JVM) classpath.

Note that the system properties describing the two are not the same: sun.boot.class.path vs java.class.path (http://docs.oracle.com/javase/7/docs/technotes/tools/findingclasses.html)

The -usejavacp option should probably add all jars / directories from both (JVM) classpaths to the scala/dotty classpath. This should be handled in the compiler code, it has nothing to do with the runner script and this pull request.

@DarkDimius
Copy link
Contributor Author

@lrytz

For scalac / dotc it should not matter whether the scala library is on the boot classpath or on the normal (JVM) classpath.

I completely agree that it shouldn't, but currently for dotty it matters

java -cp "/home/dark/opt/scala-2.11.0-M7/lib/scala-library.jar" -Dscala.usejavacp=true -jar /home/dark/workspace/dotty/target/scala-2.11.0-M7/dotty_2.11.0-M7-0.1-SNAPSHOT.jar -Dscala.usejavacp=true  1.scala

will die with error

Exception in thread "main" ERROR at ?: bad symbolic reference. A signature
refers to scala$ in package <root> which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling the signature.

while

java -Xbootclasspath/a:"/home/dark/opt/scala-2.11.0-M7/lib/scala-library.jar" -Dscala.usejavacp=true -jar /home/dark/workspace/dotty/target/scala-2.11.0-M7/dotty_2.11.0-M7-0.1-SNAPSHOT.jar 1.scala

succeeds.

Interesting though that removing -Dscala.usejavacp=true from last command line also makes it fail the same way

@lrytz
Copy link
Member

lrytz commented Feb 12, 2014

Interesting though that removing -Dscala.usejavacp=true from last command line also makes it fail the same way

This is kind of expected.

@DarkDimius
Copy link
Contributor Author

Works on my machine at least now.
@lrytz AFAIK you are using MacBook. Can you please check if script runs on mac?

@@ -0,0 +1,53 @@
#!/bin/bash
if [[ "$OSTYPE" == "linux-gnu" ]]; then
MY_PATH="`realpath \"$0\"`" # relative, symbolic links resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't rely on realpath -- it's not a standard unix util (needed apt-get to install it)

@VladUreche
Copy link
Contributor

LGTM modulo the realpath usage. Since realpath recursively expands links, while readlink only does it once, I'd say the script is as good as we;re going to get.

Anyone against merging?

@VladUreche
Copy link
Contributor

Just for reference, the answer to the question why do we need to set the bootclasspath to run dotty in eclipse/sbt: https://github.com/lampepfl/dotty/wiki/Classpaths-when-running-dotty

@lrytz
Copy link
Member

lrytz commented Feb 12, 2014

when adding a new page to the wiki, consider adding it to the sidebar navigation. click "edit page" on the wiki, then there's a "sidebar" section.

@VladUreche
Copy link
Contributor

Thanks @lrytz, I added the link under Getting Started.

@lrytz
Copy link
Member

lrytz commented Feb 13, 2014

Running on my macbook i get realpath: command not found

lucmac:dotty luc$ ./dottyc 
./dottyc: line 10: realpath: command not found
Usage: scalac <options> <source files>
where possible standard options include:
-Dproperty=value   Pass -Dproperty=value directly to the runtime system.
-J<flag>           Pass <flag> directly to the runtime system.
...

I'd suggest

  • moving the script to some directory (there might be more in the future)
  • renaming it to dotc

Otherwise it seems to work

lucmac:dotty luc$ cat test.scala 
class C {
  val x = 1
  println(x)
}

lucmac:dotty luc$ ./dottyc test.scala -verbose
./dottyc: line 10: realpath: command not found
[loaded package loader classes.jar in 285ms]
...
[loaded class file /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar(java/lang/Object.class) in 20ms]
...
[loaded class file /Users/luc/scala/dotty/target/scala-2.11.0-M7/dotty_2.11.0-M7-0.1-SNAPSHOT.jar(dotty/DottyPredef.class) in 32ms]
...
[loaded class file /Users/luc/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.0-M7.jar(scala/Predef.class) in 45ms]
...

@DarkDimius
Copy link
Contributor Author

I already have some commands called dotc and dotty in PATH(I believe they come from graphviz package).
I suggest we leave it as dottyc.

@lrytz
Copy link
Member

lrytz commented Feb 13, 2014

That's unfortunate.. Are you sure it's from graphviz? I have it installed, so I do have dot, but i don't have dotc. Also, a google search does not show any results.

@DarkDimius
Copy link
Contributor Author

dark@roll ~/workspace/dotty $ equery b dotty
 * Searching for dotty ... 
media-gfx/graphviz-2.26.3-r4 (/usr/bin/dotty)
dark@roll ~/workspace/dotty $ equery b dotc
 * Searching for dotc ... 
dark@roll ~/workspace/dotty $

Package manager doesn't know where does dotc come from. But dotty is definitely part of graphviz

@lrytz
Copy link
Member

lrytz commented Feb 13, 2014

OK. I'd vote for dotc, it's consistent with the package name used in the source code.

@VladUreche
Copy link
Contributor

Seems dotc is also available on Ubuntu 12.04:

$ dotc
Commande 'dotc' non trouvée, vouliez-vous dire :
 La commande 'dtc' du paquet 'device-tree-compiler' (main)
 La commande 'dot' du paquet 'graphviz' (main)
 La commande 'dots' du paquet 'dots' (universe)
 La commande 'ddtc' du paquet 'ddtc' (universe)
dotc : commande introuvable

@DarkDimius
Copy link
Contributor Author

I will work on improving the script with features from paulp script. As well as rename it to dotc.

@adriaanm
Copy link
Contributor

btw, I find the status quo for usejavacp backwards -- it should be opt-out
since the compiler doesn't work without it, we shouldn't have to specify it

@DarkDimius
Copy link
Contributor Author

It seems that making repo public broke ling between my branch and this PR.
Please continue in #26

@DarkDimius DarkDimius closed this Feb 19, 2014
smarter pushed a commit that referenced this pull request Mar 12, 2020
doc(opaque type alias): revise text, remove workaround
romanowski added a commit to romanowski/dotty that referenced this pull request Oct 23, 2020
Add dotty-dokka resources appender and installer, append project-specific CSS
pikinier20 added a commit that referenced this pull request Aug 16, 2022
szymon-rd pushed a commit that referenced this pull request Dec 9, 2022
Add second line with description to search result
WojciechMazur added a commit to WojciechMazur/dotty that referenced this pull request Mar 19, 2025
Backport "Let show behave more robustly for Recheck" to LTS
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.

5 participants