Add uncommited generation checking to all the gen tasks.
If checking="true" on them, they generate their code to a String instead of a file, and compare that against existing output. If any generation would produce changes, the build is failed. As a side effect, generation will now only write files if it's going to modify them, which should eliminate some spurious compiling. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6349 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -6,19 +6,10 @@ import java.lang.reflect.TypeVariable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.io.Resources;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
|
||||
import com.threerings.presents.dobj.DSet;
|
||||
|
||||
public class CPPUtil
|
||||
@@ -70,19 +61,6 @@ public class CPPUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTemplate (String tmplPath, File root, String path,
|
||||
Map<String, Object> ctx)
|
||||
throws IOException
|
||||
{
|
||||
String tmpl =
|
||||
Resources.toString(Resources.getResource(tmplPath), Charsets.UTF_8);
|
||||
File file = new File(root, path);
|
||||
file.getParentFile().mkdirs();
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||
Mustache.compiler().escapeHTML(false).compile(tmpl).execute(ctx, out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static String makeCPPName (Class<?> sclass)
|
||||
{
|
||||
return makeCPPName(makeNamespaces(sclass), sclass.getSimpleName());
|
||||
@@ -103,6 +81,17 @@ public class CPPUtil
|
||||
return Joiner.on(File.separator).join(namespaces) + File.separator + className+ ext;
|
||||
}
|
||||
|
||||
public static String makePath (File root, Class<?> klass, String ext)
|
||||
{
|
||||
return new File(root, makePath(klass, ext)).getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
public static String makePath (File root, List<String> namespaces, String className, String ext)
|
||||
{
|
||||
return new File(root, makePath(namespaces, className, ext)).getAbsolutePath();
|
||||
}
|
||||
|
||||
public static List<String> makeNamespaces (String pack)
|
||||
{
|
||||
Iterable<String> split = Splitter.on(".").split(pack);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.threerings.presents.tools.cpp;
|
||||
|
||||
import static com.threerings.presents.tools.cpp.CPPUtil.makePath;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -39,8 +41,7 @@ public class GenCPPReceiverTask extends GenReceiverTask
|
||||
ctx.put("receiverCode", rcode);
|
||||
ctx.put("argbuilder", new CPPArgBuilder(false));
|
||||
|
||||
CPPUtil.writeTemplate(DECODER_HEADER_TMPL, _cpproot,
|
||||
CPPUtil.makePath(namespaces, dname, ".h"), ctx);
|
||||
writeTemplate(DECODER_HEADER_TMPL, makePath(_cpproot, namespaces, dname, ".h"), ctx);
|
||||
|
||||
Set<String> receiverHeaderIncludes = Sets.newTreeSet();
|
||||
Set<String> decoderImplIncludes = Sets.newTreeSet();
|
||||
@@ -60,13 +61,9 @@ public class GenCPPReceiverTask extends GenReceiverTask
|
||||
}
|
||||
|
||||
ctx.put("includes", decoderImplIncludes);
|
||||
CPPUtil.writeTemplate(DECODER_CPP_TMPL, _cpproot,
|
||||
CPPUtil.makePath(namespaces, dname, ".cpp"), ctx);
|
||||
|
||||
|
||||
writeTemplate(DECODER_CPP_TMPL, makePath(_cpproot, namespaces, dname, ".cpp"), ctx);
|
||||
ctx.put("includes", receiverHeaderIncludes);
|
||||
CPPUtil.writeTemplate(RECEIVER_HEADER_TMPL, _cpproot,
|
||||
CPPUtil.makePath(namespaces, rname, ".h"), ctx);
|
||||
writeTemplate(RECEIVER_HEADER_TMPL, makePath(_cpproot, namespaces, rname, ".h"), ctx);
|
||||
|
||||
super.generateDecoder(receiver, source, rname, rpackage, methods, imports, rcode);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.threerings.presents.tools.GenServiceTask;
|
||||
|
||||
import static com.threerings.presents.tools.cpp.CPPUtil.makeNamespaces;
|
||||
import static com.threerings.presents.tools.cpp.CPPUtil.makePath;
|
||||
import static com.threerings.presents.tools.cpp.CPPUtil.writeTemplate;
|
||||
|
||||
public class GenCPPServiceTask extends GenServiceTask
|
||||
{
|
||||
@@ -58,9 +57,9 @@ public class GenCPPServiceTask extends GenServiceTask
|
||||
}
|
||||
}
|
||||
ctx.put("includes", implIncludes);
|
||||
writeTemplate(CPP_TMPL, _cpproot, makePath(namespaces, name, ".cpp"), ctx);
|
||||
writeTemplate(CPP_TMPL, makePath(_cpproot, namespaces, name, ".cpp"), ctx);
|
||||
ctx.put("includes", includes);
|
||||
writeTemplate(HEADER_TMPL, _cpproot, makePath(namespaces, name, ".h"), ctx);
|
||||
writeTemplate(HEADER_TMPL, makePath(_cpproot, namespaces, name, ".h"), ctx);
|
||||
super.generateMarshaller(source, sdesc);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,10 +134,10 @@ public class GenCPPStreamableTask extends GenTask
|
||||
|
||||
// now write all that out to the target source file
|
||||
ctx.put("includes", headerIncludes);
|
||||
CPPUtil.writeTemplate(HEADER_TMPL, _cpproot, makePath(sclass, ".h"), ctx);
|
||||
writeTemplate(HEADER_TMPL, makePath(_cpproot, sclass, ".h"), ctx);
|
||||
|
||||
ctx.put("includes", implIncludes);
|
||||
CPPUtil.writeTemplate(CPP_TMPL, _cpproot, makePath(sclass, ".cpp"), ctx);
|
||||
writeTemplate(CPP_TMPL, makePath(_cpproot, sclass, ".cpp"), ctx);
|
||||
}
|
||||
|
||||
protected static void addInclude (Class<?> ftype, Set<String> includes)
|
||||
|
||||
Reference in New Issue
Block a user