Skip to content

Commit 1be446d

Browse files
committed
make python resources into their own optional distribution
1 parent 5993d03 commit 1be446d

File tree

10 files changed

+318
-16
lines changed

10 files changed

+318
-16
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
3+
4+
<!--
5+
This configuration file was written by the eclipse-cs plugin configuration editor
6+
-->
7+
<!--
8+
Checkstyle-Configuration: Checks
9+
Description: none
10+
-->
11+
<module name="Checker">
12+
<module name="LineLength">
13+
<property name="max" value="300"/>
14+
</module>
15+
<property name="severity" value="error"/>
16+
<module name="TreeWalker">
17+
<module name="IllegalType">
18+
<property name="illegalClassNames" value="TruffleObject"/>
19+
<property name="tokens" value="VARIABLE_DEF,METHOD_DEF,PARAMETER_DEF"/>
20+
</module>
21+
<module name="AvoidStarImport">
22+
<property name="allowClassImports" value="true"/>
23+
<property name="allowStaticMemberImports" value="true"/>
24+
</module>
25+
<property name="tabWidth" value="4"/>
26+
<module name="LocalFinalVariableName"/>
27+
<module name="LocalVariableName">
28+
<property name="format" value="^(([_a-zA-Z][_a-zA-Z0-9]*$)|(_[A-Z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*$))"/>
29+
</module>
30+
<module name="MemberName">
31+
<property name="format" value="^(([_a-zA-Z][_a-zA-Z0-9]*$)|(_[A-Z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*$))"/>
32+
</module>
33+
<module name="MethodName">
34+
<property name="format" value="^(([_a-zA-Z][_a-zA-Z0-9]*$)|(_[A-Z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*$))"/>
35+
</module>
36+
<module name="PackageName"/>
37+
<module name="ParameterName">
38+
<property name="format" value="^(([_a-zA-Z][_a-zA-Z0-9]*$)|(_[A-Z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*$))"/>
39+
</module>
40+
<module name="TypeName">
41+
<property name="format" value="^[_a-zA-Z][_a-zA-Z0-9]*$"/>
42+
</module>
43+
<module name="RedundantImport"/>
44+
<module name="UnusedImports"/>
45+
<module name="MethodParamPad"/>
46+
<module name="NoWhitespaceAfter">
47+
<property name="tokens" value="ARRAY_INIT,BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
48+
</module>
49+
<module name="NoWhitespaceBefore">
50+
<property name="tokens" value="SEMI,DOT,POST_DEC,POST_INC"/>
51+
</module>
52+
<module name="ParenPad"/>
53+
<module name="TypecastParenPad">
54+
<property name="tokens" value="RPAREN,TYPECAST"/>
55+
</module>
56+
<module name="WhitespaceAfter"/>
57+
<module name="WhitespaceAround">
58+
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
59+
</module>
60+
<module name="AvoidNestedBlocks">
61+
<property name="allowInSwitchCase" value="true"/>
62+
</module>
63+
<module name="EmptyBlock">
64+
<property name="option" value="text"/>
65+
<property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_TRY,LITERAL_WHILE,STATIC_INIT"/>
66+
</module>
67+
<module name="LeftCurly"/>
68+
<module name="NeedBraces"/>
69+
<module name="RightCurly"/>
70+
<module name="EmptyStatement"/>
71+
<module name="HiddenField">
72+
<property name="severity" value="ignore"/>
73+
<property name="ignoreConstructorParameter" value="true"/>
74+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
75+
</module>
76+
<module name="HideUtilityClassConstructor">
77+
<property name="severity" value="ignore"/>
78+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
79+
</module>
80+
<module name="ArrayTypeStyle"/>
81+
<module name="UpperEll"/>
82+
<module name="FallThrough"/>
83+
<module name="FinalLocalVariable">
84+
<property name="severity" value="ignore"/>
85+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
86+
</module>
87+
<module name="StringLiteralEquality">
88+
<property name="severity" value="error"/>
89+
</module>
90+
<module name="SuperFinalize"/>
91+
<module name="UnnecessaryParentheses">
92+
<property name="severity" value="ignore"/>
93+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
94+
</module>
95+
<module name="Indentation">
96+
<property name="severity" value="ignore"/>
97+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
98+
</module>
99+
<module name="StaticVariableName">
100+
<property name="format" value="^[A-Za-z][_a-zA-Z0-9]*$"/>
101+
</module>
102+
<module name="EmptyForInitializerPad"/>
103+
<module name="EmptyForIteratorPad"/>
104+
<module name="ModifierOrder"/>
105+
<module name="DefaultComesLast"/>
106+
<module name="InnerAssignment">
107+
<property name="severity" value="ignore"/>
108+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
109+
</module>
110+
<module name="MutableException">
111+
<property name="severity" value="ignore"/>
112+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
113+
</module>
114+
<module name="ParameterAssignment">
115+
<property name="severity" value="ignore"/>
116+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
117+
</module>
118+
<module name="RegexpSinglelineJava">
119+
<metadata name="net.sf.eclipsecs.core.comment" value="Illegal trailing whitespace(s) at the end of the line."/>
120+
<property name="format" value="\s$"/>
121+
<property name="message" value="Illegal trailing whitespace(s) at the end of the line."/>
122+
<property name="ignoreComments" value="true"/>
123+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Checks for trailing spaces at the end of a line"/>
124+
</module>
125+
<module name="RegexpSinglelineJava">
126+
<metadata name="net.sf.eclipsecs.core.comment" value="illegal space before a comma"/>
127+
<property name="format" value=" ,"/>
128+
<property name="message" value="illegal space before a comma"/>
129+
<property name="ignoreComments" value="true"/>
130+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Checks for whitespace before a comma."/>
131+
<metadata name="com.atlassw.tools.eclipse.checkstyle.customMessage" value="Illegal whitespace before a comma."/>
132+
</module>
133+
<module name="RegexpSinglelineJava">
134+
<property name="format" value="new (Hashtable|Vector|Stack|StringBuffer)[^\w]"/>
135+
<property name="message" value="Don't use old synchronized collection classes"/>
136+
</module>
137+
<module name="SuppressionCommentFilter">
138+
<property name="offCommentFormat" value="Checkstyle: stop constant name check"/>
139+
<property name="onCommentFormat" value="Checkstyle: resume constant name check"/>
140+
<property name="checkFormat" value="ConstantNameCheck"/>
141+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Allow non-conforming constant names"/>
142+
</module>
143+
<module name="SuppressionCommentFilter">
144+
<property name="offCommentFormat" value="Checkstyle: stop method name check"/>
145+
<property name="onCommentFormat" value="Checkstyle: resume method name check"/>
146+
<property name="checkFormat" value="MethodName"/>
147+
<property name="checkC" value="false"/>
148+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable method name checks"/>
149+
</module>
150+
<module name="SuppressionCommentFilter">
151+
<property name="offCommentFormat" value="CheckStyle: stop parameter assignment check"/>
152+
<property name="onCommentFormat" value="CheckStyle: resume parameter assignment check"/>
153+
<property name="checkFormat" value="ParameterAssignment"/>
154+
<property name="checkC" value="false"/>
155+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable Parameter Assignment"/>
156+
</module>
157+
<module name="SuppressionCommentFilter">
158+
<property name="offCommentFormat" value="Checkstyle: stop final variable check"/>
159+
<property name="onCommentFormat" value="Checkstyle: resume final variable check"/>
160+
<property name="checkFormat" value="FinalLocalVariable"/>
161+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable final variable checks"/>
162+
</module>
163+
<module name="SuppressionCommentFilter">
164+
<property name="offCommentFormat" value="CheckStyle: stop inner assignment check"/>
165+
<property name="onCommentFormat" value="CheckStyle: resume inner assignment check"/>
166+
<property name="checkFormat" value="InnerAssignment"/>
167+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable inner assignment checks"/>
168+
</module>
169+
<module name="SuppressionCommentFilter">
170+
<property name="offCommentFormat" value="Checkstyle: stop field name check"/>
171+
<property name="onCommentFormat" value="Checkstyle: resume field name check"/>
172+
<property name="checkFormat" value="MemberName"/>
173+
<property name="checkC" value="false"/>
174+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable field name checks"/>
175+
</module>
176+
<module name="SuppressionCommentFilter">
177+
<property name="offCommentFormat" value="CheckStyle: stop header check"/>
178+
<property name="onCommentFormat" value="CheckStyle: resume header check"/>
179+
<property name="checkFormat" value=".*Header"/>
180+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable header checks"/>
181+
</module>
182+
<module name="SuppressionCommentFilter">
183+
<property name="offCommentFormat" value="CheckStyle: stop line length check"/>
184+
<property name="onCommentFormat" value="CheckStyle: resume line length check"/>
185+
<property name="checkFormat" value="LineLength"/>
186+
</module>
187+
<module name="SuppressionCommentFilter">
188+
<property name="offCommentFormat" value="CheckStyle: start generated"/>
189+
<property name="onCommentFormat" value="CheckStyle: stop generated"/>
190+
<property name="checkFormat" value=".*Name|.*LineLength|.*Header"/>
191+
</module>
192+
</module>
193+
<module name="FileTabCharacter">
194+
<property name="severity" value="error"/>
195+
<property name="fileExtensions" value="java"/>
196+
</module>
197+
<module name="NewlineAtEndOfFile">
198+
<property name="lineSeparator" value="lf"/>
199+
</module>
200+
<module name="Translation"/>
201+
<module name="RegexpMultiline">
202+
<metadata name="net.sf.eclipsecs.core.comment" value="illegal Windows line ending"/>
203+
<property name="format" value="\r\n"/>
204+
<property name="message" value="illegal Windows line ending"/>
205+
</module>
206+
<module name="SuppressWithPlainTextCommentFilter">
207+
<property name="offCommentFormat" value="Checkstyle: stop"/>
208+
<property name="onCommentFormat" value="Checkstyle: resume"/>
209+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable all checks"/>
210+
</module>
211+
</module>

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonResource.java renamed to graalpython/com.oracle.graal.python.resources/src/com/oracle/graal/python/resources/PythonResource.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3939
* SOFTWARE.
4040
*/
41-
package com.oracle.graal.python;
41+
package com.oracle.graal.python.resources;
4242

