@@ -2455,3 +2455,57 @@ def svm_libcontainer_namespace(args):
2455
2455
libcontainer_project = mx .project ("com.oracle.svm.native.libcontainer" )
2456
2456
for src_dir in libcontainer_project .source_dirs ():
2457
2457
mx .command_function ("svm_namespace" )(args + ["--directory" , src_dir , "--namespace" , "svm_container" ])
2458
+
2459
+ @mx .command (suite , 'capnp-compile' , usage_msg = "Compile Cap'n Proto schema files to source code." )
2460
+ def capnp_compile (args ):
2461
+ capnpcjava_home = os .environ .get ('CAPNPROTOJAVA_HOME' )
2462
+ if capnpcjava_home is None or not exists (capnpcjava_home + '/capnpc-java' ):
2463
+ mx .abort ('Clone and build capnproto/capnproto-java from GitHub and point CAPNPROTOJAVA_HOME to its path.' )
2464
+ srcdir = 'src/com.oracle.svm.hosted/resources/'
2465
+ outdir = 'src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/'
2466
+ command = ['capnp' , 'compile' ,
2467
+ '--import-path=' + capnpcjava_home + '/compiler/src/main/schema/' ,
2468
+ '--output=' + capnpcjava_home + '/capnpc-java:' + outdir ,
2469
+ '--src-prefix=' + srcdir ,
2470
+ srcdir + 'SharedLayerSnapshotCapnProtoSchema.capnp' ]
2471
+ mx .run (command )
2472
+ # Remove huge unused schema chunks from generated code
2473
+ outpath = outdir + 'SharedLayerSnapshotCapnProtoSchemaHolder.java' # name specified in schema
2474
+ with open (outpath , 'r' ) as f :
2475
+ lines = f .readlines ()
2476
+ with open (outpath , 'w' ) as f :
2477
+ f .write (
2478
+ """/*
2479
+ * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
2480
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2481
+ *
2482
+ * This code is free software; you can redistribute it and/or modify it
2483
+ * under the terms of the GNU General Public License version 2 only, as
2484
+ * published by the Free Software Foundation. Oracle designates this
2485
+ * particular file as subject to the "Classpath" exception as provided
2486
+ * by Oracle in the LICENSE file that accompanied this code.
2487
+ *
2488
+ * This code is distributed in the hope that it will be useful, but WITHOUT
2489
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2490
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2491
+ * version 2 for more details (a copy is included in the LICENSE file that
2492
+ * accompanied this code).
2493
+ *
2494
+ * You should have received a copy of the GNU General Public License version
2495
+ * 2 along with this work; if not, write to the Free Software Foundation,
2496
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2497
+ *
2498
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2499
+ * or visit www.oracle.com if you need additional information or have any
2500
+ * questions.
2501
+ */
2502
+ //@formatter:off
2503
+ //Checkstyle: stop
2504
+ """ )
2505
+ for line in lines :
2506
+ if line .startswith ("public final class " ):
2507
+ f .write ('@SuppressWarnings("all")\n ' )
2508
+ if 'public static final class Schemas {' in line :
2509
+ break
2510
+ f .write (line )
2511
+ f .write ('}\n ' )
0 commit comments