Skip to content

ide: Include .idea/zulip.iml #637

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

Merged

Conversation

chrisbobbe
Copy link
Collaborator

This has some useful excludeFolder items that should help Android Studio see that certain files are not part of our project and should be excluded in searches that are supposed to be limited to "project files".

@chrisbobbe chrisbobbe added the a-tools Our own development tooling, scripts, and infrastructure label Apr 26, 2024
@chrisbobbe chrisbobbe requested a review from gnprice April 26, 2024 23:26
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks for sending this!

One complication in trying to merge something like this for general use is that Android Studio seems to pick a variety of names for this .iml file.

  • For you, it's .idea/zulip-flutter.iml.
  • For me on my desktop in the office, it's .idea/flutter.iml.

From those two, it seemed like the pattern was that it uses the basename of the project's parent directory — your clone of this repo is in a directory whose name ends in …/zulip-flutter, and mine is at ~/z/flutter. (Generally I leave the zulip- prefix off of these directories' names, to keep down the amount of typing or tab-completion to get to them. Similarly I have my zulip-mobile tree at ~/z/mobile.)

But then the wrinkles continue:

  • For me on my main desktop, at home, the file is at zulip.iml — outside the .idea/ directory, at the root of the tree.

    (Meanwhile this tree is at ~/z/flutterz — same idea as above, but I also wanted it to have a different basename from my checkout of Flutter itself, because parts of the Android Studio UI identify a project by just the basename of its directory.)

I don't know why that one's in a different place.

… Aha — it's because flutter create put it there, back when I began the prototype. See the template file packages/flutter_tools/templates/app_shared/projectName.iml.tmpl in the Flutter upstream tree.

So, maybe we can put the file there and it'll work? The experiment to try would be:

  • Exit Android Studio.
  • Move your .idea/zulip-flutter.iml to just zulip.iml.
  • Re-open Android Studio.
  • Confirm that it's using the file from its new location: that it hasn't made any new .iml file, and that the excluded folders are excluded.

<excludeFolder url="file://$MODULE_DIR$/packages/zulip_plugin/.pub" />
<excludeFolder url="file://$MODULE_DIR$/packages/zulip_plugin/build" />
<excludeFolder url="file://$MODULE_DIR$/packages/zulip_plugin/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/macos/Flutter/ephemeral" />
Copy link
Member

Choose a reason for hiding this comment

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

Another good line to add, from looking at what I have on my home desktop:

      <excludeFolder url="file://$MODULE_DIR$/scripts/icons/node_modules" />

<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral" />
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral" />
</content>
<orderEntry type="inheritedJdk" />
Copy link
Member

Choose a reason for hiding this comment

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

This element is absent in the file on my home desktop. I'm not sure what it means.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'm not sure either. Maybe leave it out, and if we need it we'll eventually find out?

@chrisbobbe
Copy link
Collaborator Author

So, maybe we can put the file [at the root of the tree] and it'll work? The experiment to try would be:

  • Exit Android Studio.
  • Move your .idea/zulip-flutter.iml to just zulip.iml.
  • Re-open Android Studio.
  • Confirm that it's using the file from its new location: that it hasn't made any new .iml file, and that the excluded folders are excluded.

I think I've gotten this to work, but I think an .idea/modules.xml file is involved in making it work at the new location. Here is the content of that file when it works:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/zulip.iml" />
    </modules>
  </component>
</project>

Should we commit that file too, and if so, is it OK for it to stay in .idea/ or do we think it's better to move it out to the root of the tree?

Is there a reason to prefer moving the .iml file out to the root? I think it's working for me even if the .iml file is .idea/zulip.iml. And when it's there—even with that name zulip.iml instead of zulip-flutter.iml—it seems to work even in the absence of an .idea/modules.xml file.

@gnprice
Copy link
Member

gnprice commented Apr 30, 2024

I think it's working for me even if the .iml file is .idea/zulip.iml. And when it's there—even with that name zulip.iml instead of zulip-flutter.iml—it seems to work even in the absence of an .idea/modules.xml file.

Sure, let's try that, then.

an .idea/modules.xml file

FWIW I have such a file too, and it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/zulip.iml" filepath="$PROJECT_DIR$/zulip.iml" />
      <module fileurl="file://$PROJECT_DIR$/android/zulip_android.iml" filepath="$PROJECT_DIR$/android/zulip_android.iml" />
    </modules>
  </component>
</project>

The timestamp looks like when I started the prototype. There's a corresponding template in the Flutter tree, which fits.

The android/zulip_android.iml file is another one I have locally, that flutter create created. After we have this .iml file for the main project merged, I may follow up by dealing with that one; it's a lower priority because it's much less common for us to open the android/ subtree as its own project (and indeed I'm not sure anyone other than me ever has).

@chrisbobbe
Copy link
Collaborator Author

it's much less common for us to open the android/ subtree as its own project (and indeed I'm not sure anyone other than me ever has).

I've found this very helpful when I want to use Android Studio's "merged manifest" feature. The "Merged Manifest" tab isn't offered when you open the project from the root, but it is offered when you open the android/ subtree as its own project. I remember searching online for why the "Merged Manifest" tab wasn't there and not finding anything helpful. Maybe worth pointing out this solution in a comment at the top of android/app/src/main/AndroidManifest.xml? I could do that.

