Skip to content

Commit e83504a

Browse files
committed
add support for submodules
1 parent 4498819 commit e83504a

3 files changed

Lines changed: 84 additions & 21 deletions

File tree

SuperPatch.Core/Storages/Bromite/BromiteRemoteStorage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ protected override async Task FetchChromiumCommit()
2323
(await http.GetStringAsync($"{PatchSourceUrl}/{workspace.CommitShaOrTag}/build/RELEASE"))
2424
.Replace("\n", "")
2525
.Replace("\r", "");
26+
await base.FetchChromiumCommit();
2627
}
2728

2829
public override async Task<byte[]> GetPatchAsync(string filename)

SuperPatch.Core/Storages/ChromiumStorage.cs

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,121 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using DiffPatch.Data;
8+
using static SuperPatch.Core.Storages.ChromiumStorage;
89

910
namespace SuperPatch.Core.Storages
1011
{
1112
public abstract class ChromiumStorage : Storage
1213
{
14+
public class SubModulesInfo
15+
{
16+
public string Path { get; internal set; }
17+
public string Url { get; internal set; }
18+
public string RevisionIndex { get; internal set; }
19+
public string Revision { get; internal set; }
20+
}
21+
1322
protected HttpClient http { get; private set; }
1423

1524
protected virtual string FileSourceUrl => @"https://raw.githubusercontent.com/chromium/chromium";
1625

17-
public string ChromiumCommit { get; protected set; }
26+
public string ChromiumCommit { get; protected set; }
27+
private string v8_revision;
1828

1929
private string _CacheDirectory = null;
2030
protected string CacheDirectory { get { return _CacheDirectory; } }
2131

32+
private List<SubModulesInfo> subModulesInfos = new List<SubModulesInfo>();
33+
2234
public ChromiumStorage(Workspace wrk, HttpClient http) : base(wrk)
2335
{
2436
this.http = http;
25-
}
2637

27-
protected virtual async Task FetchChromiumCommit()
38+
subModulesInfos.Add(new SubModulesInfo()
39+
{
40+
Path = "v8/",
41+
Url = "https://raw.githubusercontent.com/v8/v8",
42+
RevisionIndex = "v8_revision"
43+
});
44+
}
45+
46+
protected virtual async Task FetchChromiumCommit()
2847
{
29-
ChromiumCommit = workspace.CommitShaOrTag;
30-
await Task.CompletedTask;
48+
if (string.IsNullOrEmpty(ChromiumCommit))
49+
ChromiumCommit = workspace.CommitShaOrTag;
50+
51+
var depsByte = await GetFileAsync("DEPS");
52+
foreach(var submodule in subModulesInfos)
53+
submodule.Revision = GetRevision(depsByte, submodule.RevisionIndex);
54+
55+
await Task.CompletedTask;
3156
}
3257

33-
public virtual void SetCacheDirectory( string CacheDirectory )
58+
private string GetRevision(byte[] file, string index)
59+
{
60+
string deps = Encoding.UTF8.GetString(file);
61+
var rev = $"'{index}'";
62+
foreach (var line in deps.Split("\n"))
63+
{
64+
if (line.Contains(rev))
65+
{
66+
string value = line.Split(":")[1]
67+
.Replace("'", "")
68+
.Replace(",", "")
69+
.Trim();
70+
return value;
71+
}
72+
}
73+
throw new NotSupportedException();
74+
}
75+
76+
public virtual void SetCacheDirectory( string CacheDirectory )
3477
{
3578
_CacheDirectory = CacheDirectory;
3679
}
3780

38-
public override async Task<byte[]> GetFileAsync(IFileDiff file)
39-
{
40-
if (file.From == "/dev/null") return null;
81+
public override async Task<byte[]> GetFileAsync(IFileDiff file)
82+
{
83+
if (file.From == "/dev/null") return null;
84+
return await GetFileAsync(file.From);
85+
}
86+
87+
private async Task<byte[]> GetFileAsync(string file)
88+
{
4189
if (_CacheDirectory != null)
4290
{
43-
var localFile = System.IO.Path.Combine(_CacheDirectory, file.From);
91+
var localFile = System.IO.Path.Combine(_CacheDirectory, file);
4492
if( System.IO.File.Exists(localFile))
4593
return await System.IO.File.ReadAllBytesAsync(localFile);
4694
}
4795

4896
if (string.IsNullOrEmpty(ChromiumCommit)) await FetchChromiumCommit();
49-
var content = await http.GetByteArrayAsync($"{FileSourceUrl}/{ChromiumCommit}/{file.From}");
5097

51-
if (_CacheDirectory != null)
52-
{
53-
var localFile = System.IO.Path.Combine(_CacheDirectory, file.From);
54-
var directory = System.IO.Path.GetDirectoryName(localFile);
55-
if (System.IO.Directory.Exists(directory) == false)
56-
System.IO.Directory.CreateDirectory(directory);
98+
var url = $"{FileSourceUrl}/{ChromiumCommit}/{file}";
99+
foreach( var submodule in subModulesInfos)
100+
if (file.StartsWith(submodule.Path))
101+
url = $"{submodule.Url}/{submodule.Revision}/{file.Substring(submodule.Path.Length)}";
57102

58-
System.IO.File.WriteAllBytes(localFile, content);
59-
}
103+
try
104+
{
105+
var content = await http.GetByteArrayAsync(url);
106+
107+
if (_CacheDirectory != null)
108+
{
109+
var localFile = System.IO.Path.Combine(_CacheDirectory, file);
110+
var directory = System.IO.Path.GetDirectoryName(localFile);
111+
if (System.IO.Directory.Exists(directory) == false)
112+
System.IO.Directory.CreateDirectory(directory);
113+
114+
System.IO.File.WriteAllBytes(localFile, content);
115+
}
60116

61-
return content;
117+
return content;
118+
}
119+
catch (Exception ex)
120+
{
121+
throw new Exception($"Url {url} error: {ex}", ex);
122+
}
62123
}
63124
}
64125
}

SuperPatch.Core/Storages/Kiwi/KiwiRemoteStorage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected override async Task FetchChromiumCommit()
3838
.Select(x => x.Substring(x.IndexOf("=") + 1))
3939
.ToList();
4040
ChromiumCommit = string.Join(".", build);
41-
}
41+
await base.FetchChromiumCommit();
42+
}
4243

4344
public override async Task<byte[]> GetPatchAsync(string filename)
4445
{

0 commit comments

Comments
 (0)