use of org.eclipse.ceylon.compiler.js.util.Options in project ceylon by eclipse.
the class MainForJsTest method main.
public static void main(String[] args) throws Exception {
String distRepo = "../dist/dist/repo";
final Options opts = new Options().addRepo(distRepo).outRepo("build/test/proto");
System.out.println("Typechecking Ceylon test code...");
JsModuleManagerFactory.setVerbose(true);
TypeCheckerBuilder tcb = new TypeCheckerBuilder().verbose(false).moduleManagerFactory(new JsModuleManagerFactory(null)).usageWarnings(false);
final ArrayList<File> excludes = new ArrayList<>();
final ArrayList<File> resfiles = new ArrayList<>();
final ArrayList<File> resdirs = new ArrayList<>();
for (String dir : args) {
final File d = new File(dir.charAt(1) == ':' ? dir.substring(2) : dir);
if (dir.startsWith("X:")) {
excludes.add(d);
} else if (dir.startsWith("R:")) {
resdirs.add(d);
} else if (dir.startsWith("r:")) {
resfiles.add(d);
} else if (dir.startsWith("c:")) {
opts.cwd(d);
} else {
tcb.addSrcDirectory(d);
opts.addSrcDir(d);
}
}
final RepositoryManager repoman = CeylonUtils.repoManager().cwd(opts.getCwd()).systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
tcb.setRepositoryManager(repoman);
final TypeChecker typeChecker = tcb.getTypeChecker();
for (File x : excludes) {
String ap = x.getPath();
// Fix for Windows
if ('/' != File.separatorChar) {
ap = ap.replace(File.separatorChar, '/');
}
for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
if (pu.getUnit().getFullPath().startsWith(ap)) {
typeChecker.getPhasedUnits().removePhasedUnitForRelativePath(pu.getPathRelativeToSrcDir());
}
}
}
TypeCache.doWithoutCaching(new Runnable() {
@Override
public void run() {
typeChecker.process();
}
});
if (typeChecker.getErrors() > 0) {
System.exit(1);
}
System.out.println("Compiling in prototype style");
opts.resourceDirs(resdirs);
JsCompiler jsc = new JsCompiler(typeChecker, opts).stopOnErrors(true);
ArrayList<File> sources = new ArrayList<>();
for (String dir : args) {
// The arg is src/test/ceylon for example
addFilesToList(new File(dir), sources);
}
Collections.sort(sources);
jsc.setSourceFiles(sources);
jsc.setResourceFiles(resfiles);
PrintWriter writer = new PrintWriter(System.out);
if (!jsc.generate()) {
jsc.printErrorsAndCount(writer);
}
}
use of org.eclipse.ceylon.compiler.js.util.Options in project ceylon by eclipse.
the class Stitcher method compileLanguageModule.
private static int compileLanguageModule(final String line, final JsOutput writer) throws IOException {
File clsrcTmpDir = Files.createTempDirectory(tmpDir, "clsrc").toFile();
final File tmpout = new File(clsrcTmpDir, Constants.DEFAULT_MODULE_DIR);
FileUtil.mkdirs(tmpout);
final Options opts = new Options().addRepo("build/runtime").comment(false).optimize(true).outRepo(tmpout.getAbsolutePath()).modulify(false).minify(true).suppressWarnings(EnumUtil.enumsFromStrings(Warning.class, Arrays.asList("unusedDeclaration", "ceylonNamespace", "unusedImport"))).addSrcDir(clSrcDir).addSrcDir(LANGMOD_JS_SRC);
// Typecheck the whole language module
if (langmodtc == null) {
langmodtc = new TypeCheckerBuilder().addSrcDirectory(clSrcDir).addSrcDirectory(LANGMOD_JS_SRC).encoding("UTF-8");
langmodtc.setRepositoryManager(CeylonUtils.repoManager().systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager());
langmodtc.usageWarnings(false);
}
final TypeChecker tc = langmodtc.getTypeChecker();
tc.process(true);
if (tc.getErrors() > 0) {
return 1;
}
// Compile these files
final List<File> includes = new ArrayList<File>();
for (String filename : line.split(",")) {
filename = filename.trim();
final boolean isJsSrc = filename.endsWith(".js");
final boolean isDir = filename.endsWith("/");
final boolean exclude = filename.charAt(0) == '-';
if (exclude) {
filename = filename.substring(1);
}
final File src = ".".equals(filename) ? clSrcFileDir : new File(isJsSrc ? LANGMOD_JS_SRC : clSrcFileDir, isJsSrc || isDir ? filename : String.format("%s.ceylon", filename));
if (!addFiles(includes, src, exclude)) {
final File src2 = new File(clJsFileDir, isDir ? filename : String.format("%s.ceylon", filename));
if (!addFiles(includes, src2, exclude)) {
throw new IllegalArgumentException("Invalid Ceylon language module source " + src + " or " + src2);
}
}
}
if (includes.isEmpty()) {
return 0;
}
// Compile only the files specified in the line
// Set this before typechecking to share some decls that otherwise would be private
JsCompiler jsc = new JsCompiler(tc, opts, true).stopOnErrors(false).setSourceFiles(includes);
if (!jsc.generate()) {
jsc.printErrorsAndCount(new OutputStreamWriter(System.out));
return 1;
} else {
// We still call this here for any warning there might be
jsc.printErrorsAndCount(new OutputStreamWriter(System.out));
}
if (names == null) {
names = jsc.getNames();
}
File compsrc = new File(tmpout, "delete/me/delete-me.js");
if (compsrc.exists() && compsrc.isFile() && compsrc.canRead()) {
try {
writer.outputFile(compsrc);
} finally {
compsrc.delete();
}
} else {
System.out.println("Can't find generated js for language module in " + compsrc.getAbsolutePath());
return 1;
}
return 0;
}
use of org.eclipse.ceylon.compiler.js.util.Options in project ceylon by eclipse.
the class CompileSomething method main.
public static void main(String[] x) throws IOException {
final Options opts = new Options().outRepo("/tmp/modules").addRepo("compiler-js/build/runtime").addRepo("../ceylon.ast/modules").addRepo("../ceylon-sdk/modules").addRepo("compiler-js/build/test/proto").addRepo("npm:").optimize(true).verbose("all").generateSourceArchive(false).suppressWarnings(EnumUtil.enumsFromStrings(Warning.class, Arrays.asList("unusedImport"))).addSrcDir("/tmp/source");
final TypeCheckerBuilder tcb = new TypeCheckerBuilder().statistics(false).encoding("UTF-8");
for (File sd : opts.getSrcDirs()) {
tcb.addSrcDirectory(sd);
}
final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
tcb.setRepositoryManager(repoman);
JsModuleManagerFactory.setVerbose(true);
tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
final TypeChecker tc = tcb.getTypeChecker();
TypeCache.setEnabled(false);
tc.process(true);
TypeCache.setEnabled(true);
final JsCompiler jsc = new JsCompiler(tc, opts);
ArrayList<File> individualSources = new ArrayList<>();
for (File srcdir : opts.getSrcDirs()) {
for (File sd : srcdir.listFiles()) {
if (sd.isFile() && sd.getName().endsWith(".js") || !individualSources.isEmpty()) {
System.out.println("Especificando archivos para incluir fuentes js");
individualSources.addAll(Arrays.asList(srcdir.listFiles()));
break;
}
}
}
if (!individualSources.isEmpty()) {
jsc.setSourceFiles(individualSources);
}
jsc.stopOnErrors(true);
boolean ok = jsc.generate();
jsc.printErrors(new java.io.PrintWriter(System.out));
if (ok) {
System.out.println("OK");
} else {
System.out.println("EXIT CODE: " + jsc.getExitCode());
}
}
use of org.eclipse.ceylon.compiler.js.util.Options in project ceylon by eclipse.
the class TestJavaDeps method testJavaDependencies.
@Test
public void testJavaDependencies() throws IOException {
final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test-modules").buildManager();
final TypeCheckerBuilder builder = new TypeCheckerBuilder().setRepositoryManager(repoman).addSrcDirectory(new File("src/test/resources/javadeps"));
final TypeChecker tc = builder.getTypeChecker();
tc.process();
final Options opts = new Options().addSrcDir("src/test/resources/javadeps").outRepo("./build").comment(false).generateSourceArchive(false).encoding("UTF-8");
final JsCompiler comp = new JsCompiler(tc, opts);
comp.generate();
}
use of org.eclipse.ceylon.compiler.js.util.Options in project ceylon by eclipse.
the class TestModuleManager method setup.
@BeforeClass
public static void setup() throws IOException {
// Copy language module to destination
java.io.File srclangmod = new java.io.File(String.format("build/runtime/ceylon/language/%s/ceylon.language-%<s.js", Versions.CEYLON_VERSION_NUMBER));
java.io.File dstlangmod = new java.io.File("build/test/test_modules/ceylon/language/" + Versions.CEYLON_VERSION_NUMBER);
System.out.printf("Copying %s to %s%n", srclangmod, dstlangmod);
dstlangmod.mkdirs();
java.io.BufferedReader lmreader = new java.io.BufferedReader(new java.io.FileReader(srclangmod));
java.io.Writer lmwriter = new java.io.FileWriter(new java.io.File(dstlangmod, srclangmod.getName()));
String line;
while ((line = lmreader.readLine()) != null) {
lmwriter.write(line);
lmwriter.write('\n');
}
lmreader.close();
lmwriter.close();
options = new Options().addRepo("build/test/test_modules").outRepo("build/test/test_modules").addSrcDir("src/test/resources/loader/pass1/m1/test.ceylon").addSrcDir("src/test/resources/loader/pass1");
repoman = CeylonUtils.repoManager().cwd(options.getCwd()).systemRepo(options.getSystemRepo()).userRepos(options.getRepos()).outRepo(options.getOutRepo()).buildManager();
// Create a typechecker to compile the test module
System.out.println("Compiling pass 1");
TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
tcb.addSrcDirectory(new java.io.File("src/test/resources/loader/pass1"));
tcb.setRepositoryManager(repoman);
tc = tcb.getTypeChecker();
tc.process();
JsCompiler compiler = new JsCompiler(tc, options);
compiler.stopOnErrors(false);
compiler.generate();
loadJsModel();
srcmod = tc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule().getLanguageModule();
jsmod = jstc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule().getLanguageModule();
srclang = srcmod.getDirectPackage(Module.LANGUAGE_MODULE_NAME);
jslang = jsmod.getDirectPackage(Module.LANGUAGE_MODULE_NAME);
}
Aggregations