Skip to content

Add Addressables Report support #29

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ UnityFileSystemTestData/**/*.sln
UnityFileSystemTestData/ProjectSettings/
UnityFileSystemTestData/UserSettings/
UnityFileSystemTestData/Packages/
*.db
*.txt
*.csv
1 change: 1 addition & 0 deletions Analyzer/Analyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
37 changes: 36 additions & 1 deletion Analyzer/AnalyzerTool.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityDataTools.Analyzer.Build;
using UnityDataTools.Analyzer.SQLite;
using UnityDataTools.FileSystem;

Expand Down Expand Up @@ -44,6 +46,12 @@ public int Analyze(
int i = 1;
foreach (var file in files)
{
if (Path.GetExtension(file) == ".json")
{
ProcessAddressablesBuild(file, writer, i, files.Length);
++i;
continue;
}
if (ShouldIgnoreFile(file))
{
var relativePath = Path.GetRelativePath(path, file);
Expand Down Expand Up @@ -173,6 +181,33 @@ void ProcessFile(string file, string rootDirectory, SQLiteWriter writer, int fil
}
}



void ProcessAddressablesBuild(string file, SQLiteWriter writer, int fileIndex, int cntFiles)
{
try
{
Console.Error.WriteLine(file);
using (StreamReader reader = File.OpenText(file))
{
JsonSerializer serializer = new JsonSerializer();
BuildLayout buildLayout = (BuildLayout)serializer.Deserialize(reader, typeof(BuildLayout));
writer.WriteAddressablesBuild(file, buildLayout);
ReportProgress(file, fileIndex, cntFiles);
}
}
catch (Exception e)
{
EraseProgressLine();
Console.Error.WriteLine();
Console.Error.WriteLine($"Error processing file: {file}");
Console.WriteLine($"{e.GetType()}: {e.Message}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.json is a standard file, and there will be .json files in a player output.

For those we should ideally continue to be silent or a minor warning about ignoring it.

Maybe there is a way to first just sanity check that it really is a Addressables build report, perhaps by peeking at the start of the file to check for clear expected formatting?

Or attempting to parsing it but only logging the full error if further analysis proves it is a Addressable file?

if (m_Verbose)
Console.WriteLine(e.StackTrace);
}

}

int m_LastProgressMessageLength = 0;

void ReportProgress(string relativePath, int fileIndex, int cntFiles)
Expand Down
267 changes: 267 additions & 0 deletions Analyzer/Resources/Init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,272 @@ WHERE m.type = "Material";

INSERT INTO types (id, name) VALUES (-1, 'Scene');

CREATE TABLE addr_builds
(
id INTEGER,
name TEXT,
build_target INTEGER,
start_time TEXT,
duration REAL,
error TEXT,
package_version TEXT,
player_version TEXT,
build_script TEXT,
result_hash TEXT,
type INTEGER,
unity_version TEXT,
PRIMARY KEY (id)
);

create table addr_build_bundles
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the short form will be immediately apparent to everyone "addr_build" as short for for Addressables Build.

Suggested change
create table addr_build_bundles
create table addressables_bundles

I wonder if there is any easy way to make all these tables optional, e.g. only created if we actually find Addressables file? I"m thinking now the dropdown of Tables will start with quite a long list of tables that will be all empty for some builds. Not the end of the world but if they are self contained maybe this can be a sql file that is only run when we discover the file?

(
id INTEGER,
build_id INTEGER,
asset_count INTEGER,
build_status INTEGER,
crc INTEGER,
compression TEXT,
dependency_file_size INTEGER,
expanded_dependency_file_size INTEGER,
file_size INTEGER,
group_rid INTEGER,
hash TEXT,
internal_name TEXT,
load_path TEXT,
name TEXT,
provider TEXT,
result_type TEXT,
PRIMARY KEY (id, build_id)
);
create table addr_build_bundle_dependent_bundles
(
bundle_id INTEGER,
build_id INTEGER,
dependent_bundle_rid INTEGER,
PRIMARY KEY (bundle_id, build_id, dependent_bundle_rid),
FOREIGN KEY (bundle_id, build_id) REFERENCES addr_build_bundles(id, build_id)
);
create table addr_build_bundle_dependencies
(
bundle_id INTEGER,
build_id INTEGER,
dependency_rid INTEGER,
PRIMARY KEY (bundle_id, build_id, dependency_rid),
FOREIGN KEY (bundle_id, build_id) REFERENCES addr_build_bundles(id, build_id)
);
create table addr_build_bundle_expanded_dependencies
(
bundle_id INTEGER,
build_id INTEGER,
dependency_rid INTEGER,
PRIMARY KEY (bundle_id, build_id, dependency_rid),
FOREIGN KEY (bundle_id, build_id) REFERENCES addr_build_bundles(id, build_id)
);

create table addr_build_bundle_files
(
bundle_id INTEGER,
build_id INTEGER,
file_rid INTEGER,
PRIMARY KEY (bundle_id, build_id, file_rid),
FOREIGN KEY (bundle_id, build_id) REFERENCES addr_build_bundles(id, build_id)
);
create table addr_build_bundle_regular_dependencies
(
bundle_id INTEGER,
build_id INTEGER,
dependency_rid INTEGER,
PRIMARY KEY (bundle_id, build_id, dependency_rid),
FOREIGN KEY (bundle_id, build_id) REFERENCES addr_build_bundles(id, build_id)
);
create table addr_build_data_from_other_assets
(
id INTEGER,
build_id INTEGER,
asset_guid TEXT,
asset_path TEXT,
file INTEGER,
main_asset_type INTEGER,
object_count INTEGER,
serialized_size INTEGER,
streamed_size INTEGER,
PRIMARY KEY (id, build_id)
);
create table addr_build_data_from_other_asset_objects
(
data_from_other_asset_id INTEGER,
build_id INTEGER,
asset_type INTEGER,
component_name TEXT,
local_identifier_in_file INTEGER,
object_name TEXT,
serialized_size INTEGER,
streamed_size INTEGER,
PRIMARY KEY (data_from_other_asset_id, build_id, local_identifier_in_file),
FOREIGN KEY (data_from_other_asset_id, build_id) REFERENCES addr_build_data_from_other_assets(id, build_id)
);
create table addr_build_data_from_other_asset_object_references
(
data_from_other_asset_id INTEGER,
build_id INTEGER,
local_identifier_in_file INTEGER,
asset_id INTEGER,
object_id INTEGER,
PRIMARY KEY (data_from_other_asset_id, build_id, local_identifier_in_file, asset_id, object_id),
FOREIGN KEY (data_from_other_asset_id, build_id, local_identifier_in_file) REFERENCES addr_build_data_from_other_asset_objects(data_from_other_asset_id, build_id, local_identifier_in_file)
);
create table addr_build_data_from_other_asset_referencing_assets
(
data_from_other_asset_id INTEGER,
build_id INTEGER,
referencing_asset_rid INTEGER,
PRIMARY KEY (data_from_other_asset_id, build_id, referencing_asset_rid),
FOREIGN KEY (data_from_other_asset_id, build_id) REFERENCES addr_build_data_from_other_assets(id, build_id)
);
create table addr_build_explicit_assets
(
id INTEGER,
build_id INTEGER,
bundle INTEGER,
file INTEGER,
asset_hash TEXT,
asset_path TEXT,
addressable_name TEXT,
group_guid TEXT,
guid TEXT,
internal_id TEXT,
main_asset_type INTEGER,
serialized_size INTEGER,
streamed_size INTEGER,
PRIMARY KEY (id, build_id)
);
create table addr_build_explicit_asset_externally_referenced_assets
(
explicit_asset_id INTEGER,
build_id INTEGER,
externally_referenced_asset_rid INTEGER,
PRIMARY KEY (explicit_asset_id, build_id, externally_referenced_asset_rid),
FOREIGN KEY (explicit_asset_id, build_id) REFERENCES addr_build_explicit_assets(id, build_id)
);
create table addr_build_explicit_asset_internal_referenced_explicit_assets
(
explicit_asset_id INTEGER,
build_id INTEGER,
internal_referenced_explicit_asset_rid INTEGER,
PRIMARY KEY (explicit_asset_id, build_id, internal_referenced_explicit_asset_rid),
FOREIGN KEY (explicit_asset_id, build_id) REFERENCES addr_build_explicit_assets(id, build_id)
);
create table addr_build_explicit_asset_internal_referenced_other_assets
(
explicit_asset_id INTEGER,
build_id INTEGER,
internal_referenced_other_asset_rid INTEGER,
PRIMARY KEY (explicit_asset_id, build_id, internal_referenced_other_asset_rid),
FOREIGN KEY (explicit_asset_id, build_id) REFERENCES addr_build_explicit_assets(id, build_id)
);
create table addr_build_explicit_asset_labels
(
explicit_asset_id INTEGER,
build_id INTEGER,
label TEXT,
PRIMARY KEY (explicit_asset_id, build_id, label),
FOREIGN KEY (explicit_asset_id, build_id) REFERENCES addr_build_explicit_assets(id, build_id)
);
create table addr_build_files
(
id INTEGER,
build_id INTEGER,
bundle INTEGER,
bundle_object_info_size INTEGER,
mono_script_count INTEGER,
mono_script_size INTEGER,
name TEXT,
preload_info_size INTEGER,
write_result_filename TEXT,
PRIMARY KEY (id, build_id)
);
create table addr_build_file_assets
(
file_id INTEGER,
build_id INTEGER,
asset_rid INTEGER,
PRIMARY KEY (file_id, build_id, asset_rid),
FOREIGN KEY (file_id, build_id) REFERENCES addr_build_files(id, build_id)
);
create table addr_build_file_other_assets
(
file_id INTEGER,
build_id INTEGER,
other_asset_rid INTEGER,
PRIMARY KEY (file_id, build_id, other_asset_rid),
FOREIGN KEY (file_id, build_id) REFERENCES addr_build_files(id, build_id)
);
create table addr_build_file_sub_files
(
file_id INTEGER,
build_id INTEGER,
sub_file_rid INTEGER,
PRIMARY KEY (file_id, build_id, sub_file_rid),
FOREIGN KEY (file_id, build_id) REFERENCES addr_build_files(id, build_id)
);
create table addr_build_file_external_references
(
file_id INTEGER,
build_id INTEGER,
external_reference_rid INTEGER,
PRIMARY KEY (file_id, build_id, external_reference_rid),
FOREIGN KEY (file_id, build_id) REFERENCES addr_build_files(id, build_id)
);
create table addr_build_groups
(
id INTEGER,
build_id INTEGER,
guid TEXT,
name TEXT,
packing_mode TEXT,
PRIMARY KEY (id, build_id)
);
create table addr_build_group_bundles
(
group_id INTEGER,
build_id INTEGER,
bundle_rid INTEGER,
PRIMARY KEY (group_id, build_id, bundle_rid),
FOREIGN KEY (group_id, build_id) REFERENCES addr_build_groups(id, build_id)
);
create table addr_build_group_schemas
(
group_id INTEGER,
build_id INTEGER,
schema_rid INTEGER,
PRIMARY KEY (group_id, build_id, schema_rid),
FOREIGN KEY (group_id, build_id) REFERENCES addr_build_groups(id, build_id)
);
create table addr_build_schemas
(
id INTEGER,
build_id INTEGER,
guid TEXT,
type TEXT,
PRIMARY KEY (id, build_id)
);
create table addr_build_schema_data_pairs
(
schema_id INTEGER,
build_id INTEGER,
key TEXT,
value TEXT,
PRIMARY KEY (schema_id, build_id, key),
FOREIGN KEY (schema_id, build_id) REFERENCES addr_build_schemas(id, build_id)
);
create table addr_build_sub_files
(
id INTEGER,
build_id INTEGER,
is_serialized_file INTEGER,
name TEXT,
size INTEGER,
PRIMARY KEY (id, build_id)
);
PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
Loading