Inital work on getting the prebaker to work, still very broken but things have worked

dev/0.11
modmuss50 2018-06-18 16:16:03 +01:00
parent d8609346dd
commit 527000ed24
No known key found for this signature in database
GPG Key ID: 773D17BE8BF49C82
7 changed files with 122 additions and 25 deletions

View File

@ -13,7 +13,7 @@ targetCompatibility = 1.8
group = 'com.openmodloader' group = 'com.openmodloader'
archivesBaseName = project.name archivesBaseName = project.name
version = '0.0.8-SNAPSHOT' version = '0.0.9-SNAPSHOT'
repositories { repositories {
mavenCentral() mavenCentral()
@ -56,6 +56,10 @@ dependencies {
shade 'org.ow2.asm:asm-debug-all:5.2' shade 'org.ow2.asm:asm-debug-all:5.2'
shade 'cuchaz:enigma:0.11.0.33:lib' shade 'cuchaz:enigma:0.11.0.33:lib'
shade 'net.fabricmc:tiny-remapper:+' shade 'net.fabricmc:tiny-remapper:+'
shade 'net.sf.jopt-simple:jopt-simple:5.0.4'
shade 'org.apache.logging.log4j:log4j-api:2.11.0'
shade 'org.apache.logging.log4j:log4j-core:2.11.0'
shade ('net.minecraft:launchwrapper:1.12') { shade ('net.minecraft:launchwrapper:1.12') {
transitive = false transitive = false

View File

@ -210,6 +210,11 @@ public class AbstractPlugin implements Plugin<Project> {
mavenArtifactRepository.setUrl("http://maven.fabricmc.net/"); mavenArtifactRepository.setUrl("http://maven.fabricmc.net/");
}); });
project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("modmuss50");
mavenArtifactRepository.setUrl("https://maven.modmuss50.me");
});
project1.getRepositories().maven(mavenArtifactRepository -> { project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("SpongePowered"); mavenArtifactRepository.setName("SpongePowered");
mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven"); mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven");
@ -241,11 +246,10 @@ public class AbstractPlugin implements Plugin<Project> {
} }
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", "")); project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", ""));
if (extension.fabricVersion != null && !extension.fabricVersion.isEmpty()) { if (extension.omlVersion != null && !extension.omlVersion.isEmpty()) {
//only add this when not in a fabric dev env //only add this when not in a fabric dev env
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.fabricmc:fabric-base:" + extension.version + "-" + extension.fabricVersion + ":deobf"); project1.getDependencies().add(Constants.COMPILE_MODS, "OpenModLoader:OpenModLoader:" + extension.version + "-" + extension.omlVersion);
} }
project1.getDependencies().add(Constants.PROCESS_MODS_DEPENDENCIES, "net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT");
}); });
project.getTasks().getByName("build").doLast(task -> { project.getTasks().getByName("build").doLast(task -> {

View File

@ -31,7 +31,7 @@ import java.io.File;
public class LoomGradleExtension { public class LoomGradleExtension {
public String version; public String version;
public String runDir = "run"; public String runDir = "run";
public String fabricVersion; public String omlVersion;
public String pomfVersion; public String pomfVersion;
public String refmapName; public String refmapName;
public boolean localMappings = false; public boolean localMappings = false;
@ -41,13 +41,13 @@ public class LoomGradleExtension {
public String getVersionString() { public String getVersionString() {
if (isModWorkspace()) { if (isModWorkspace()) {
return version + "-" + fabricVersion; return version + "-" + omlVersion;
} }
return version; return version;
} }
public boolean isModWorkspace() { public boolean isModWorkspace() {
return fabricVersion != null && !fabricVersion.isEmpty(); return omlVersion != null && !omlVersion.isEmpty();
} }
public File getUserCache() { public File getUserCache() {

View File

@ -0,0 +1,63 @@
package net.fabricmc.loom.mixin;
import com.google.common.io.ByteStreams;
import org.spongepowered.asm.service.IClassBytecodeProvider;
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
public class MixinServiceGradle extends MixinServiceLaunchWrapper implements IClassBytecodeProvider {
private static List<JarFile> jars = new ArrayList<>();
@Override
public String getName() {
return "OpenModLoaderGradle";
}
@Override
public InputStream getResourceAsStream(String name) {
for(JarFile file : jars){
ZipEntry entry = file.getEntry(name);
if(entry != null){
try {
InputStream stream = file.getInputStream(entry);
return stream;
} catch (IOException e) {
throw new RuntimeException("Failed to read mod file", e);
}
}
}
return super.getResourceAsStream(name);
}
public static void setupModFiles(Set<File> mods, File minecraft) throws IOException {
jars.clear();
for(File mod : mods){
JarFile jarFile = new JarFile(mod);
jars.add(jarFile);
}
jars.add(new JarFile(minecraft));
}
@Override
public IClassBytecodeProvider getBytecodeProvider() {
return this;
}
public byte[] getClassBytes(String name, String transformedName) throws IOException {
InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class");
byte[] classBytes = ByteStreams.toByteArray(inputStream);
if(classBytes == null){
return super.getClassBytes(name, transformedName);
}
return classBytes;
}
}

View File

@ -16,15 +16,20 @@
package net.fabricmc.loom.util.proccessing; package net.fabricmc.loom.util.proccessing;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Predicate;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.fabricmc.loom.mixin.MixinServiceGradle;
import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraft.launchwrapper.LaunchClassLoader;
import org.objectweb.asm.*; import org.objectweb.asm.*;
import org.spongepowered.asm.launch.GlobalProperties; import org.spongepowered.asm.launch.GlobalProperties;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.EnvironmentStateTweaker; import org.spongepowered.asm.mixin.EnvironmentStateTweaker;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.transformer.MixinTransformer; import org.spongepowered.asm.mixin.transformer.MixinTransformer;
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper; import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
@ -116,8 +121,9 @@ public class MixinPrebaker {
public static final String APPLIED_MIXIN_CONFIGS_FILENAME = ".oml-applied-mixin-configs"; public static final String APPLIED_MIXIN_CONFIGS_FILENAME = ".oml-applied-mixin-configs";
public static final String MAPPINGS_FILENAME = ".oml-dev-mappings.tiny"; public static final String MAPPINGS_FILENAME = ".oml-dev-mappings.tiny";
public static MixinTransformer mixinTransformer;
public static void main(String[] args) { public static void main(String[] args) throws IOException {
boolean hasMappingsFile = false; boolean hasMappingsFile = false;
if (args.length < 3) { if (args.length < 3) {
@ -148,17 +154,8 @@ public class MixinPrebaker {
Launch.blackboard = new HashMap<>(); Launch.blackboard = new HashMap<>();
Launch.blackboard.put(MixinServiceLaunchWrapper.BLACKBOARD_KEY_TWEAKS, Collections.emptyList()); Launch.blackboard.put(MixinServiceLaunchWrapper.BLACKBOARD_KEY_TWEAKS, Collections.emptyList());
List<JsonObject> modInfo = findModInfo(modFiles); List<JsonObject> mods = findModInfo(modFiles);
List<JsonObject> mods = new ArrayList<>(); System.out.println("Found " + mods.size() + " mods");
for(JsonObject modInfoJson : modInfo){
if(!modInfoJson.isJsonArray()){
continue;
}
JsonArray jsonArray = modInfoJson.getAsJsonArray();
for (int i = 0; i < jsonArray.size(); i++) {
mods.add(jsonArray.get(i).getAsJsonObject());
}
}
List<String> mixins = new ArrayList<>(); List<String> mixins = new ArrayList<>();
for(JsonObject modObject : mods){ for(JsonObject modObject : mods){
mixins.addAll(findMixins(modObject.getAsJsonArray("mixins"))); mixins.addAll(findMixins(modObject.getAsJsonArray("mixins")));
@ -167,11 +164,30 @@ public class MixinPrebaker {
} }
System.out.println("Found " + mixins.size() + " mixins to pre bake"); System.out.println("Found " + mixins.size() + " mixins to pre bake");
List<String> tweakers = new ArrayList<>();
tweakers.add("com.openmodloader.loader.launch.OpenTweaker");
GlobalProperties.put("TweakClasses", tweakers);
MixinBootstrap.init();
mixins.forEach(Mixins::addConfiguration);
MixinServiceGradle.setupModFiles(modFiles, new File(args[argOffset + 0]));
EnvironmentStateTweaker tweaker = new EnvironmentStateTweaker(); EnvironmentStateTweaker tweaker = new EnvironmentStateTweaker();
tweaker.getLaunchArguments(); tweaker.getLaunchArguments();
tweaker.injectIntoClassLoader(Launch.classLoader); tweaker.injectIntoClassLoader(Launch.classLoader);
MixinTransformer mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER); if(mixinTransformer == null){
mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER);
}
//Check to ensure its not null
if(mixinTransformer == null){
throw new RuntimeException("Failed to get MixinTransformer!");
}
MixinEnvironment mixinEnvironment = MixinEnvironment.getDefaultEnvironment();
mixinEnvironment.setSide(MixinEnvironment.Side.CLIENT); //TODO have an all side?
mixinTransformer.audit(mixinEnvironment);
try { try {
JarInputStream input = new JarInputStream(new FileInputStream(new File(args[argOffset + 0]))); JarInputStream input = new JarInputStream(new FileInputStream(new File(args[argOffset + 0])));
@ -233,21 +249,29 @@ public class MixinPrebaker {
} }
private static List<JsonObject> findModInfo(Set<File> mods){ private static List<JsonObject> findModInfo(Set<File> mods){
return mods.stream().map(file -> { List<JsonArray> modFiles = mods.stream().map(file -> {
try { try {
JarFile jar = new JarFile(file); JarFile jar = new JarFile(file);
return readModInfoFromJar(jar); return readModInfoFromJar(jar);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Failed to mod " + file.getName(), e); throw new RuntimeException("Failed to mod " + file.getName(), e);
} }
}).collect(Collectors.toList()); }).filter((Predicate<JsonArray>) Objects::nonNull).collect(Collectors.toList());
List<JsonObject> containedMods = new ArrayList<>();
for(JsonArray modFile : modFiles){
for (int i = 0; i < modFile.size(); i++) {
containedMods.add(modFile.get(i).getAsJsonObject());
}
}
return containedMods;
} }
private static JsonObject readModInfoFromJar(@Nonnull JarFile file) throws IOException { private static JsonArray readModInfoFromJar(@Nonnull JarFile file) throws IOException {
Gson gson = new Gson(); Gson gson = new Gson();
ZipEntry entry = file.getEntry("mod.json"); ZipEntry entry = file.getEntry("mod.json");
if (entry == null) if (entry == null)
return null; return null;
return gson.fromJson(new InputStreamReader(file.getInputStream(entry)), JsonObject.class); return gson.fromJson(new InputStreamReader(file.getInputStream(entry)), JsonArray.class);
} }
} }

View File

@ -30,11 +30,12 @@ import net.fabricmc.loom.util.Constants;
import org.gradle.api.Project; import org.gradle.api.Project;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.List; import java.util.List;
public class PreBakeMixins { public class PreBakeMixins {
public void proccess(Project project, LoomGradleExtension extension, List<File> mods) { public void proccess(Project project, LoomGradleExtension extension, List<File> mods) throws IOException {
project.getLogger().lifecycle(":Found " + mods.size() + " mods to prebake"); project.getLogger().lifecycle(":Found " + mods.size() + " mods to prebake");
String[] args = new String[mods.size() + 4]; String[] args = new String[mods.size() + 4];
args[0] = "-m"; args[0] = "-m";

View File

@ -0,0 +1 @@
net.fabricmc.loom.mixin.MixinServiceGradle