Skip to content

Commit d465ed9

Browse files
committed
Detect Dart SDK repo even when not the first Git project in the workspace
Fixes #4011.
1 parent cbe3435 commit d465ed9

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎src/extension/sdk/utils.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Logger, Sdks, SdkSearchResults, WorkspaceConfig, WritableWorkspaceConfi
66
import { flatMap, isDartSdkFromFlutter, notUndefined } from "../../shared/utils";
77
import { extractFlutterSdkPathFromPackagesFile, fsPath, getSdkVersion, hasPubspec, projectReferencesFlutterSdk } from "../../shared/utils/fs";
88
import { resolvedPromise } from "../../shared/utils/promises";
9-
import { processBazelWorkspace, processFuchsiaWorkspace, processKnownGitRepositories } from "../../shared/utils/workspace";
9+
import { processBazelWorkspace, processDartSdkRepository, processFuchsiaWorkspace } from "../../shared/utils/workspace";
1010
import { envUtils, getAllProjectFolders, getDartWorkspaceFolders } from "../../shared/vscode/utils";
1111
import { WorkspaceContext } from "../../shared/workspace";
1212
import { Analytics } from "../analytics";
@@ -230,7 +230,7 @@ export class SdkUtils {
230230
return undefined;
231231
};
232232

233-
await processWorkspaceType(findGitRoot, processKnownGitRepositories);
233+
await processWorkspaceType(findDartSdkRoot, processDartSdkRepository);
234234
// TODO: Remove this lambda when the preview flag is removed.
235235
await processWorkspaceType(findBazelWorkspaceRoot, (l, c, b) => processBazelWorkspace(l, c, b, config.previewBazelWorkspaceCustomScripts));
236236
const fuchsiaRoot = await processWorkspaceType(findFuchsiaRoot, processFuchsiaWorkspace);
@@ -467,6 +467,14 @@ async function findGitRoot(logger: Logger, folder: string): Promise<string | und
467467
return findRootContaining(folder, ".git");
468468
}
469469

470+
async function findDartSdkRoot(logger: Logger, folder: string): Promise<string | undefined> {
471+
const gitRoot = await findGitRoot(logger, folder);
472+
if (gitRoot && fs.existsSync(path.join(gitRoot, "README.dart-sdk")) && fs.existsSync(path.join(gitRoot, "DEPS")))
473+
return gitRoot;
474+
else
475+
return undefined;
476+
}
477+
470478
function findRootContaining(folder: string, childName: string, expectFile = false): string | undefined {
471479
if (folder) {
472480
// Walk up the directories from the workspace root, and see if there

‎src/shared/utils/workspace.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import * as path from "path";
33
import { isWin, MAX_VERSION } from "../constants";
44
import { CustomScript, Logger, WritableWorkspaceConfig } from "../interfaces";
55

6-
export function processKnownGitRepositories(logger: Logger, config: WritableWorkspaceConfig, gitRoot: string) {
7-
const isDartSdkRepo = fs.existsSync(path.join(gitRoot, "README.dart-sdk")) && fs.existsSync(path.join(gitRoot, "DEPS"));
8-
if (isDartSdkRepo) {
9-
config.disableAutomaticPackageGet = true;
10-
// The Dart SDKs tests cannot run using pub, so also force them to use the VM.
11-
config.useVmForTests = true;
12-
}
6+
export function processDartSdkRepository(logger: Logger, config: WritableWorkspaceConfig, dartSdkRoot: string) {
7+
config.disableAutomaticPackageGet = true;
8+
// The Dart SDKs tests cannot run using pub, so also force them to use the VM.
9+
config.useVmForTests = true;
1310
}
1411

1512
export function processFuchsiaWorkspace(logger: Logger, config: WritableWorkspaceConfig, fuchsiaRoot: string) {

0 commit comments

Comments
 (0)