@chrisbobbe chrisbobbe force-pushed the pr-exclude-from-project-files-android-studio branch from 9148cc6 to f18a408 Compare May 1, 2024 23:56
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

@chrisbobbe chrisbobbe changed the title ide: Include .idea/zulip-flutter.iml ide: Include .idea/zulip.iml May 3, 2024
@gnprice
Copy link
Member

gnprice commented May 4, 2024

Thanks! Pushed to the branch a couple of changes, based on testing on my office desktop just now and our in-person discussion.

@gnprice
Copy link
Member

gnprice commented May 4, 2024

Also tried that updated branch on my laptop, and it seems to work smoothly there too.

@chrisbobbe chrisbobbe force-pushed the pr-exclude-from-project-files-android-studio branch from 64ae2e0 to 08a7116 Compare May 6, 2024 20:44
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review, testing, and updates to the branch! Revision pushed, incorporating those proposed changes.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks! Comments below. One minor line to change… and then one boring-looking line that's missing that turns out to be important.

I think this is very close, though — I'm hoping that after those two tweaks, it'll be ready.

.idea/zulip.iml Outdated
<excludeFolder url="file://$MODULE_DIR$/packages/zulip_plugin/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/packages/zulip_plugin/.pub" />
<excludeFolder url="file://$MODULE_DIR$/packages/zulip_plugin/build" />
<excludeFolder url="file://$MODULE_DIR$/scripts/icons/node_modules" />
Copy link
Member

Choose a reason for hiding this comment

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

Ha, what this should actually be (contra #637 (comment) ) is:

Suggested change
<excludeFolder url="file://$MODULE_DIR$/scripts/icons/node_modules" />
<excludeFolder url="file://$MODULE_DIR$/tools/icons/node_modules" />

There is no scripts/; that must have been… aha, it's what tools/ was called before e5d1e3b.

If we'd had this file in those versions of the tree, we'd want it to say scripts/; but we didn't, and at this point it should say tools/.


My local zulip.iml has both; it was just hard to spot with all the noise from .dart_tool, .pub, and build in every plugin package. To make sure there's nothing else hiding there, here it is with all the noise stripped out:

$ grep -vFe '/.dart_tool"' -e '/.pub"' -e '/build"' zulip.iml 
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <excludeFolder url="file://$MODULE_DIR$/scripts/icons/node_modules" />
      <excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral" />
      <excludeFolder url="file://$MODULE_DIR$/tools/icons/node_modules" />
      <excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral" />
    </content>
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Dart SDK" level="project" />
    <orderEntry type="library" name="Flutter Plugins" level="project" />
    <orderEntry type="library" name="Dart Packages" level="project" />
  </component>
</module>

So, looks like everything else there is covered in this revision. There is this line:

    <orderEntry type="library" name="Dart Packages" level="project" />

But I can't find anything missing as a consequence of leaving that line out. For example…

… hmm no. I tried a search and found it did get results from "Dart Packages":
image

But then I found that that entry had been added back in somehow:

--- .idea/zulip.iml
+++ .idea/zulip.iml
@@ -18,5 +18,6 @@
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="library" name="Dart SDK" level="project" />
     <orderEntry type="library" name="Flutter Plugins" level="project" />
+    <orderEntry type="library" name="Dart Packages" level="project" />
   </component>
 </module>
\ No newline at end of file

I discarded that with git reset --hard, tried again, and now I'm only seeing the results that can also be found under "Flutter Plugins":
image

Similarly try searching for "Table" (a class from package:drift); it doesn't appear.

Or in fact something from the Flutter framework, like "Widget".

So yeah, that's a line we want to include. 🙂

@chrisbobbe chrisbobbe force-pushed the pr-exclude-from-project-files-android-studio branch from 08a7116 to 4e9d813 Compare May 7, 2024 02:38
@chrisbobbe
Copy link
Collaborator Author

Cool, thanks! Revision pushed.

Android Studio wanted to add back a newline at the end of the file; do we want to keep that? I think we would usually include the newline.

@gnprice
Copy link
Member

gnprice commented May 8, 2024

Android Studio wanted to add back a newline at the end of the file; do we want to keep that? I think we would usually include the newline.

Great, yeah. This is a file it's inevitably going to keep modifying at its whim, so whatever it wants to automatically do we'll follow (because it'd be a big pain to try to do otherwise); glad the answer happens to be to include the final newline.

chrisbobbe added 2 commits May 7, 2024 18:21
In Greg's testing, the modules.xml file seemed needed in order for
Android Studio to know where to find the .iml file.

This has some useful `excludeFolder` items that should help Android
Studio see that certain files are not part of our project, and
should be excluded in searches that are supposed to be limited to
"project files".
@gnprice
Copy link
Member

gnprice commented May 8, 2024

Thanks for all the revisions on this! Looks good; merging, with a small commit-message tweak mainly to mention the modules.xml in the summary line as well as the zulip.iml.

@gnprice gnprice force-pushed the pr-exclude-from-project-files-android-studio branch from 4e9d813 to e511902 Compare May 8, 2024 01:27
@gnprice gnprice merged commit e511902 into zulip:main May 8, 2024
1 check passed
@chrisbobbe chrisbobbe deleted the pr-exclude-from-project-files-android-studio branch May 8, 2024 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-tools Our own development tooling, scripts, and infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants