Skip to content

Commit

Permalink
feat: 更新打包工具
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisaAkiron committed Jul 11, 2022
1 parent e557609 commit f55a321
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 291 deletions.
48 changes: 0 additions & 48 deletions .github/workflows/release-maa-resource.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"Default",
"DevBuild",
"ReleaseMaa",
"ReleaseMaaResource",
"SetMaaChangeLog",
"SetPackageBundled",
"SetVersion",
Expand All @@ -75,13 +74,10 @@
"UseMaaChangeLog",
"UseMaaDevBundle",
"UseMaaRelease",
"UseMaaResource",
"UseMaaResourceChangeLog",
"UsePublishArtifact",
"UsePublishRelease",
"UseTagVersion",
"WithCompileCoreRelease",
"WithCompileResourceRelease",
"WithCompileWpfRelease"
]
}
Expand All @@ -95,7 +91,6 @@
"Default",
"DevBuild",
"ReleaseMaa",
"ReleaseMaaResource",
"SetMaaChangeLog",
"SetPackageBundled",
"SetVersion",
Expand All @@ -104,13 +99,10 @@
"UseMaaChangeLog",
"UseMaaDevBundle",
"UseMaaRelease",
"UseMaaResource",
"UseMaaResourceChangeLog",
"UsePublishArtifact",
"UsePublishRelease",
"UseTagVersion",
"WithCompileCoreRelease",
"WithCompileResourceRelease",
"WithCompileWpfRelease"
]
}
Expand Down
43 changes: 28 additions & 15 deletions package-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
{
"name_template": "MaaBundle-{VERSION}",
"type": "MaaBundle",
"configuration": { }
"configuration": {
"include": [
"**"
]
}
},
{
"name_template": "MaaBundle-OTA-{VERSION}",
"type": "MaaBundleOta",
"configuration": {
"include": [
"resource/**",
"MeoAssistant.dll",
"MeoAsstGui.exe"
],
"exclude": [
"libiomp5md.dll",
"mkldnn.dll",
"mklml.dll",
"opencv_world453.dll",
"paddle_inference.dll",
"ppocr.dll",
"aria2c.exe",
"resource/PaddleOCR/**"
"**/PaddleOCR/**"
]
}
},
Expand All @@ -37,9 +39,10 @@
"libiomp5md.dll",
"mkldnn.dll",
"mklml.dll",
"opencv_world453.dll",
"paddle_inference.dll",
"ppocr.dll"
"ppocr.dll",
"opencv_world453.dll",
"**/PaddleOCR/**"
]
}
},
Expand All @@ -48,12 +51,22 @@
"type": "MaaDependencyNoAvx",
"configuration": {
"include": [
"libiomp5md.dll",
"mkldnn.dll",
"mklml.dll",
"opencv_world453.dll"
"opencv_world453.dll",
"**/PaddleOCR/**"
],
"no_avx_bundle": "3rdparty/ppocr_noavx.zip"
}
},
{
"name_template": "MaaResource-{VERSION}",
"type": "MaaResource",
"configuration": {
"include": [
"resource/**"
],
"exclude": [
"**/PaddleOCR/**"
]
}
}
]
19 changes: 0 additions & 19 deletions tools/MaaBuilder/Build.CI.GitHubActions.ReleaseMaaResource.cs

This file was deleted.

97 changes: 25 additions & 72 deletions tools/MaaBuilder/Build.Helper.Bundler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text.Json;
using System.Linq;
using MaaBuilder.Models;
using Microsoft.Extensions.FileSystemGlobbing;
using Nuke.Common;
Expand Down Expand Up @@ -29,30 +29,23 @@ void BundlePackage(AbsolutePath input, string bundleName)
ZipFile.CreateFromDirectory(input, bundle, CompressionLevel.SmallestSize, false);
}

static void RemoveIgnoredFiles(AbsolutePath baseDirectory, IEnumerable<string> ignorePattern)
static void MoveGlobFiles(AbsolutePath source, AbsolutePath target, IEnumerable<string> include, IEnumerable<string> exclude)
{
var match = new Matcher();
var iMatch = new Matcher();
var eMatch = new Matcher();

// 这里反过来可以获取到需要排除的文件列表,而不是需要保留的文件列表
match.AddIncludePatterns(ignorePattern);

var ignoredFiles = match.GetResultsInFullPath(baseDirectory);
foreach (var f in ignoredFiles)
{
FileSystemTasks.DeleteFile(f);
}
}
iMatch.AddIncludePatterns(include);
eMatch.AddIncludePatterns(exclude);

static void CopyIncludeFiles(AbsolutePath originalDirectory, AbsolutePath targetDirectory, IEnumerable<string> includePattern)
{
var match = new Matcher();
match.AddIncludePatterns(includePattern);
var includeFiles = match.GetResultsInFullPath(originalDirectory);
var includeFiles = iMatch.GetResultsInFullPath(source).ToList();
var excludeFiles = eMatch.GetResultsInFullPath(source).ToList();

includeFiles.RemoveAll(x => excludeFiles.Contains(x));

foreach (var file in includeFiles)
{
var relative = file.Replace(originalDirectory, string.Empty);
var targetPath = targetDirectory / relative;
var relative = file.Replace(source, string.Empty);
var targetPath = target / relative;

FileSystemTasks.CopyFile(file, targetPath, FileExistsPolicy.Overwrite);
}
Expand All @@ -68,63 +61,23 @@ static void RemoveDebugSymbols(AbsolutePath outputDir)
}
}

static T GetPackageBundlerConfiguration<T>(Package package) where T : class, IPackageConfiguration
void BundleMaaBundle(AbsolutePath buildOutput, string bundleName, Package package)
{
var configString = package.Configuration["configuration"].ToString().NotNull();
var config = JsonSerializer.Deserialize<T>(configString).NotNull();
return config;
}

void BundleMaaBundle(AbsolutePath buildOutput, string bundleName)
{
BundlePackage(buildOutput, bundleName);
}

void BundleMaaBundleOta(AbsolutePath buildOutput, string bundleName, Package package)
{
var context = Parameters.BuildOutput / package.PackageType.ToString();
FileSystemTasks.CopyDirectoryRecursively(buildOutput, context, DirectoryExistsPolicy.Merge);

var config = GetPackageBundlerConfiguration<PackageMaaBundleOta>(package);

RemoveIgnoredFiles(context, config.Exclude);
BundlePackage(context, bundleName);
}

void BundleMaaCore(AbsolutePath buildOutput, string bundleName, Package package)
{
var context = Parameters.BuildOutput / package.PackageType.ToString();
FileSystemTasks.EnsureExistingDirectory(context);

var config = GetPackageBundlerConfiguration<PackageMaaCore>(package);

CopyIncludeFiles(buildOutput, context, config.Include);
BundlePackage(context, bundleName);
}

void BundleMaaDependency(AbsolutePath buildOutput, string bundleName, Package package)
{
var context = Parameters.BuildOutput / package.PackageType.ToString();
FileSystemTasks.EnsureExistingDirectory(context);
var tempDir = buildOutput.Parent / package.PackageType.ToString();
FileSystemTasks.EnsureExistingDirectory(tempDir);

var config = GetPackageBundlerConfiguration<PackageMaaDependency>(package);
var include = package.Configuration.Include;
var exclude = package.Configuration.Exclude;
var noAvxBundle = package.Configuration.NoAvxBundle;

CopyIncludeFiles(buildOutput, context, config.Include);
BundlePackage(context, bundleName);
}

void BundleMaaDependencyNoAvx(AbsolutePath buildOutput, string bundleName, Package package)
{
var context = Parameters.BuildOutput / package.PackageType.ToString();
FileSystemTasks.EnsureExistingDirectory(context);

var config = GetPackageBundlerConfiguration<PackageMaaDependencyNoAvx>(package);

CopyIncludeFiles(buildOutput, context, config.Include);
MoveGlobFiles(buildOutput, tempDir, include, exclude);

var noAvxBundle = RootDirectory / config.NoAvxBundle;
ZipFile.ExtractToDirectory(noAvxBundle, context, overwriteFiles: true);
if (string.IsNullOrEmpty(noAvxBundle) is false)
{
var file = RootDirectory / noAvxBundle;
ZipFile.ExtractToDirectory(file, tempDir, true);
}

BundlePackage(context, bundleName);
BundlePackage(tempDir, bundleName);
}
}
37 changes: 3 additions & 34 deletions tools/MaaBuilder/Build.Job.Bundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,14 @@ public partial class Build

foreach (var package in Parameters.Packages)
{
var type = package.PackageType;
var name = package.NameTemplate.Replace("{VERSION}", Version);

switch (type)
{
case PackageTypes.MaaBundle:
BundleMaaBundle(releaseBuildOutput, name);
break;
case PackageTypes.MaaBundleOta:
BundleMaaBundleOta(releaseBuildOutput, name, package);
break;
case PackageTypes.MaaCore:
BundleMaaCore(releaseBuildOutput, name, package);
break;
case PackageTypes.MaaDependency:
BundleMaaDependency(releaseBuildOutput, name, package);
break;
case PackageTypes.MaaDependencyNoAvx:
BundleMaaDependencyNoAvx(releaseBuildOutput, name, package);
break;
default:
throw new ArgumentOutOfRangeException();
}

BundleMaaBundle(releaseBuildOutput, name, package);
}
});

Target UseMaaResource => _ => _
.DependsOn(WithCompileResourceRelease)
.Triggers(SetPackageBundled)
.Executes(() =>
{
var buildOutput = Parameters.BuildOutput / BuildConfiguration.Release;
RemoveDebugSymbols(buildOutput);

BundlePackage(buildOutput, MaaResourcePackageName);
});

Target SetPackageBundled => _ => _
.After(UseMaaDevBundle, UseMaaResource)
.After(UseMaaDevBundle)
.Executes(() =>
{
Information("已完成打包");
Expand Down
17 changes: 0 additions & 17 deletions tools/MaaBuilder/Build.Job.Changelog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@ public partial class Build
}
});

Target UseMaaResourceChangeLog => _ => _
.Triggers(SetMaaChangeLog)
.Executes(() =>
{
if (File.Exists(Parameters.MaaResourceChangeLogFile))
{
Information($"找到 {Parameters.MaaResourceChangeLogFile} 文件,读取内容作为更新日志");
var text = File.ReadAllText(Parameters.MaaResourceChangeLogFile);
ChangeLog = text;
}
else
{
Warning($"未发现 {Parameters.MaaResourceChangeLogFile} 文件,将使用默认值");
}
ChangeLog += $"\n\n对应 Commit:[{Parameters.MainRepo}@{Parameters.CommitHash}](https://github.com/{Parameters.MainRepo}/commit/{Parameters.CommitHashFull})";
});

Target SetMaaChangeLog => _ => _
.Executes(() =>
{
Expand Down
Loading

0 comments on commit f55a321

Please sign in to comment.