Skip to content

Commit

Permalink
Add an Ant task to compile .py files to $py.class. It runs on Lib as …
Browse files Browse the repository at this point in the history
…part of developer-build to

exercise it a little bit.

Also, only rename the xerces parts of org.apache.  Otherwise our ant imports get renamed when
jarjaring.
  • Loading branch information
groves committed Jan 18, 2009
1 parent 8fb2e40 commit d1d3479
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 150 deletions.
21 changes: 16 additions & 5 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ svnant.jar.dir=${basedir}/../externals/svnant-jars
</echo>
</target>

<target name="jarless" depends="compile, copy-lib"/>
<target name="jarless" depends="compile, pycompile"/>

<target name="developer-build" depends="prepare-output, jar, copy-lib" description="a local build for developers" />
<target name="developer-build" depends="prepare-output, pycompile" description="a local build for developers" />

<target name="full-build" depends="full-check, install" description="a full build with svn checkout" />

Expand Down Expand Up @@ -364,7 +364,7 @@ svnant.jar.dir=${basedir}/../externals/svnant-jars

<!-- skip-brand can be set in ant.properties or as a system property to keep from updating the
version.properties file and making the jar on every developer build. -->
<target name="brand-version" depends="version-init, svnversion" unless="skip-brand">
<target name="brand-version" depends="init, svnversion" unless="skip-brand">
<condition property="build.svn.revision" value="">
<not>
<isset property="build.svn.revision"/>
Expand Down Expand Up @@ -522,8 +522,10 @@ The readme text for the next release will be like:
<rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/>
<zipfileset src="extlibs/constantine-0.4.jar"/>
<rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/>
<zipfileset src="extlibs/xercesImpl-2.9.1.jar"/>
<rule pattern="org.apache.**" result="org.python.apache.@1"/>
<rule pattern="org.apache.xml.**" result="org.python.apache.xml.@1"/>
<rule pattern="org.apache.xerces.**" result="org.python.apache.xerces.@1"/>
<rule pattern="org.apache.wml.**" result="org.python.apache.wml.@1"/>
<rule pattern="org.apache.html.**" result="org.python.apache.html.@1"/>
<manifest>
<attribute name="Main-Class" value="org.python.util.jython" />
<attribute name="Built-By" value="${user.name}" />
Expand Down Expand Up @@ -637,6 +639,15 @@ The readme text for the next release will be like:
</copy>
</target>

<target name="pycompile" depends="jar,copy-lib">
<taskdef name="jycompile" classname="org.python.util.JycompileAntTask">
<classpath path="${dist.dir}/Lib"/>
<classpath path="${dist.dir}/${jython.dev.jar}" />
<classpath refid="main.classpath" />
</taskdef>
<jycompile srcdir="${dist.dir}/Lib" destdir="${dist.dir}/Lib" excludes="test/**"/>
</target>

<target name="copy-lib" depends="init, copy-javalib, copy-cpythonlib">
<!-- XXX untested and most likely broken in 2.5
<copy todir="${dist.dir}" preservelastmodified="true">
Expand Down
10 changes: 4 additions & 6 deletions src/org/python/compiler/Future.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ private boolean check(ImportFrom cand) throws Exception {
return false;
int n = cand.getInternalNames().size();
if (n == 0) {
throw new ParseException(
"future statement does not support import *",cand);
throw new ParseException("future statement does not support import *", cand);
}
for (int i = 0; i < n; i++) {
String feature = cand.getInternalNames().get(i).getInternalName();
Expand Down Expand Up @@ -56,8 +55,7 @@ private boolean check(ImportFrom cand) throws Exception {
if (feature.equals("GIL") || feature.equals("global_interpreter_lock")) {
throw new ParseException("Never going to happen!", cand);
}
throw new ParseException("future feature "+feature+
" is not defined",cand);
throw new ParseException("future feature " + feature + " is not defined", cand);
}
return true;
}
Expand Down Expand Up @@ -90,7 +88,7 @@ public void preprocessFutures(mod node,
if (!(s instanceof ImportFrom))
break;
s.from_future_checked = true;
if (!check((ImportFrom) s))
if (!check((ImportFrom)s))
break;
}

Expand Down Expand Up @@ -119,7 +117,7 @@ public static void checkFromFuture(ImportFrom node) throws Exception {
public boolean areDivisionOn() {
return division;
}

public boolean withStatementSupported() {
return with_statement;
}
Expand Down
14 changes: 7 additions & 7 deletions src/org/python/compiler/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,20 @@ public PyCodeConstant PyCode(mod tree, String name,
c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj);
c.dup();
c.ifnonnull(label_got_name);

c.pop();
c.aload(1);
c.ldc("__name__");
c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj);

c.label(label_got_name);
c.astore(module_tmp);
c.aload(1);
c.ldc("__module__");
c.aload(module_tmp);
c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V");
}

