eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
399 stars 62 forks source link

Programmatically compiling a ceylon module #7059

Open welopino opened 7 years ago

welopino commented 7 years ago

The expample on page Starting a Ceylon module from the JVM - in the section about: Compiling a Ceylon module for both backends - that shows how to compile a module programmatically doesnt fire any method of the listener nor does it seem to compile anything. (ceylon 1.3.2)

Here a ceylon version:


import com.redhat.ceylon.compiler.java.runtime.tools {
    ...
}
import java.io {
    File
}

void compile() {
    CompilerOptions options = CompilerOptions();

    options.addModule("module.to.compile");

    object listener satisfies CompilationListener {

        shared actual void error(File file, Integer line, Integer column, String message) {
            print("error " + message);

        }

        shared actual void warning(File file, Integer line, Integer column, String message) {
            print("warning  " + message);
        }

        shared actual void moduleCompiled(String \imodule, String version) {

            print("moduleCompiled  " + \imodule);
        }
    }

    Compiler jvmCompiler = CeylonToolProvider.getCompiler(Backend.\iJava);
    jvmCompiler.compile(options, listener);
    }

I expect at least one of the three alternative results to be fired on the listener - even in case of a wrong working directory or non-existing "module.to.compile".

welopino commented 7 years ago

And the same problem with the original from the reference:

Run.java


package run;

import com.redhat.ceylon.compiler.java.runtime.tools.*;
import java.io.File;

public class Run {
     public void run(){
        CompilerOptions options = new CompilerOptions();
        options.addModule("c");

        CompilationListener listener = new CompilationListener(){
            @Override
            public void error(File file, long line, long column, String message){
              System.out.println("error");
            }
            @Override
            public void warning(File file, long line, long column, String message){
              System.out.println("warning");
            }
            @Override
            public void moduleCompiled(String module, String version){
              System.out.println("moduleCompiled");
            }
        };

        com.redhat.ceylon.compiler.java.runtime.tools.Compiler jvmCompiler = CeylonToolProvider.getCompiler(Backend.Java);
        jvmCompiler.compile(options, listener);

    }
}

module.ceylon

native("jvm") module run "1.0.0" {
    native("jvm") import java.base "8";
    native("jvm") import com.redhat.ceylon.tool.provider "1.3.2";
    native("jvm") import com.redhat.ceylon.compiler.java "1.3.2";
}

package.ceylon:

shared package run;

run.ceylon:

shared void run(){
  Run().run();
}

No callback is fired - it doesnt do anything.

gavinking commented 7 years ago

@FroMage this is really a usage question for you, I guess. Can you take a look and tell @welopino what he's doing wrong?