4343
import java.io.IOException;
4444
import java.nio.file.InvalidPathException;
@@ -56,6 +56,13 @@
5656
*/
5757
@Id("python-home")
5858
public final class PythonResource implements InternalResource {
59+
// These fields should be initialized by the language using these resource so the layout will
60+
// match up
61+
public static int PYTHON_MAJOR = 0;
62+
public static int PYTHON_MINOR = 0;
63+
public static int GRAALVM_MAJOR = 0;
64+
public static int GRAALVM_MINOR = 0;
65+
5966
private static final Path BASE_PATH = Path.of("META-INF", "resources");
6067
private static final String LIBGRAALPY = "libgraalpy";
6168
private static final String LIBPYTHON = "libpython";
@@ -76,8 +83,8 @@ public void unpackFiles(Env env, Path targetDirectory) throws IOException {
7683
env.unpackResourceFiles(BASE_PATH.resolve(LIBPYTHON_FILES), targetDirectory.resolve("Lib"), BASE_PATH.resolve(LIBPYTHON));
7784
env.unpackResourceFiles(BASE_PATH.resolve(LIBGRAALPY_FILES), targetDirectory.resolve("lib-graalpython"), BASE_PATH.resolve(LIBGRAALPY));
7885
} else {
79-
env.unpackResourceFiles(BASE_PATH.resolve(LIBPYTHON_FILES), targetDirectory.resolve("lib").resolve("python" + PythonLanguage.MAJOR + "." + PythonLanguage.MINOR), BASE_PATH.resolve(LIBPYTHON));
80-
env.unpackResourceFiles(BASE_PATH.resolve(LIBGRAALPY_FILES), targetDirectory.resolve("lib").resolve("graalpy" + PythonLanguage.GRAALVM_MAJOR + "." + PythonLanguage.GRAALVM_MINOR), BASE_PATH.resolve(LIBGRAALPY));
86+
env.unpackResourceFiles(BASE_PATH.resolve(LIBPYTHON_FILES), targetDirectory.resolve("lib").resolve("python" + PYTHON_MAJOR + "." + PYTHON_MINOR), BASE_PATH.resolve(LIBPYTHON));
87+
env.unpackResourceFiles(BASE_PATH.resolve(LIBGRAALPY_FILES), targetDirectory.resolve("lib").resolve("graalpy" + GRAALVM_MAJOR + "." + GRAALVM_MINOR), BASE_PATH.resolve(LIBGRAALPY));
8188
}
8289
// include files are in the same place on all platforms
8390
env.unpackResourceFiles(BASE_PATH.resolve(INCLUDE_FILES), targetDirectory, BASE_PATH);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import com.oracle.graal.python.pegparser.sst.ModTy;
8686
import com.oracle.graal.python.pegparser.sst.StmtTy;
8787
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
88+
import com.oracle.graal.python.resources.PythonResource;
8889
import com.oracle.graal.python.runtime.GilNode;
8990
import com.oracle.graal.python.runtime.PythonContext;
9091
import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
@@ -186,6 +187,27 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
186187
public static final int GRAALVM_MAJOR = 23;
187188
public static final int GRAALVM_MINOR = 1;
188189

190+
public static final Class<PythonResource> PYTHON_RESOURCE_CLASS;
191+
192+
@SuppressWarnings("unchecked")
193+
private static Class<PythonResource> getPythonResourceClass() {
194+
Class<PythonResource> pr;
195+
try {
196+
pr = (Class<PythonResource>) Class.forName("com.oracle.graal.python.resources.PythonResource");
197+
} catch (ClassNotFoundException e) {
198+
return null;
199+
}
200+
try {
201+
pr.getDeclaredField("PYTHON_MAJOR").set(pr, MAJOR);
202+
pr.getDeclaredField("PYTHON_MINOR").set(pr, MINOR);
203+
pr.getDeclaredField("GRAALVM_MAJOR").set(pr, GRAALVM_MAJOR);
204+
pr.getDeclaredField("GRAALVM_MINOR").set(pr, GRAALVM_MINOR);
205+
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
206+
return null;
207+
}
208+
return pr;
209+
}
210+
189211
static {
190212
switch (RELEASE_LEVEL) {
191213
case RELEASE_LEVEL_ALPHA:
@@ -201,6 +223,8 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
201223
default:
202224
RELEASE_LEVEL_STRING = tsLiteral("final");
203225
}
226+
227+
PYTHON_RESOURCE_CLASS = getPythonResourceClass();
204228
}
205229
public static final int RELEASE_SERIAL = 0;
206230
public static final int VERSION_HEX = MAJOR << 24 |

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
import org.graalvm.options.OptionKey;
9999

100100
import com.oracle.graal.python.PythonLanguage;
101-
import com.oracle.graal.python.PythonResource;
102101
import com.oracle.graal.python.builtins.Python3Core;
103102
import com.oracle.graal.python.builtins.PythonOS;
104103
import com.oracle.graal.python.builtins.modules.ImpModuleBuiltins;
@@ -1725,11 +1724,14 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
17251724
Supplier<?>[] homeCandidates = new Supplier<?>[] {
17261725
() -> { return home; },
17271726
() -> {
1728-
try {
1729-
return newEnv.getInternalResource(PythonResource.class).getAbsoluteFile();
1730-
} catch (IOException e) {
1731-
return null;
1727+
if (PythonLanguage.PYTHON_RESOURCE_CLASS != null) {
1728+
try {
1729+
return newEnv.getInternalResource(PythonLanguage.PYTHON_RESOURCE_CLASS).getAbsoluteFile();
1730+
} catch (IOException e) {
1731+
// fall through
1732+
}
17321733
}
1734+
return null;
17331735
}
17341736
};
17351737
for (Supplier<?> homeCandidateSupplier : homeCandidates) {

mx.graalpython/native-image.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Args = -H:MaxRuntimeCompileMethods=20000 \
1212
-H:IncludeLocales=no,be,ro,ru,es,se,in,ka,hu,hr,bg,is,mk,da,nn,cs,sq,fr,pl,fo,bs,kl,fa,sv,it,uk,af,tg,ps,de \
1313
--initialize-at-build-time=com.oracle.graal.python,com.oracle.truffle.regex,jline,org.fusesource \
1414
--initialize-at-run-time=org.tukaani.xz \
15-
-H:ReflectionConfigurationResources=com/oracle/graal/python/resources/reflect-config.json \
16-
-H:ResourceConfigurationResources=com/oracle/graal/python/resources/resource-config.json \
17-
-H:JNIConfigurationResources=com/oracle/graal/python/resources/jni-config.json \
15+
-H:ReflectionConfigurationResources=com/oracle/graal/python/niresources/reflect-config.json \
16+
-H:ResourceConfigurationResources=com/oracle/graal/python/niresources/resource-config.json \
17+
-H:JNIConfigurationResources=com/oracle/graal/python/niresources/jni-config.json \
1818
-H:Features=com.oracle.graal.python.BouncyCastleFeature

0 commit comments

Comments
 (0)