Label genswitch = new Label();
if (scope.generator) {
c.goto_(genswitch);
Expand Down Expand Up @@ -476,13 +476,13 @@ public PyCodeConstant PyCode(mod tree, String name,
compiler.parse(tree, c, fast_locals, className, classBody,
scope, cflags);


// similar to visitResume code in pyasm.py
if (scope.generator) {
c.label(genswitch);

c.aload(1);
c.getfield("org/python/core/PyFrame", "f_lasti", "I");
c.getfield("org/python/core/PyFrame", "f_lasti", "I");
Label[] yields = new Label[compiler.yields.size()+1];

yields[0] = start;
Expand Down Expand Up @@ -637,7 +637,7 @@ public void error(String msg,boolean err,PythonTree node)
public static void compile(mod node, OutputStream ostream,
String name, String filename,
boolean linenumbers, boolean printResults,
org.python.core.CompilerFlags cflags)
CompilerFlags cflags)
throws Exception
{
Module module = new Module(name, filename, linenumbers);
Expand Down
11 changes: 5 additions & 6 deletions src/org/python/compiler/ScopesCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import org.python.antlr.ast.Return;
import org.python.antlr.ast.With;
import org.python.antlr.ast.Yield;
import org.python.antlr.ast.comprehension;
import org.python.antlr.ast.arguments;
import org.python.antlr.ast.expr_contextType;
import org.python.antlr.base.expr;
import org.python.antlr.base.stmt;
import org.python.core.ParserFacade;

import java.util.ArrayList;
import java.util.Hashtable;
Expand Down Expand Up @@ -85,8 +85,7 @@ public void parse(PythonTree node) throws Exception {
try {
visit(node);
} catch (Throwable t) {
throw org.python.core.ParserFacade.fixParseError(null, t,
code_compiler.getFilename());
throw ParserFacade.fixParseError(null, t, code_compiler.getFilename());
}
}

Expand Down Expand Up @@ -138,10 +137,10 @@ public Object visitFunctionDef(FunctionDef node) throws Exception {
beginScope(node.getInternalName(), FUNCSCOPE, node, ac);
int n = ac.names.size();
for (int i = 0; i < n; i++) {
cur.addParam((String) ac.names.get(i));
cur.addParam(ac.names.get(i));
}
for (int i = 0; i < ac.init_code.size(); i++) {
visit((stmt) ac.init_code.get(i));
visit(ac.init_code.get(i));
}
cur.markFromParam();
suite(node.getInternalBody());
Expand Down Expand Up @@ -291,7 +290,7 @@ public Object visitYield(Yield node) throws Exception {
traverse(node);
return null;
}

@Override
public Object visitReturn(Return node) throws Exception {
if (node.getInternalValue() != null) {
Expand Down
35 changes: 18 additions & 17 deletions src/org/python/core/PySystemState.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,23 +495,23 @@ private static String findRoot(Properties preProperties,
jarIndex = lowerCaseClasspath.indexOf(JYTHON_DEV_JAR);
}
if (jarIndex >= 0) {
int start = classpath.lastIndexOf(java.io.File.pathSeparator, jarIndex) + 1;
int start = classpath.lastIndexOf(File.pathSeparator, jarIndex) + 1;
root = classpath.substring(start, jarIndex);
} else {
// in case JYTHON_JAR is referenced from a MANIFEST inside another jar on the classpath
root = jarFileName;
root = new File(jarFileName).getParent();
}
}
}
if (root != null) {
File rootFile = new File(root);
try {
root = rootFile.getCanonicalPath();
} catch (IOException ioe) {
root = rootFile.getAbsolutePath();
}
if (root == null) {
return null;
}
File rootFile = new File(root);
try {
return rootFile.getCanonicalPath();
} catch (IOException ioe) {
return rootFile.getAbsolutePath();
}
return root;
}

public static void determinePlatform(Properties props) {
Expand Down Expand Up @@ -554,8 +554,7 @@ private static void initRegistry(Properties preProperties, Properties postProper
}
try {
addRegistryFile(new File(prefix, "registry"));
File homeFile = new File(registry.getProperty("user.home"),
".jython");
File homeFile = new File(registry.getProperty("user.home"), ".jython");
addRegistryFile(homeFile);
} catch (Exception exc) {
}
Expand Down Expand Up @@ -615,21 +614,23 @@ public static Properties getBaseProperties(){
}

public static synchronized void initialize() {
initialize(null, null, new String[] {""});
initialize(null, null);
}

public static synchronized void initialize(Properties preProperties, Properties postProperties) {
initialize(preProperties, postProperties, new String[] {""});
}

public static synchronized void initialize(Properties preProperties,
Properties postProperties,
String[] argv)
{
String[] argv) {
initialize(preProperties, postProperties, argv, null);
}

public static synchronized void initialize(Properties preProperties,
Properties postProperties,
String[] argv,
ClassLoader classLoader)
{
ClassLoader classLoader) {
initialize(preProperties, postProperties, argv, classLoader, new ClassicPyObjectAdapter());
}

Expand Down
11 changes: 9 additions & 2 deletions src/org/python/core/imp.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public static byte[] readCode(String name, InputStream fp, boolean testing) thro
return data;
}

public static byte[] compileSource(String name, File file) {
return compileSource(name, file, null);
}

public static byte[] compileSource(String name, File file, String sourceFilename) {
return compileSource(name, file, sourceFilename, null);
}

public static byte[] compileSource(String name, File file, String sourceFilename,
String compiledFilename) {
if (sourceFilename == null) {
Expand Down Expand Up @@ -209,8 +217,7 @@ public static byte[] compileSource(String name, InputStream fp, String filename)
}
}

public static PyObject createFromSource(String name, InputStream fp,
String filename) {
public static PyObject createFromSource(String name, InputStream fp, String filename) {
return createFromSource(name, fp, filename, null);
}

Expand Down
Loading

0 comments on commit d1d3479

Please sign in to comment.