Skip to content

Commit 5c95626

Browse files
committed
Add flag to build C API on-demand via launcher.
1 parent d9de738 commit 5c95626

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static void main(String[] args) {
7171
private boolean quietFlag = false;
7272
private boolean noUserSite = false;
7373
private boolean noSite = false;
74+
private boolean ensureCapi = false;
7475
private boolean stdinIsInteractive = System.console() != null;
7576
private boolean runLLI = false;
7677
private boolean unbufferedIO = false;
@@ -159,6 +160,13 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
159160
unrecognized.add(arg);
160161
}
161162
break;
163+
case "-ensure-capi":
164+
if (wantsExperimental) {
165+
ensureCapi = true;
166+
} else {
167+
unrecognized.add(arg);
168+
}
169+
break;
162170
case "-debug-java":
163171
if (wantsExperimental) {
164172
if (!isAOT()) {
@@ -400,6 +408,9 @@ protected void launch(Builder contextBuilder) {
400408
print("Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.");
401409
}
402410
}
411+
if (ensureCapi) {
412+
evalInternal(context, "import build_capi; build_capi.ensure_capi([" + (quietFlag ? "'-q'" : "") + "])\n");
413+
}
403414
if (!noSite) {
404415
evalInternal(context, "import site\n");
405416
}

graalpython/lib-python/3/build_capi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ def configure_logging(args):
6565
logging.basicConfig(level=logging.INFO)
6666

6767

68+
def ensure_capi(args=[]):
69+
configure_logging(args)
70+
from distutils.sysconfig import get_config_var
71+
if not os.path.exists(os.path.join(capi_home, "libpython" + get_config_var("EXT_SUFFIX"))):
72+
return load_setup().build(capi_home, capi_module_home)
73+
return 0
74+
75+
6876
def build(args=[]):
6977
configure_logging(args)
7078
return load_setup().build(capi_home, capi_module_home)

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs):
132132
mx.logv("CHROMEINSPECTOR was not built, not including it automatically")
133133

134134
graalpython_args.insert(0, '--experimental-options=true')
135+
graalpython_args.insert(1, '-ensure-capi')
135136

136137
vm_args += mx.get_runtime_jvm_args(dists, jdk=jdk)
137138

0 commit comments

Comments
 (0)