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

Check for BUILD file for bazel projects only #4735

Merged
merged 3 commits into from
Aug 4, 2020
Merged

Conversation

helin24
Copy link
Member

@helin24 helin24 commented Aug 4, 2020

We removed a check for BUILD to fix #4692 but this caused problems for internal projects.

return dir.isDirectory() && (
dir.findChild("pubspec.yaml") != null || dir.findChild(".packages") != null);
dir.findChild("pubspec.yaml") != null ||
(WorkspaceCache.getInstance(project).isBazel() && dir.findChild("BUILD") != null) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking for a BUILD file could be fragile. Instead ,it would be better to check whether the directory is under the bazel root directory. I think that is the equivalent of what isAppDir is doing externally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable, but how do we define the bazel root directory? Is it related to what we're doing in Workspace, e.g. findContainingWorkspaceFile or ProjectRootManager.getInstance(p).getContentRoots()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findContainingWorkspaceFile will give you a breadcrumb to the answer. If you go back up the relative path from that directory to google3/ you will be in the right place.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this (i.e. asking for the "type" of workspace) be part of the flutter_tool interface? We are not able to customize the plugin easily in g3 but we are able to customize the tooling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear. We are actually extremely robust on determining whether a project is bazel by checking for the existence of dart/config/intellij-plugins/flutter.json. This bug is a case of code being written that forgets that not all Dart projects have pubspec.yaml or .packages file. A solution would be to audit the code base for all checks for pubspec.yaml and replace them with a helper call that is specialized for bazel workspaces.

One advantage of the current system is we don't have to make users configure the flutter sdk directory manually for bazel projects as we are able to determine it automatically. If we relied on specifying a flutter sdk directory we would have a chicken and egg problem as a user would have to have configured flutter before we could ask it whether a particular directory is a bazel or vanilla project.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

Audit the code base for all checks for pubspec.yaml and replace them with a helper call that is specialized for bazel workspaces.

SGTM. I implemented a similar strategy for dartdoc where all "package" related operations go through an overridable class called PackageInfo rather than random code doing package processing. This also has the added advantage that what the plugin needs from pubspec.yaml is well defined and testable rather than being scattered all over the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a PackageInfo class sounds like a clean solution. Filed #4738 to track cleaning up this tech debt.

@helin24 helin24 merged commit 0cc436a into flutter:master Aug 4, 2020
@helin24 helin24 deleted the build branch August 4, 2020 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't run debug while main.dart has a build diretory sibling
3 participants