Check for bad characters in path on Windows build (#107949)
* Check for bad characters in path on Windows build * Doc comments * Fix formatting * Commenting/formatting * Link to issue in comment * Comments, formatting * Global var rename
This commit is contained in:
parent
2a8a0890e2
commit
1e2be6ed54
@ -19,12 +19,29 @@ import '../globals.dart' as globals;
|
|||||||
import '../migrations/cmake_custom_command_migration.dart';
|
import '../migrations/cmake_custom_command_migration.dart';
|
||||||
import 'visual_studio.dart';
|
import 'visual_studio.dart';
|
||||||
|
|
||||||
|
// These characters appear to be fine: @%()-+_{}[]`~
|
||||||
|
const String _kBadCharacters = r"'#!$^&*=|,;<>?";
|
||||||
|
|
||||||
/// Builds the Windows project using msbuild.
|
/// Builds the Windows project using msbuild.
|
||||||
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
|
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
|
||||||
String? target,
|
String? target,
|
||||||
VisualStudio? visualStudioOverride,
|
VisualStudio? visualStudioOverride,
|
||||||
SizeAnalyzer? sizeAnalyzer,
|
SizeAnalyzer? sizeAnalyzer,
|
||||||
}) async {
|
}) async {
|
||||||
|
// MSBuild files generated by CMake do not properly escape some characters
|
||||||
|
// In the directories. This check produces more meaningful error messages
|
||||||
|
// on failure as pertains to https://github.com/flutter/flutter/issues/104802
|
||||||
|
final String projectPath = windowsProject.parent.directory.absolute.path;
|
||||||
|
final bool badPath = _kBadCharacters.runes
|
||||||
|
.any((int i) => projectPath.contains(String.fromCharCode(i)));
|
||||||
|
if (badPath) {
|
||||||
|
throwToolExit(
|
||||||
|
'Path $projectPath contains invalid characters in "$_kBadCharacters". '
|
||||||
|
'Please rename your directory so as to not include any of these characters '
|
||||||
|
'and retry.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!windowsProject.cmakeFile.existsSync()) {
|
if (!windowsProject.cmakeFile.existsSync()) {
|
||||||
throwToolExit(
|
throwToolExit(
|
||||||
'No Windows desktop project configured. See '
|
'No Windows desktop project configured. See '
|
||||||
|
@ -21,9 +21,11 @@ import '../../src/fakes.dart';
|
|||||||
import '../../src/test_flutter_command_runner.dart';
|
import '../../src/test_flutter_command_runner.dart';
|
||||||
|
|
||||||
const String flutterRoot = r'C:\flutter';
|
const String flutterRoot = r'C:\flutter';
|
||||||
const String buildFilePath = r'C:\windows\CMakeLists.txt';
|
const String buildFilePath = r'windows\CMakeLists.txt';
|
||||||
const String visualStudioPath = r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community';
|
const String visualStudioPath =
|
||||||
const String _cmakePath = visualStudioPath + r'\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe';
|
r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community';
|
||||||
|
const String _cmakePath = visualStudioPath +
|
||||||
|
r'\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe';
|
||||||
const String _defaultGenerator = 'Visual Studio 16 2019';
|
const String _defaultGenerator = 'Visual Studio 16 2019';
|
||||||
|
|
||||||
final Platform windowsPlatform = FakePlatform(
|
final Platform windowsPlatform = FakePlatform(
|
||||||
@ -80,7 +82,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
_cmakePath,
|
_cmakePath,
|
||||||
'-S',
|
'-S',
|
||||||
fileSystem.path.dirname(buildFilePath),
|
fileSystem.path.absolute(fileSystem.path.dirname(buildFilePath)),
|
||||||
'-B',
|
'-B',
|
||||||
r'build\windows',
|
r'build\windows',
|
||||||
'-G',
|
'-G',
|
||||||
@ -933,6 +935,35 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
|
|||||||
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform),
|
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: windowsPlatform),
|
||||||
Usage: () => usage,
|
Usage: () => usage,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Confirms that running for Windows in a directory with a
|
||||||
|
// bad character (' in this case) throws the desired error message
|
||||||
|
// If the issue https://github.com/flutter/flutter/issues/104802 ever
|
||||||
|
// is resolved on the VS side, we can allow these paths again
|
||||||
|
testUsingContext('Test bad path characters', () async {
|
||||||
|
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
|
||||||
|
final BuildWindowsCommand command = BuildWindowsCommand()
|
||||||
|
..visualStudioOverride = fakeVisualStudio;
|
||||||
|
fileSystem.currentDirectory = fileSystem.directory("test_'path")
|
||||||
|
..createSync();
|
||||||
|
final String absPath = fileSystem.currentDirectory.absolute.path;
|
||||||
|
setUpMockCoreProjectFiles();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
createTestCommandRunner(command).run(const <String>['windows', '--no-pub']),
|
||||||
|
throwsToolExit(
|
||||||
|
message:
|
||||||
|
'Path $absPath contains invalid characters in "\'#!\$^&*=|,;<>?". '
|
||||||
|
'Please rename your directory so as to not include any of these characters '
|
||||||
|
'and retry.',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
Platform: () => windowsPlatform,
|
||||||
|
FileSystem: () => fileSystem,
|
||||||
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
|
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeVisualStudio extends Fake implements VisualStudio {
|
class FakeVisualStudio extends Fake implements VisualStudio {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user