Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android progress indication and refactor of progress logic #10

Merged
merged 1 commit into from
Mar 21, 2024
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
5 changes: 5 additions & 0 deletions packages/vscode-extension/lib/android/initscript.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ gradle.allprojects { project ->
}
}
}

// This is a functionality that is used by BuildAndroidProgressProcessor
gradle.taskGraph.whenReady { graph ->
println "React-Native-IDE:TaskGraphSize: ${graph.allTasks.size()}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { BuildProgressProcessor } from "./BuildProgressProcessor";

export class BuildAndroidProgressProcessor implements BuildProgressProcessor {
private completedTasks: number = 0;
private tasksToComplete: number = 0;

constructor(private progressListener: (newProgress: number) => void) {}

private updateProgress() {
if (!this.tasksToComplete) {
return;
}
this.progressListener(this.completedTasks / this.tasksToComplete);
}

processLine(line: string): void {
const taskGrapfSizeMatch = /React-Native-IDE:TaskGraphSize: (\d+)/m.exec(line);

if (taskGrapfSizeMatch) {
this.tasksToComplete += Number(taskGrapfSizeMatch[1]);
}
const taskExecutedMatch = /> Task /m.exec(line);
if (taskExecutedMatch) {
this.completedTasks++;
this.updateProgress();
}
}
}
11 changes: 8 additions & 3 deletions packages/vscode-extension/src/builders/BuildManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
if (platform === Platform.Android) {
const cancelToken = new CancelToken();
return new DisposableBuildImpl(
this.startAndroidBuild(forceCleanBuild, cancelToken),
this.startAndroidBuild(forceCleanBuild, cancelToken, progressListener),
cancelToken
);
} else {
Expand All @@ -107,7 +107,7 @@
ANDROID_BUILD_CACHE_KEY
) as AndroidBuildCacheInfo;

if (cacheInfo && cacheInfo.fingerprint == newFingerprint) {

Check warning on line 110 in packages/vscode-extension/src/builders/BuildManager.ts

View workflow job for this annotation

GitHub Actions / check

Expected '===' and instead saw '=='
const build = cacheInfo.buildResult;

// We have to check if the user removed the build that was cached.
Expand All @@ -127,7 +127,11 @@
return undefined;
}

private async startAndroidBuild(forceCleanBuild: boolean, cancelToken: CancelToken) {
private async startAndroidBuild(
forceCleanBuild: boolean,
cancelToken: CancelToken,
progressListener: (newProgress: number) => void
) {
const newFingerprint = await generateWorkspaceFingerprint();
if (!forceCleanBuild) {
const buildResult = await this.loadAndroidCachedBuild(newFingerprint);
Expand All @@ -147,7 +151,8 @@
getAppRootFolder(),
forceCleanBuild,
cancelToken,
this.buildOutputChannel!
this.buildOutputChannel!,
progressListener
);
const buildResult: AndroidBuildResult = { ...build, platform: Platform.Android };

Expand All @@ -165,7 +170,7 @@
IOS_BUILD_CACHE_KEY
) as IOSBuildCacheInfo;

if (cacheInfo && cacheInfo.fingerprint == newFingerprint) {

Check warning on line 173 in packages/vscode-extension/src/builders/BuildManager.ts

View workflow job for this annotation

GitHub Actions / check

Expected '===' and instead saw '=='
const build = cacheInfo.buildResult;

// We have to check if the user removed the build that was cached.
Expand Down
12 changes: 8 additions & 4 deletions packages/vscode-extension/src/builders/buildAndroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import { Logger } from "../Logger";
import { exec, lineReader } from "../utilities/subprocess";
import { CancelToken } from "./BuildManager";

import path from "path";
import fs from "fs";
import { OutputChannel, window } from "vscode";
import { extensionContext } from "../utilities/extensionContext";
import { Project } from "../project/project";
import { BuildAndroidProgressProcessor } from "./BuildAndroidProgressProcessor";

const BUILD_TOOLS_PATH = path.join(ANDROID_HOME, "build-tools");
const RELATIVE_APK_PATH = "app/build/outputs/apk/debug/app-debug.apk";
Expand Down Expand Up @@ -49,7 +48,8 @@
appRootFolder: string,
forceCleanBuild: boolean,
cancelToken: CancelToken,
outputChannel: OutputChannel
outputChannel: OutputChannel,
progressListener: (newProgress: number) => void
) {
const androidSourceDir = getAndroidSourceDir(appRootFolder);
const cpuArchitecture = getCpuArchitecture();
Expand All @@ -66,12 +66,16 @@
const buildProcess = cancelToken.adapt(
exec("./gradlew", gradleArgs, {
cwd: androidSourceDir,
env: { ...process.env, JAVA_HOME, ANDROID_HOME },

Check warning on line 69 in packages/vscode-extension/src/builders/buildAndroid.ts

View workflow job for this annotation

GitHub Actions / check

Object Literal Property name `JAVA_HOME` must match one of the following formats: camelCase

Check warning on line 69 in packages/vscode-extension/src/builders/buildAndroid.ts

View workflow job for this annotation

GitHub Actions / check

Object Literal Property name `ANDROID_HOME` must match one of the following formats: camelCase
buffer: false,
})
);
const buildAndroidProgressProcessor = new BuildAndroidProgressProcessor(progressListener);
outputChannel.clear();
lineReader(buildProcess).onLineRead(outputChannel.appendLine);
lineReader(buildProcess).onLineRead((line) => {
outputChannel.appendLine(line);
buildAndroidProgressProcessor.processLine(line);
});

await buildProcess;
Logger.debug("Android build sucessful");
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/common/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

// important: order of values in this enum matters
export enum StartupMessage {
InitializingDevice = "Initializing device",

Check warning on line 27 in packages/vscode-extension/src/common/Project.ts

View workflow job for this annotation

GitHub Actions / check

Enum Member name `InitializingDevice` must match one of the following formats: camelCase
StartingPackager = "Starting packager",

Check warning on line 28 in packages/vscode-extension/src/common/Project.ts

View workflow job for this annotation

GitHub Actions / check

Enum Member name `StartingPackager` must match one of the following formats: camelCase
BootingDevice = "Booting device",
Building = "Building",
Installing = "Installing",
Expand Down Expand Up @@ -76,7 +76,7 @@

getDeviceSettings(): Promise<DeviceSettings>;
updateDeviceSettings(deviceSettings: DeviceSettings): Promise<void>;
stageProgressListener(newStageProgress: number): void;
stageProgressListener(newStageProgress: number, stage: string): void;

resumeDebugger(): Promise<void>;
stepOverDebugger(): Promise<void>;
Expand Down
9 changes: 6 additions & 3 deletions packages/vscode-extension/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {

Logger.debug(`Launching metro`);
const waitForMetro = this.metro.start(forceCleanBuild, (newStageProgress: number) => {
this.stageProgressListener(newStageProgress);
this.stageProgressListener(newStageProgress, StartupMessage.WaitingForAppToLoad);
});
}

Expand Down Expand Up @@ -290,7 +290,10 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
await this.deviceSession?.changeDeviceSettings(settings);
this.eventEmitter.emit("deviceSettingsChanged", this.deviceSettings);
}
public async stageProgressListener(newStageProgress: number) {
public async stageProgressListener(newStageProgress: number, stage: string) {
if (stage !== this.projectState.startupMessage) {
return;
}
if (newStageProgress < this.projectState.stageProgress) {
return;
}
Expand Down Expand Up @@ -345,7 +348,7 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
deviceInfo.platform,
forceCleanBuild,
(newStageProgress: number) => {
this.stageProgressListener(newStageProgress);
this.stageProgressListener(newStageProgress, StartupMessage.Building);
}
)
);
Expand Down
Loading