Compile multiple files with ADVANCED_OPTIMIZATIONS

507 views
Skip to first unread message

jochen

unread,
Mar 7, 2011, 3:03:41 PM3/7/11
to Closure Compiler Discuss
Hello,

I want to compile multiple files with ADVANCED_OPTIMIZATIONS and
output the compiled version of each file in a compiled/ directory.
This is the code I am using:

java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js
~/javascripts/one.js --module one:1 --js ~/javascripts/two.js --module
two:1 --module_output_path_prefix=build/

However this seems to throw an exception:


java.lang.RuntimeException: java.lang.IllegalArgumentException:
expected one element but was: <one, two>
at com.google.javascript.jscomp.Compiler.runCallable(Unknown Source)
at com.google.javascript.jscomp.Compiler.runInCompilerThread(Unknown
Source)
at com.google.javascript.jscomp.Compiler.compile(Unknown Source)
at com.google.javascript.jscomp.Compiler.compileModules(Unknown
Source)
at
com.google.javascript.jscomp.AbstractCommandLineRunner.doRun(Unknown
Source)
at com.google.javascript.jscomp.AbstractCommandLineRunner.run(Unknown
Source)
at com.google.javascript.jscomp.CommandLineRunner.main(Unknown
Source)
Caused by: java.lang.IllegalArgumentException: expected one element
but was: <js, share>
at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:
290)
at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:
210)
at com.google.javascript.jscomp.JSModuleGraph.getRootModule(Unknown
Source)
at
com.google.javascript.jscomp.AnalyzePrototypeProperties.<init>(Unknown
Source)

I have the latest code from trunk, any idea what I am doing wrong?

Thanks

peter_lenahan

unread,
Mar 7, 2011, 11:56:20 PM3/7/11
to Closure Compiler Discuss


This tool only acts on a single file at a time. It is not really a
big deal, the tool works very nicely in general.
If you are using a scripting language (shell, perl, python) you can
loop over the files very easily.
If you want to write a "C" or Java Program you can generate the script
as a series of java commands.

Shell Example:

#
# Create you output directory
#
mkdir output
#
#
#
FILE_LIST="~/javascripts/one.js ~/javascripts/two.js "
for file in $FILE_LIST
do
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS
--js ${file} -o output/${file}
done

On windows you can install one of these scripting languages to do
this.
Scripting the the DOS command language is very difficult.

I hope this answers your question.

Good Luck,
Peter

jochen

unread,
Mar 8, 2011, 2:05:27 AM3/8/11
to Closure Compiler Discuss
I was under the impression that to use it with various scripts (who
might depend on each other), we had to compile them all together since
the compiler renames variables.
Looping over files which depend on each other and compiling them one
by one would give issues I believe.

John Lenz

unread,
Mar 8, 2011, 11:40:12 AM3/8/11
to closure-comp...@googlegroups.com
The compiler expects a module tree, where module has some relationship with the others and there is one "root" module.  The compiler is complaining that there are two root modules.

Changing this: 
--module two:1
to this:
--module two:1:one

Should fix the problem. However, this  does tell the compiler that module two can depend on module one being loaded before it is.

If you don't have a common utility module, you can include an empty js file as the root module and the compiler will put the common definitions there.

John Lenz

unread,
Mar 8, 2011, 11:45:07 AM3/8/11
to closure-comp...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages