Don't hardcode ink sparkle spir-v (#102674)

This commit is contained in:
Zachary Anderson
2022-05-04 09:28:45 -07:00
committed by GitHub
parent d1bbd822c0
commit 577919dbfe
11 changed files with 429 additions and 3111 deletions

View File

@@ -8,6 +8,7 @@ import 'dart:convert';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
@@ -387,6 +388,63 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
});
group('Shaders: ', () {
MemoryFileSystem fileSystem;
Artifacts artifacts;
String impellerc;
Directory output;
String shaderPath;
String outputPath;
setUp(() {
artifacts = Artifacts.test();
fileSystem = MemoryFileSystem.test();
impellerc = artifacts.getHostArtifact(HostArtifact.impellerc).path;
fileSystem.file(impellerc).createSync(recursive: true);
output = fileSystem.directory('asset_output')..createSync(recursive: true);
shaderPath = fileSystem.path.join('assets', 'shader.frag');
outputPath = fileSystem.path.join(output.path, 'assets', 'shader.frag');
fileSystem.file(shaderPath).createSync(recursive: true);
});
testUsingContext('Including a shader triggers the shader compiler', () async {
fileSystem.file('.packages').createSync();
fileSystem.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
flutter:
assets:
- assets/shader.frag
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 0);
await writeBundle(output, bundle.entries, loggerOverride: testLogger);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--flutter-spirv',
'--spirv=$outputPath',
'--input=/$shaderPath',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
},
),
]),
});
});
testUsingContext('Does not insert dummy file into additionalDependencies '
'when wildcards are used by dependencies', () async {
globals.fs.file('.packages').writeAsStringSync(r'''

View File

@@ -0,0 +1,81 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
import '../../../src/common.dart';
import '../../../src/fake_process_manager.dart';
const String shaderPath = '/shaders/my_shader.frag';
const String notShaderPath = '/shaders/not_a_shader.file';
const String outputPath = '/output/shaders/my_shader.spv';
void main() {
late BufferLogger logger;
late MemoryFileSystem fileSystem;
late Artifacts artifacts;
late String impellerc;
setUp(() {
artifacts = Artifacts.test();
fileSystem = MemoryFileSystem.test();
logger = BufferLogger.test();
impellerc = artifacts.getHostArtifact(HostArtifact.impellerc).path;
fileSystem.file(impellerc).createSync(recursive: true);
fileSystem.file(shaderPath).createSync(recursive: true);
fileSystem.file(notShaderPath).createSync(recursive: true);
});
testWithoutContext('compileShader returns false for non-shader files', () async {
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: FakeProcessManager.empty(),
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
expect(
await shaderCompiler.compileShader(
input: fileSystem.file(notShaderPath),
outputPath: outputPath,
),
false,
);
});
testWithoutContext('compileShader returns true for shader files', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--flutter-spirv',
'--spirv=$outputPath',
'--input=$shaderPath',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
},
),
]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
expect(
await shaderCompiler.compileShader(
input: fileSystem.file(shaderPath),
outputPath: outputPath,
),
true,
);
expect(fileSystem.file(outputPath).existsSync(), true);
});
}