Skip to content

Commit b8de52d

Browse files
committed
[GR-11906] [GR-12029] Migrate to 'ProcessProperties'.
PullRequest: graalpython/222
2 parents 748e302 + 4ceb3e2 commit b8de52d

File tree

4 files changed

+83
-12
lines changed

4 files changed

+83
-12
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.test.module;
42+
43+
import org.graalvm.polyglot.Context;
44+
import org.graalvm.polyglot.Engine;
45+
import org.junit.Test;
46+
47+
import com.oracle.graal.python.test.PythonTests;
48+
49+
public class MemoryviewTest extends PythonTests {
50+
@Test
51+
public void testContextReuse() {
52+
Engine engine = Engine.newBuilder().build();
53+
try (Context context = newContext(engine)) {
54+
context.eval("python", "memoryview(b'abc')");
55+
}
56+
}
57+
58+
private static Context newContext(Engine engine) {
59+
return Context.newBuilder().allowAllAccess(true).engine(engine).build();
60+
}
61+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.concurrent.atomic.AtomicLong;
3636
import java.util.concurrent.locks.ReentrantLock;
3737

38+
import org.graalvm.nativeimage.ProcessProperties;
3839
import org.graalvm.options.OptionValues;
3940

4041
import com.oracle.graal.python.PythonLanguage;
@@ -50,8 +51,8 @@
5051
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5152
import com.oracle.truffle.api.Truffle;
5253
import com.oracle.truffle.api.TruffleLanguage;
53-
import com.oracle.truffle.api.TruffleLanguage.Env;
5454
import com.oracle.truffle.api.TruffleOptions;
55+
import com.oracle.truffle.api.TruffleLanguage.Env;
5556

5657
public final class PythonContext {
5758

@@ -191,8 +192,8 @@ public void patch(Env newEnv) {
191192

192193
private void setupRuntimeInformation() {
193194
PythonModule sysModule = core.initializeSysModule();
194-
if (TruffleOptions.AOT) {
195-
sysModule.setAttribute("executable", Compiler.command(new Object[]{"com.oracle.svm.core.posix.GetExecutableName"}));
195+
if (TruffleOptions.AOT && !language.isNativeBuildTime()) {
196+
sysModule.setAttribute("executable", ProcessProperties.getExecutableName());
196197
}
197198
sysModules = (PDict) sysModule.getAttribute("modules");
198199
builtinsModule = (PythonModule) sysModules.getItem("builtins");

mx.graalpython/mx_graalpython.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,13 @@ def graalpython_gate_runner(args, tasks):
393393

394394
with Task('GraalPython C extension tests', tasks, tags=[GraalPythonTags.cpyext]) as task:
395395
if task:
396+
# we deliberately added this to test the combination of Sulong and 'mx_unittest'
397+
unittest(['--regex', re.escape('com.oracle.graal.python.test.module.MemoryviewTest'),
398+
"-Dgraal.TraceTruffleCompilation=true"])
399+
396400
gate_unittests(subdir="cpyext/")
397401

402+
398403
with Task('GraalPython C extension managed tests', tasks, tags=[GraalPythonTags.cpyext_managed]) as task:
399404
if task:
400405
mx.run_mx(["--dynamicimports", "sulong-managed", "python-gate-unittests", "--llvm.configuration=managed", "--subdir=cpyext", "--"])
@@ -407,13 +412,12 @@ def graalpython_gate_runner(args, tasks):
407412
if task:
408413
svm_image_name = "./graalpython-svm"
409414
if not os.path.exists(svm_image_name):
410-
python_svm(["-h"])
411-
else:
412-
llvm_home = mx_subst.path_substitutions.substitute('--native.Dllvm.home=<path:SULONG_LIBS>')
413-
args = ["--python.CoreHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-graalpython"),
414-
"--python.StdLibHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-python/3"),
415-
llvm_home]
416-
run_python_unittests(svm_image_name, args)
415+
svm_image_name = python_svm(["-h"])
416+
llvm_home = mx_subst.path_substitutions.substitute('--native.Dllvm.home=<path:SULONG_LIBS>')
417+
args = ["--python.CoreHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-graalpython"),
418+
"--python.StdLibHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-python/3"),
419+
llvm_home]
420+
run_python_unittests(svm_image_name, args)
417421

418422
with Task('GraalPython apptests', tasks, tags=[GraalPythonTags.apptests]) as task:
419423
if task:
@@ -448,6 +452,11 @@ def graalpython_gate_runner(args, tasks):
448452
])
449453
if success not in out.data:
450454
mx.abort('Output from generated SVM image "' + svm_image + '" did not match success pattern:\n' + success)
455+
llvm_home = mx_subst.path_substitutions.substitute('--native.Dllvm.home=<path:SULONG_LIBS>')
456+
args = ["--python.CoreHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-graalpython"),
457+
"--python.StdLibHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-python/3"),
458+
llvm_home]
459+
run_python_unittests(svm_image, args)
451460

452461

453462
mx_gate.add_gate_runner(_suite, graalpython_gate_runner)

mx.graalpython/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
},
2626
{
2727
"name": "sulong",
28-
"version": "a8a599d132146bb0f87a2b95572db7d76b641b88",
28+
"version": "97d30b8572cbae48cf8d8360f1dd4411f7cbaeec",
2929
"subdir": True,
3030
"urls": [
3131
{"url": "https://github.com/oracle/graal", "kind": "git"},
3232
]
3333
},
3434
{
3535
"name": "regex",
36-
"version": "a8a599d132146bb0f87a2b95572db7d76b641b88",
36+
"version": "97d30b8572cbae48cf8d8360f1dd4411f7cbaeec",
3737
"subdir": True,
3838
"urls": [
3939
{"url": "https://github.com/oracle/graal", "kind": "git"},

0 commit comments

Comments
 (0)