Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Clang tidy and web engine cherrypicks #37660

Merged
merged 7 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions lib/web_ui/dev/analyze.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2013 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 'dart:async';

import 'package:args/command_runner.dart';

import 'environment.dart';
import 'pipeline.dart';
import 'utils.dart';

class AnalyzeCommand extends Command<bool> with ArgUtils<bool> {
@override
String get name => 'analyze';

@override
String get description => 'Analyze the Flutter web engine.';

@override
FutureOr<bool> run() async {
final Pipeline buildPipeline = Pipeline(steps: <PipelineStep>[
PubGetStep(),
AnalyzeStep(),
]);
await buildPipeline.run();
return true;
}
}

/// Runs `dart pub get`.
class PubGetStep extends ProcessStep {
@override
String get description => 'pub get';

@override
bool get isSafeToInterrupt => true;

@override
Future<ProcessManager> createProcess() {
print('Running `dart pub get`...');
return startProcess(
environment.dartExecutable,
<String>['pub', 'get'],
workingDirectory: environment.webUiRootDir.path,
);
}
}

/// Runs `dart analyze --fatal-infos`.
class AnalyzeStep extends ProcessStep {
@override
String get description => 'analyze';

@override
bool get isSafeToInterrupt => true;

@override
Future<ProcessManager> createProcess() {
print('Running `dart analyze`...');
return startProcess(
environment.dartExecutable,
<String>['analyze', '--fatal-infos'],
workingDirectory: environment.webUiRootDir.path,
);
}
}
38 changes: 4 additions & 34 deletions lib/web_ui/dev/felt
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,17 @@ else
fi

WEB_UI_DIR="${FLUTTER_DIR}/lib/web_ui"
DEV_DIR="${WEB_UI_DIR}/dev"
DART_TOOL_DIR="${WEB_UI_DIR}/.dart_tool"
DART_PATH="$DART_SDK_DIR/bin/dart"
SNAPSHOT_PATH="${DART_TOOL_DIR}/felt.snapshot"
STAMP_PATH="${DART_TOOL_DIR}/felt.snapshot.stamp"
SCRIPT_PATH="${DEV_DIR}/felt.dart"
REVISION="$(cd "$FLUTTER_DIR"; git rev-parse HEAD)"

if [[ "$FELT_DEBUG" == "true" || "$FELT_DEBUG" == "1" ]]
then
FELT_DEBUG_FLAGS="--enable-vm-service --pause-isolates-on-start"
fi

install_deps() {
# We need to run pub get here before we actually invoke felt.
echo "Running \`dart pub get\` in 'engine/src/flutter/lib/web_ui'"
(cd "$WEB_UI_DIR"; $DART_PATH pub get)

echo "Running \`dart pub get\` in 'engine/src/flutter/web_sdk/web_engine_tester'"
(cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; $DART_PATH pub get)
}

if [[ $KERNEL_NAME == *"Darwin"* ]]
Expand Down Expand Up @@ -135,28 +127,6 @@ then
set -e
fi

if [[ "$FELT_USE_SNAPSHOT" == "false" || "$FELT_USE_SNAPSHOT" == "0" ]]; then
echo "[Snapshot mode: off]"
# Running without snapshot means there is high likelihood of local changes. In
# that case, let's clear the snapshot to avoid any surprises.
rm -f "$SNAPSHOT_PATH"
rm -f "$STAMP_PATH"
install_deps
$DART_SDK_DIR/bin/dart $FELT_DEBUG_FLAGS "$DEV_DIR/felt.dart" $@
else
# Create a new snapshot if any of the following is true:
# * SNAPSHOT_PATH is not a file, or
# * STAMP_PATH is not a file with nonzero size, or
# * Contents of STAMP_PATH is not our local git HEAD revision, or
# * pubspec.yaml last modified after pubspec.lock
if [[ ! -f $SNAPSHOT_PATH || ! -s "$STAMP_PATH" || "$(cat "$STAMP_PATH")" != "$REVISION" || "$WEB_UI_DIR/pubspec.yaml" -nt "$WEB_UI_DIR/pubspec.lock" ]]; then
echo "[Snapshot mode: on] (creating a new snapshot)"
install_deps
mkdir -p $DART_TOOL_DIR

"$DART_SDK_DIR/bin/dart" --snapshot="$SNAPSHOT_PATH" --packages="$WEB_UI_DIR/.dart_tool/package_config.json" "$SCRIPT_PATH"
echo "$REVISION" > "$STAMP_PATH"
fi

$DART_SDK_DIR/bin/dart $FELT_DEBUG_FLAGS --packages="$WEB_UI_DIR/.dart_tool/package_config.json" "$SNAPSHOT_PATH" $@
fi
cd $WEB_UI_DIR
install_deps
(cd $WEB_UI_DIR && $DART_SDK_DIR/bin/dart run $FELT_DEBUG_FLAGS dev/felt.dart $@)
40 changes: 3 additions & 37 deletions lib/web_ui/dev/felt.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,19 @@ FOR %%a IN ("%TMP:~0,-1%") DO SET TMP=%%~dpa
FOR %%a IN ("%TMP:~0,-1%") DO SET ENGINE_SRC_DIR=%%~dpa

SET ENGINE_SRC_DIR=%ENGINE_SRC_DIR:~0,-1%
SET OUT_DIR=%ENGINE_SRC_DIR%\out
SET HOST_DEBUG_UNOPT_DIR=%OUT_DIR%\host_debug_unopt
SET FLUTTER_DIR=%ENGINE_SRC_DIR%\flutter
SET WEB_UI_DIR=%FLUTTER_DIR%\lib\web_ui
SET DEV_DIR=%WEB_UI_DIR%\dev
SET FELT_PATH=%DEV_DIR%\felt.dart
SET DART_TOOL_DIR=%WEB_UI_DIR%\.dart_tool
SET SNAPSHOT_PATH=%DART_TOOL_DIR%\felt.snapshot
SET SDK_PREBUILTS_DIR=%FLUTTER_DIR%\prebuilts
SET PREBUILT_TARGET=windows-x64
IF NOT DEFINED DART_SDK_DIR (
SET DART_SDK_DIR=%SDK_PREBUILTS_DIR%\%PREBUILT_TARGET%\dart-sdk
)
SET DART_BIN=%DART_SDK_DIR%\bin\dart

SET needsHostDebugUnoptRebuild=0
for %%x in (%*) do (
if ["%%~x"]==["--clean"] (
ECHO Clean rebuild requested
SET needsHostDebugUnoptRebuild=1
)
)

IF NOT EXIST %OUT_DIR% (SET needsHostDebugUnoptRebuild=1)
IF NOT EXIST %HOST_DEBUG_UNOPT_DIR% (SET needsHostDebugUnoptRebuild=1)

IF %needsHostDebugUnoptRebuild%==1 (
ECHO Building host_debug_unopt
:: Delete old snapshot, if any, because the new Dart SDK may invalidate it.
IF EXIST "%SNAPSHOT_PATH%" (
del %SNAPSHOT_PATH%
)
CALL gclient sync -D
CALL python %GN% --unoptimized --full-dart-sdk
CALL ninja -C %HOST_DEBUG_UNOPT_DIR%)

cd %WEB_UI_DIR%
IF NOT EXIST "%SNAPSHOT_PATH%" (
ECHO Precompiling felt snapshot
CALL %DART_SDK_DIR%\bin\dart pub get
%DART_BIN% --snapshot="%SNAPSHOT_PATH%" --packages="%WEB_UI_DIR%\.dart_tool\package_config.json" %FELT_PATH%
)

IF "%1"=="test" (
%DART_SDK_DIR%\bin\dart --packages="%WEB_UI_DIR%\.dart_tool\package_config.json" "%SNAPSHOT_PATH%" %* --browser=chrome
) ELSE (
%DART_SDK_DIR%\bin\dart --packages="%WEB_UI_DIR%\.dart_tool\package_config.json" "%SNAPSHOT_PATH%" %*
)
:: We need to invoke pub get here before we actually invoke felt.
%DART_BIN% pub get
%DART_BIN% run dev/felt.dart %*

EXIT /B %ERRORLEVEL%
2 changes: 2 additions & 0 deletions lib/web_ui/dev/felt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io' as io;

import 'package:args/command_runner.dart';

import 'analyze.dart';
import 'build.dart';
import 'clean.dart';
import 'exceptions.dart';
Expand All @@ -19,6 +20,7 @@ CommandRunner<bool> runner = CommandRunner<bool>(
'felt',
'Command-line utility for building and testing Flutter web engine.',
)
..addCommand(AnalyzeCommand())
..addCommand(BuildCommand())
..addCommand(CleanCommand())
..addCommand(GenerateFallbackFontDataCommand())
Expand Down
18 changes: 17 additions & 1 deletion lib/web_ui/dev/steps/compile_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,23 @@ Future<void> buildHostPage() async {
print('Building ${hostDartFile.path}.');
}

