[Jython-checkins] jython: Fixed issue 2535. Now stores e.g. 'distutils/sysconfig.py' instead of
stefan.richthofer
jython-checkins at python.org
Thu Dec 1 08:58:45 EST 2016
https://hg.python.org/jython/rev/45e1a6b52935
changeset: 7974:45e1a6b52935
user: Stefan Richthofer <stefan.richthofer at gmx.de>
date: Thu Dec 01 14:57:20 2016 +0100
summary:
Fixed issue 2535. Now stores e.g. 'distutils/sysconfig.py' instead of 'local_home_path/of/who/ever/built/this/jython/distribution/jython/dist/Lib/distutils/sysconfig.py' as source-filename in class-files compiled from Python-source. Normalizes path-separator to '/' to have same strings regardless which platform was used for building (i.e. in the style of URL-notaion).
files:
src/org/python/compiler/ClassFile.java | 24 ++++++++++++-
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/org/python/compiler/ClassFile.java b/src/org/python/compiler/ClassFile.java
--- a/src/org/python/compiler/ClassFile.java
+++ b/src/org/python/compiler/ClassFile.java
@@ -4,6 +4,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.File;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -213,6 +215,22 @@
public void write(OutputStream stream)
throws IOException
{
+ String sfilenameShort = sfilename;
+ if (sfilename != null) {
+ try {
+ Path pth = new File("dist/Lib").toPath().normalize().toAbsolutePath();
+ Path pth2 = new File(sfilename).toPath().normalize().toAbsolutePath();
+ sfilenameShort = pth.relativize(pth2).toString();
+ if (sfilenameShort.startsWith("..")) {
+ // prefer absolute path in this case
+ sfilenameShort = sfilename;
+ }
+ if (File.separatorChar != '/') {
+ // Make the path uniform on all platforms. We use POSIX- and URL-notation here.
+ sfilenameShort = sfilenameShort.replace(File.separatorChar, '/');
+ }
+ } catch (Exception fe) {}
+ }
cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, this.name, null, this.superclass, interfaces);
AnnotationVisitor av = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true);
// XXX: should imp.java really house this value or should imp.java point into
@@ -224,11 +242,11 @@
av.visit("value", new Long(mtime));
av.visitEnd();
- if (sfilename != null) {
+ if (sfilenameShort != null) {
av = cw.visitAnnotation("Lorg/python/compiler/Filename;", true);
- av.visit("value", sfilename);
+ av.visit("value", sfilenameShort);
av.visitEnd();
- cw.visitSource(sfilename, null);
+ cw.visitSource(sfilenameShort, null);
}
endClassAnnotations();
endFields();
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list