Skip to content

Commit

Permalink
deno! (thanks to ennui!)
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Jun 19, 2023
1 parent 456c2ab commit 9c05d63
Show file tree
Hide file tree
Showing 11 changed files with 76,312 additions and 191 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

## setup

In order to match, you must have both [deno](https://deno.com/[email protected]/getting_started/installation) and java installed.

In this tutorial our old version will be `1.18` and our new version will be `1.19`.

0. Before you start, make sure you've merged all pull requests marked with `final-comment-period` in the QM repo!
1. Clone this repo. We'll be calling the folder you cloned it into our `root` folder.
2. Enter your root folder.
3. Clone QM with `git clone https://github.com/quiltmc/quilt-mappings [your old version name]`. For us, this means we'll have a QM clone in a directory named `1.18`.
4. Repeat, this time naming the clone after your new version.
5. Open up `save_methods.mjs` and replace the version constants with yours. For our example, this means we'll be replacing `from_version` with `1.18` and `to_version` with `1.19`.
6. Download the hashed tiny file for your new version from [here](https://maven.quiltmc.org/repository/release/org/quiltmc/hashed/). The file you're looking for should be named something like `hashed-1.19.tiny`. Place the file in your root folder.
7. Go into your new version clone and update the `MINECRAFT_VERSION` constant in `buildSrc/src/main/java/quilt/internal/Constants.java` to match your current version.
8. Run `git checkout -b [your new version name]` to create a new branch for the new version. (`git checkout -b 1.19` for us)
9. Return to your root folder. You're ready to start matching!
5. Go into your new version clone and update the `MINECRAFT_VERSION` constant in `buildSrc/src/main/java/quilt/internal/Constants.java` to match your current version.
6. Still in the new version clone, run `git checkout -b [your new version name]` to create a new branch for the new version. (`git checkout -b 1.19` for us)
7. Return to your root folder. You're ready to start matching!

## matching

1. In both the old and new clones, run `./gradlew mapPerVersionMappingsJar`.
2. In the new clone, run `./gradlew dropInvalidMappings`.
3. Run `git add .` and `git commit -m "[your new version name]"` to commit.
4. Return to your root folder and run `node save_methods.mjs`.
4. Return to your root folder and run `deno task match [your old version] [your new version]`.
5. In the new clone, run `./gradlew dropInvalidMappings` again.
6. Run `./gradlew generatePackageInfoMappings` to generate new package info files.
7. Run `./gradlew build javadocJar` to test your build.
Expand Down
5 changes: 5 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"match": "deno run --allow-read --allow-write --allow-net save_methods.ts"
}
}
97 changes: 97 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 37 additions & 33 deletions enigma_mappings.mjs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Bunch of stuff to deal with Enigma mappings.
*/

import { readdirSync, readFileSync, mkdirSync, writeFileSync, unlinkSync } from "fs";
import * as java from "./java.mjs";