final int exitCode = await runProcess(
int exitCode = await runProcess(
environment.dartExecutable,
<String>[
'pub',
'get',
],
workingDirectory: environment.webEngineTesterRootDir.path
);

if (exitCode != 0) {
throw ToolExit(
'Failed to run pub get for web_engine_tester, exit code $exitCode',
exitCode: exitCode,
);
}

exitCode = await runProcess(
environment.dartExecutable,
<String>[
'compile',
Expand Down
12 changes: 10 additions & 2 deletions lib/web_ui/dev/steps/run_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class RunTestsStep implements PipelineStep {

final TestsByRenderer sortedTests = sortTestsByRenderer(testFiles);

bool testsPassed = true;

if (sortedTests.htmlTests.isNotEmpty) {
await _runTestBatch(
testFiles: sortedTests.htmlTests,
Expand All @@ -84,6 +86,7 @@ class RunTestsStep implements PipelineStep {
skiaClient: skiaClient,
overridePathToCanvasKit: overridePathToCanvasKit,
);
testsPassed &= io.exitCode == 0;
}

if (sortedTests.canvasKitTests.isNotEmpty) {
Expand All @@ -98,9 +101,13 @@ class RunTestsStep implements PipelineStep {
skiaClient: skiaClient,
overridePathToCanvasKit: overridePathToCanvasKit,
);
testsPassed &= io.exitCode == 0;
}

if (sortedTests.skwasmTests.isNotEmpty) {
// TODO(jacksongardner): enable this test suite on safari
// For some reason, Safari is flaky when running the Skwasm test suite
// See https://github.com/flutter/flutter/issues/115312
if (browserName != kSafari && sortedTests.skwasmTests.isNotEmpty) {
await _runTestBatch(
testFiles: sortedTests.skwasmTests,
renderer: Renderer.skwasm,
Expand All @@ -112,11 +119,12 @@ class RunTestsStep implements PipelineStep {
skiaClient: skiaClient,
overridePathToCanvasKit: overridePathToCanvasKit,
);
testsPassed &= io.exitCode == 0;
}

await browserEnvironment.cleanup();

if (io.exitCode != 0) {
if (!testsPassed) {
throw ToolExit('Some tests failed');
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1747,5 +1747,6 @@ half4 main(vec2 fragCoord) {
!.makeShader(<double>[1.0, 0.0, 0.0, 1.0]);

expect(shaderWithUniform, isNotNull);
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: true);
}
5 changes: 3 additions & 2 deletions lib/web_ui/test/canvaskit/fragment_program_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void testMain() {
await ui.webOnlyInitializePlatform();
});

group('FragmentProgram can be created from JSON IPLR bundle', () async {
test('FragmentProgram can be created from JSON IPLR bundle', () async {
final Uint8List data = utf8.encode(kJsonIPLR) as Uint8List;
final CkFragmentProgram program = await CkFragmentProgram.fromBytes('test', data);

Expand All @@ -207,5 +207,6 @@ void testMain() {
shader.setFloat(0, 5);
shader2.dispose();
expect(shader2.debugDisposed, true);
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: true);
}
6 changes: 4 additions & 2 deletions lib/web_ui/test/canvaskit/path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ void testMain() {
expect(iter2.moveNext(), isFalse);
expect(() => iter1.current, throwsRangeError);
expect(() => iter2.current, throwsRangeError);
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: true);

test('CkPath.reset', () {
final ui.Path path = ui.Path();
Expand Down Expand Up @@ -170,7 +171,8 @@ void testMain() {
expect(measure0.extractPath(0, 15).getBounds(), const ui.Rect.fromLTRB(0, 0, 10, 5));
expect(measure1.contourIndex, 1);
expect(measure1.extractPath(0, 15).getBounds(), const ui.Rect.fromLTRB(20, 20, 30, 25));
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: true);

test('Path.from', () {
const ui.Rect rect1 = ui.Rect.fromLTRB(0, 0, 10, 10);
Expand Down
5 changes: 3 additions & 2 deletions lib/web_ui/test/canvaskit/surface_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ void testMain() {
// A new context is created.
expect(afterContextLost, isNot(same(before)));
},
// Firefox doesn't have the WEBGL_lose_context extension.
skip: isFirefox || isSafari,
// Firefox and Safari don't have the WEBGL_lose_context extension.
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
skip: true,
);

// Regression test for https://github.com/flutter/flutter/issues/75286
Expand Down
6 changes: 4 additions & 2 deletions lib/web_ui/test/text_editing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,8 @@ Future<void> testMain() async {
expect(input.style.outline, 'none');
expect(input.style.border, 'none');
expect(input.style.textShadow, 'none');
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: isFirefox);

test('prevents effect of (forced-colors: active)', () {
editingStrategy!.enable(
Expand All @@ -2578,7 +2579,8 @@ Future<void> testMain() async {

final DomHTMLElement input = editingStrategy!.activeDomElement;
expect(input.style.getPropertyValue('forced-color-adjust'), 'none');
});
// TODO(hterkelsen): https://github.com/flutter/flutter/issues/115327
}, skip: isFirefox || isSafari);
});
}

Expand Down
Loading