mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] fix path escaping on in depfile generation (#50538)
This commit is contained in:
parent
c6e45ffa30
commit
fa44a1cf37
@ -74,11 +74,15 @@ class Depfile {
|
|||||||
void _writeFilesToBuffer(List<File> files, StringBuffer buffer) {
|
void _writeFilesToBuffer(List<File> files, StringBuffer buffer) {
|
||||||
for (final File outputFile in files) {
|
for (final File outputFile in files) {
|
||||||
if (globals.platform.isWindows) {
|
if (globals.platform.isWindows) {
|
||||||
// Paths in a depfile have to be escaped on windows.
|
// Foward slashes and spaces in a depfile have to be escaped on windows.
|
||||||
final String escapedPath = outputFile.path.replaceAll(r'\', r'\\');
|
final String path = outputFile.path
|
||||||
buffer.write(' $escapedPath');
|
.replaceAll(r'\', r'\\')
|
||||||
|
.replaceAll(r' ', r'\ ');
|
||||||
|
buffer.write(' $path');
|
||||||
} else {
|
} else {
|
||||||
buffer.write(' ${outputFile.path}');
|
final String path = outputFile.path
|
||||||
|
.replaceAll(r' ', r'\ ');
|
||||||
|
buffer.write(' $path');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import 'package:file/memory.dart';
|
|||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
import 'package:flutter_tools/src/build_system/depfile.dart';
|
import 'package:flutter_tools/src/build_system/depfile.dart';
|
||||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
|
import 'package:platform/platform.dart';
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/testbed.dart';
|
import '../../src/testbed.dart';
|
||||||
@ -66,6 +67,39 @@ C:\\a.txt: C:\\b.txt
|
|||||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
test('Can escape depfile with windows file paths and spaces in directory names', () => testbed.run(() {
|
||||||
|
final File inputFile = globals.fs.directory(r'Hello Flutter').childFile('a.txt').absolute
|
||||||
|
..createSync(recursive: true);
|
||||||
|
final File outputFile = globals.fs.directory(r'Hello Flutter').childFile('b.txt').absolute
|
||||||
|
..createSync();
|
||||||
|
final Depfile depfile = Depfile(<File>[inputFile], <File>[outputFile]);
|
||||||
|
final File outputDepfile = globals.fs.file('depfile');
|
||||||
|
depfile.writeToFile(outputDepfile);
|
||||||
|
|
||||||
|
expect(outputDepfile.readAsStringSync(), contains(r'C:\\Hello\ Flutter\\a.txt'));
|
||||||
|
expect(outputDepfile.readAsStringSync(), contains(r'C:\\Hello\ Flutter\\b.txt'));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||||
|
Platform: () => FakePlatform(operatingSystem: 'windows'),
|
||||||
|
}));
|
||||||
|
|
||||||
|
test('Can escape depfile with spaces in directory names', () => testbed.run(() {
|
||||||
|
final File inputFile = globals.fs.directory(r'Hello Flutter').childFile('a.txt').absolute
|
||||||
|
..createSync(recursive: true);
|
||||||
|
final File outputFile = globals.fs.directory(r'Hello Flutter').childFile('b.txt').absolute
|
||||||
|
..createSync();
|
||||||
|
final Depfile depfile = Depfile(<File>[inputFile], <File>[outputFile]);
|
||||||
|
final File outputDepfile = globals.fs.file('depfile');
|
||||||
|
depfile.writeToFile(outputDepfile);
|
||||||
|
|
||||||
|
expect(outputDepfile.readAsStringSync(), contains(r'/Hello\ Flutter/a.txt'));
|
||||||
|
expect(outputDepfile.readAsStringSync(), contains(r'/Hello\ Flutter/b.txt'));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix),
|
||||||
|
Platform: () => FakePlatform(operatingSystem: 'linux'),
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
test('Resillient to weird whitespace', () => testbed.run(() {
|
test('Resillient to weird whitespace', () => testbed.run(() {
|
||||||
final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(r'''
|
final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(r'''
|
||||||
a.txt
|
a.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user