/**
Expand Down Expand Up @@ -53,10 +52,10 @@ export class Method extends Mapping {

detailed_params(is_static) {
let lvt = is_static ? 0 : 1;
let params = [];
const params = [];

for (const param of this.descriptor.params) {
let arg = this.args[lvt];
const arg = this.args[lvt];

params.push({
lvt: lvt,
Expand Down Expand Up @@ -224,7 +223,7 @@ export class Mappings {
*/
find_class(name) {
if (name.includes("$")) {
let split = name.split("$");
const split = name.split("$");
return this.classes.find(obj => obj.intermediary === split[split.length - 1]);
}
return this.classes.find(obj => obj.intermediary === name);
Expand All @@ -236,7 +235,7 @@ export class Mappings {
}

export function parse_class_mapping(input) {
let lines = input.split("\n");
const lines = input.split("\n");

// The parsed mapping class.
let return_class;
Expand All @@ -245,17 +244,17 @@ export function parse_class_mapping(input) {
let current_method;

// 0 is the return class.
let current_classes = [];
const current_classes = [];

for (let i = 0; i < lines.length; i++) {
let line = lines[i];
let scope = (line.match(/\t/g) || []).length;
const scope = (line.match(/\t/g) || []).length;

line = line.replace(/\t/g, "");

let map = line.split(" ");
const map = line.split(" ");

let type = map[0];
const type = map[0];

let current_class = current_classes.length === 0 ? undefined : current_classes[scope - 1];

Expand All @@ -280,29 +279,34 @@ export function parse_class_mapping(input) {
}

switch (type) {
case "METHOD":
let intermediary = map[1];
let named = (map.length === 4) ? map[2] : "";
let signature = (map.length === 4) ? map[3] : map[2];
case "METHOD": {
const intermediary = map[1];
const named = (map.length === 4) ? map[2] : "";
const signature = (map.length === 4) ? map[3] : map[2];
current_object = current_method = new Method(current_class, intermediary, named, signature);
current_class.methods.push(current_method);
break;
case "FIELD":
}
case "FIELD": {
if (map[3] === undefined) {
current_class.fields.push(current_object = new Field(current_class, map[1], "", map[2]));
} else {
current_class.fields.push(current_object = new Field(current_class, map[1], map[2], map[3]));
}
break;
case "ARG":
}
case "ARG": {
// Arguments can also get comments.
current_object = current_method.args[parseInt(map[1])] = new Mapping(undefined, map[2]);
break;
case "COMMENT":
}
case "COMMENT": {
current_object.comments.push(line.replace(/COMMENT ?/, ""))
break;
default:
}
default: {
break;
}
}
}

Expand Down Expand Up @@ -377,7 +381,7 @@ export function stringify_class_mapping(clazz, scope = 0) {
scope++;

for (let index = 0; index < method.args.length; index++) {
let arg = method.args[index];
const arg = method.args[index];

if (arg === undefined || arg.named === undefined || arg.named === "undefined")
continue;
Expand All @@ -402,42 +406,42 @@ export function stringify_class_mapping(clazz, scope = 0) {
}

export function read_class_mapping(file) {
let object = parse_class_mapping(readFileSync(file, "utf8"));
const object = parse_class_mapping(Deno.readTextFileSync(file));
object.file = file;
return object;
}

export function read_mappings(root, mappings) {
let files = readdirSync(root, {withFileTypes: true});
files.forEach(file => {
if (file.isFile())
mappings.append_tree(read_class_mapping(root + file.name));
else if (file.isDirectory())
read_mappings(root + file.name + "/", mappings);
});
for (const dirEntry of Deno.readDirSync(root)) {
if (dirEntry.isFile) {
mappings.append_tree(read_class_mapping(root + dirEntry.name));
} else if (dirEntry.isDirectory) {
read_mappings(root + dirEntry.name + "/", mappings);
}
}
}

export function write_class_mapping(old_root, new_root, clazz) {
let mapping = stringify_class_mapping(clazz);
const mapping = stringify_class_mapping(clazz);

let file = clazz.file.replace(old_root, new_root);
const file = clazz.file.replace(old_root, new_root);

let path = file.split("/");
const path = file.split("/");

let dir = "";

for (let i = 0; i < path.length - 1; i++) {
dir += path[i] + "/";
}

mkdirSync(dir, {recursive: true});
Deno.mkdirSync(dir, { recursive: true });

writeFileSync(file, mapping, {encoding: "utf8"});
Deno.writeTextFileSync(file, mapping);
}

export function replace_class_mapping(current_root, old_root, new_root, old_class, new_class) {
let old_file = old_class.file.replace(old_root, new_root);
unlinkSync(old_file);
const old_file = old_class.file.replace(old_root, new_root);
Deno.removeSync(old_file);
old_class.named = new_class.named;
old_class.file = new_class.file.replace(current_root, new_root);
write_class_mapping("", "", old_class);
Expand Down
Loading

0 comments on commit 9c05d63

Please sign in to comment.