GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
BuildUtil.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.gluegen;
30
31import com.jogamp.gluegen.JavaEmitter;
32import com.jogamp.gluegen.GlueGen;
33import java.io.File;
34import java.net.URISyntaxException;
35import org.apache.tools.ant.DefaultLogger;
36import org.apache.tools.ant.Project;
37import org.apache.tools.ant.ProjectHelper;
38
39import static java.lang.System.*;
40
41/**
42 * @author Michael Bien
43 */
44public final class BuildUtil {
45
46 private static final Project project;
47
48 public static final String gluegenRoot;
49 public static final String path;
50 public static final String testOutput;
51 public static final String rootrel_build;
52
53 static {
54
55 out.println(" - - - System info - - - ");
56 out.println("OS: " + System.getProperty("os.name"));
57 out.println("VM: " + System.getProperty("java.vm.name"));
58
59 String rootrel_build_tmp = System.getProperty("rootrel.build");
60 if(null==rootrel_build_tmp || rootrel_build_tmp.length()==0) {
61 rootrel_build_tmp = "build" ;
62 }
63 rootrel_build = rootrel_build_tmp;
64 out.println("rootrel.build: " + rootrel_build);
65
66 // setup paths
67 try {
68 final File executionRoot = new File(BuildUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI());
69 out.println("execution root: " + executionRoot);
70 gluegenRoot = executionRoot.getParentFile().getParentFile().getParentFile().getParentFile().toString();
71 out.println("gluegen project root: " + gluegenRoot);
72 } catch (final URISyntaxException ex) {
73 throw new RuntimeException("can not determine gluegen root", ex);
74 }
75
76 path = gluegenRoot + "/test/junit/com/jogamp/gluegen";
77 testOutput = gluegenRoot + "/" + rootrel_build + "/test";
78
79 out.println("path: "+path);
80 out.println("testOutput: "+testOutput);
81 out.println(" - - - - - - - - - - - - ");
82
84
85 //setup ant build file
86 project = new Project();
87 project.setProperty("rootrel.build", rootrel_build);
88 passSystemProperty(project, "gluegen-cpptasks.file");
89 passSystemProperty(project, "os.arch");
90
91 final DefaultLogger logger = new DefaultLogger();
92 logger.setErrorPrintStream(out);
93 logger.setOutputPrintStream(out);
94 logger.setMessageOutputLevel(Project.MSG_WARN);
95 project.addBuildListener(logger);
96
97 project.init();
98
99 final File buildFile = new File(path, "build.xml");
100 if(!buildFile.exists()) {
101 throw new RuntimeException("buildfile "+buildFile+" does not exist");
102 }
103
104 ProjectHelper.configureProject(project, buildFile);
105 }
106
107 public static Project passSystemProperty(final Project p, final String name) {
108 final String tmp = System.getProperty(name);
109 if(null!=tmp && tmp.length()>0) {
110 p.setProperty(name, tmp);
111 }
112 return p;
113 }
114
115 public static void cleanGeneratedFiles() {
116 out.println("cleaning generated files");
117 deleteDirectory(new File(testOutput+"/gensrc"));
118 out.println("done");
119 }
120
121 /**
122 * fails if ant script fails (which is a good thing).
123 * executeTarget throws RuntimeException on failure
124 */
125 public static void compileJava() {
126 out.println("compiling java files");
127 project.executeTarget("compile.java");
128 out.println("done");
129 }
130
131 /**
132 * fails if ant script fails (which is a good thing)
133 * executeTarget throws RuntimeException on failure
134 */
135 public static void compileNatives() {
136 out.println("compiling native files");
137 project.executeTarget("compile.native");
138 out.println("done");
139 }
140
141 public static void generate(final String bindingName) {
142 generate(bindingName, JavaEmitter.class.getName());
143// generate(bindingName, DebugEmitter.class.getName());
144 }
145
146 public static void generate(final String bindingName, final String emitter) {
147 generate(bindingName, bindingName, emitter);
148 }
149 public static void generate(final String bindingName, final String header, final String emitter) {
150
151 out.println("generate binding to '" + bindingName+"' using '"+emitter+"'");
152
153 GlueGen.main( "-I"+path,
154 "-O"+testOutput+"/gensrc",
155 "-E"+emitter,
156 "-C"+path+"/"+bindingName+".cfg",
157 path+"/"+header+".h" );
158
159 out.println("done");
160 }
161
162 public static void deleteDirectory(final File path) {
163 if(path.exists()) {
164
165 final File[] files = path.listFiles();
166 for (int i = 0; i < files.length; i++) {
167 if (files[i].isDirectory()) {
168 deleteDirectory(files[i]);
169 } else {
170 files[i].delete();
171 }
172 }
173
174 path.delete();
175 }
176 }
177
178
179}
static void cleanGeneratedFiles()
Definition: BuildUtil.java:115
static void generate(final String bindingName)
Definition: BuildUtil.java:141
static void compileJava()
fails if ant script fails (which is a good thing).
Definition: BuildUtil.java:125
static final String path
Definition: BuildUtil.java:49
static void compileNatives()
fails if ant script fails (which is a good thing) executeTarget throws RuntimeException on failure
Definition: BuildUtil.java:135
static void deleteDirectory(final File path)
Definition: BuildUtil.java:162
static void generate(final String bindingName, final String emitter)
Definition: BuildUtil.java:146
static void generate(final String bindingName, final String header, final String emitter)
Definition: BuildUtil.java:149
static final String rootrel_build
Definition: BuildUtil.java:51
static Project passSystemProperty(final Project p, final String name)
Definition: BuildUtil.java:107
static final String testOutput
Definition: BuildUtil.java:50
static final String gluegenRoot
Definition: BuildUtil.java:48
Glue code generator for C functions and data structures.
Definition: GlueGen.java:59
static void main(final String... args)
Definition: GlueGen.java:383