Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate resource graph on bundle #7802

Merged
merged 39 commits into from Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
845b323
Initial commit
britzl Jul 14, 2023
e3abf4e
Update ResourceNodeGraph.java
britzl Jul 14, 2023
1effd98
Update ResourceNodeGraph.java
britzl Jul 14, 2023
11434a1
Fix imports for tests
britzl Jul 15, 2023
742b215
Improved tostring
britzl Jul 17, 2023
5c5127d
Forgot to call visitor.leave() on early out
britzl Jul 17, 2023
a582cc5
Split resource and graph builds
britzl Jul 17, 2023
eba23b9
Merged set and graph creation
britzl Jul 18, 2023
060869b
Use resources instead of resource paths
britzl Jul 26, 2023
d51454d
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
britzl Jul 26, 2023
2253d9f
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
britzl Jul 31, 2023
edac1c8
Cache hex digests
britzl Jul 31, 2023
bd4dd18
Added hex digest to resource nodes
britzl Jul 31, 2023
37c1541
Added hashCode and equals to resource nodes
britzl Jul 31, 2023
f16c33f
Set hex digests on all nodes in a resource graph
britzl Jul 31, 2023
beeb830
Changed how the archive builder is created
britzl Jul 31, 2023
d5cead0
Fix keep-unused
britzl Jul 31, 2023
2db66b5
Set excluded resources
britzl Jul 31, 2023
b3ab0c0
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
britzl Jul 31, 2023
d33411c
Merge dev + fixes (#7989)
AGulev Sep 12, 2023
35e2b79
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
AGulev Sep 12, 2023
7a168a0
Change from absolute to relative paths
britzl Sep 19, 2023
440a46e
Use relative paths in resource nodes
britzl Sep 19, 2023
8ac9e29
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
britzl Sep 25, 2023
e1f5918
Added timers
britzl Oct 2, 2023
8c860ca
Added option to write graph directly to stream
britzl Oct 2, 2023
62f246d
Reworked the resource graph
britzl Oct 5, 2023
5ca699c
Fixed tests
britzl Oct 8, 2023
0fda199
Moved test
britzl Oct 9, 2023
3c642a0
take into account only unique children
AGulev Oct 10, 2023
1c89c65
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
AGulev Oct 10, 2023
6ac4acf
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
AGulev Oct 12, 2023
2883b05
fix issue with ManifestBuilder
AGulev Oct 13, 2023
cd88f07
fix issue with resurce exclusion
AGulev Oct 16, 2023
2f29916
Merge branch 'dev' into Issue-7753-generate-resource-graph-on-bundle
AGulev Oct 17, 2023
a1dc374
fix an issue in tests
AGulev Oct 17, 2023
b5e4459
semantics refactoring
AGulev Oct 17, 2023
dfc5c19
remove old comment
AGulev Oct 17, 2023
765ffb0
do not include information about the main bundle if user doesn't use LU
AGulev Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -40,7 +40,7 @@
import com.dynamo.bob.archive.ArchiveBuilder;
import com.dynamo.bob.archive.ArchiveReader;
import com.dynamo.bob.archive.ManifestBuilder;
import com.dynamo.bob.pipeline.ResourceNode;
import com.dynamo.bob.pipeline.graph.ResourceNode;
import com.dynamo.liveupdate.proto.Manifest.HashAlgorithm;
import com.dynamo.liveupdate.proto.Manifest.ResourceEntryFlag;

Expand Down
Expand Up @@ -42,7 +42,7 @@
import org.junit.Test;

import com.dynamo.bob.archive.ManifestBuilder;
import com.dynamo.bob.pipeline.ResourceNode;
import com.dynamo.bob.pipeline.graph.ResourceNode;
import com.dynamo.liveupdate.proto.Manifest.HashAlgorithm;
import com.dynamo.liveupdate.proto.Manifest.HashDigest;
import com.dynamo.liveupdate.proto.Manifest.ManifestData;
Expand Down
Expand Up @@ -43,7 +43,7 @@
import com.dynamo.proto.DdfMath.Quat;
import com.dynamo.gamesys.proto.Sprite.SpriteDesc;
import com.google.protobuf.Message;
import com.dynamo.bob.pipeline.ResourceNode;
import com.dynamo.bob.pipeline.graph.ResourceNode;

public class CollectionBuilderTest extends AbstractProtoBuilderTest {

Expand Down
Expand Up @@ -238,6 +238,15 @@ public BobProjectProperties getProjectProperties() {
return projectProperties;
}

/**
* Convert an absolute path to a path relative to the project root
* @param path The path to relativize
* @return Relative path
*/
public String getPathRelativeToRootDirectory(String path) {
return Path.of(rootDirectory).relativize(Path.of(path)).toString();
}

public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
Expand Down
Expand Up @@ -31,13 +31,15 @@
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;

import com.dynamo.bob.CompileExceptionError;
import com.dynamo.bob.pipeline.ResourceNode;
import com.dynamo.bob.pipeline.graph.ResourceNode;
import com.dynamo.liveupdate.proto.Manifest.HashAlgorithm;
import com.dynamo.liveupdate.proto.Manifest.SignAlgorithm;
import com.dynamo.liveupdate.proto.Manifest.ResourceEntryFlag;
Expand All @@ -59,6 +61,7 @@ public class ArchiveBuilder {
private List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
private List<ArchiveEntry> excludedEntries = new ArrayList<ArchiveEntry>();
private Set<String> lookup = new HashSet<String>(); // To see if a resource has already been added
private Map<String, String> hexDigestCache = new HashMap<>();
private String root;
private ManifestBuilder manifestBuilder = null;
private LZ4Compressor lz4Compressor;
Expand Down Expand Up @@ -101,10 +104,6 @@ public int getArchiveEntrySize() {
return this.entries.size();
}

public byte[] getArchiveIndexHash() {
return this.archiveIndexMD5;
}

public byte[] loadResourceData(String filepath) throws IOException {
File fhandle = new File(filepath);
return FileUtils.readFileToByteArray(fhandle);
Expand Down Expand Up @@ -248,8 +247,8 @@ public void write(RandomAccessFile archiveIndex, RandomAccessFile archiveData, P
throw new IOException("Unable to create a Resource Pack, the hashing algorithm is not supported!");
}

// Store association between hexdigest and original filename in a lookup table
entry.setHexDigest(hexDigest);
hexDigestCache.put(entry.getFilename(), hexDigest);

// Write resource to resource pack or data archive
if (this.excludeResource(normalisedPath, excludedResources)) {
Expand Down Expand Up @@ -288,16 +287,17 @@ public void write(RandomAccessFile archiveIndex, RandomAccessFile archiveData, P
}
archiveIndex.write(indexBuffer.array());

byte[] archiveIndexMD5 = null;
try {
// Calc index file MD5 hash
archiveIndex.seek(archiveIndexHeaderOffset);
int num_bytes = (int) archiveIndex.length() - archiveIndexHeaderOffset;
byte[] archiveIndexBytes = new byte[num_bytes];
archiveIndex.readFully(archiveIndexBytes);
this.archiveIndexMD5 = ManifestBuilder.CryptographicOperations.hash(archiveIndexBytes, HashAlgorithm.HASH_MD5);
archiveIndexMD5 = ManifestBuilder.CryptographicOperations.hash(archiveIndexBytes, HashAlgorithm.HASH_MD5);
manifestBuilder.setArchiveIdentifier(archiveIndexMD5);
} catch (NoSuchAlgorithmException e) {
System.err.println("The algorithm specified is not supported!");
e.printStackTrace();
throw new IOException("Unable to create a Resource Pack, the hashing algorithm is not supported!");
}

// Update index header with offsets
Expand All @@ -309,7 +309,7 @@ public void write(RandomAccessFile archiveIndex, RandomAccessFile archiveData, P
archiveIndex.writeInt(entryOffset);
archiveIndex.writeInt(hashOffset);
archiveIndex.writeInt(ManifestBuilder.CryptographicOperations.getHashSize(manifestBuilder.getResourceHashAlgorithm()));
archiveIndex.write(this.archiveIndexMD5);
archiveIndex.write(archiveIndexMD5);
}

private void alignBuffer(RandomAccessFile outFile, int align) throws IOException {
Expand All @@ -322,6 +322,15 @@ private void alignBuffer(RandomAccessFile outFile, int align) throws IOException
}
}

/**
* Get all cached hex digests as a lookup between absolute filepath and
britzl marked this conversation as resolved.
Show resolved Hide resolved
* digest.
* @return Map with hex digests, keyed on absolute filepath
*/
public Map<String, String> getCachedHexDigests() {
return hexDigestCache;
}

private static void printUsageAndTerminate(String message) {
System.err.println("Usage: ArchiveBuilder <root> <output> [-c] <file> [<file> ...]\n");
System.err.println(" <root> - directorypath to root of input files (<file>)");
Expand Down Expand Up @@ -436,7 +445,6 @@ public static void main(String[] args) throws IOException, NoSuchAlgorithmExcept
System.out.println("Writing " + filepathArchiveData.getCanonicalPath());

archiveBuilder.write(archiveIndex, archiveData, resourcePackDirectory, excludedResources);
manifestBuilder.setArchiveIdentifier(archiveBuilder.getArchiveIndexHash());

System.out.println("Writing " + filepathManifest.getCanonicalPath());
byte[] manifestFile = manifestBuilder.buildManifest();
Expand Down
Expand Up @@ -47,7 +47,7 @@
import javax.crypto.NoSuchPaddingException;
import javax.security.auth.DestroyFailedException;

import com.dynamo.bob.pipeline.ResourceNode;
import com.dynamo.bob.pipeline.graph.ResourceNode;
import com.dynamo.bob.util.MurmurHash;
import com.dynamo.bob.logging.Logger;
import com.dynamo.liveupdate.proto.Manifest.HashAlgorithm;
Expand Down Expand Up @@ -422,7 +422,7 @@ private void buildResourceOccurrancesMap(ResourceNode node) {
// The resource may occur at many instances in the tree
// This map contains the mapping url -> occurrances (i.e. nodes)

String key = node.relativeFilepath;
String key = node.getRelativePath();
if (!pathToOccurrances.containsKey(key)) {
pathToOccurrances.put(key, new ArrayList<ResourceNode>());
}
Expand Down Expand Up @@ -457,9 +457,9 @@ public List<ArrayList<String>> getParentCollections(String filepath) {
ResourceNode current = candidates.remove(0).getParent();
result.add(new ArrayList<String>());
while (current != null) {
if (current.relativeFilepath.endsWith("collectionproxyc") ||
current.relativeFilepath.endsWith("collectionc")) {
result.get(i).add(current.relativeFilepath);
if (current.getRelativePath().endsWith("collectionproxyc") ||
current.getRelativePath().endsWith("collectionc")) {
result.get(i).add(current.getRelativePath());
}

current = current.getParent();
Expand Down Expand Up @@ -495,10 +495,10 @@ and thus create a partial archive that has to be updated (through
dependants = new ArrayList<String>();

for (ResourceNode child : candidate.getChildren()) {
dependants.add(child.relativeFilepath);
dependants.add(child.getRelativePath());

if (!child.relativeFilepath.endsWith("collectionproxyc")) {
dependants.addAll(getDependants(child.relativeFilepath));
if (!child.getRelativePath().endsWith("collectionproxyc")) {
dependants.addAll(getDependants(child.getRelativePath()));
}
}

Expand All @@ -524,7 +524,7 @@ public ManifestHeader buildManifestHeader() throws IOException {
}

private void buildPathToNodeMap(ResourceNode node) {
pathToNode.put(node.relativeFilepath, node);
pathToNode.put(node.getRelativePath(), node);
for (ResourceNode child : node.getChildren()) {
buildPathToNodeMap(child);
}
Expand Down