Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g commented Nov 18, 2022

In preparation for adding integration tests to test_plugin and alternate_language_test_plugin, which will involve multiple different tests running code based on the same generated output, this restructures the Pigeon test scripts to do generation of the *_test_plugin output files in a single shared step at the start of the test run, rather than having it be part of each test. This has several advantages:

  • Reduces overall time for a full test run; there is non-trivial overhead for each invocation of pigeon, so doing it # files times instead of # files x # languages times is faster.
  • Avoids duplication of generation that would happen otherwise (once for unit tests, then once for integration tests, for each language).
  • Makes it easy to add a new script (which this PR does) to run just the generation step, which:
    • is useful for manually checking generation output (I've wanted it quite a few times) without running all tests.
    • will work better if we check in the generated output (since it separates generation from running tests), which per a number of previous discussions is something we are very likely to do once we've done some more restructuring, as it will dramatically improve the PR review experience for generator changes.
  • Migrates more code from Bash to Dart (since it's a command we are exposing for command-line use anyway, we can migrate it without having to migrate the rest of the Bash code right now).

It does mean that running just individual tests that don't use the test plugins are currently slower; if that ends up being a common enough case before we switch to checking in generated code, we can potentially add logic to make this conditional. (Since that will be easier once everything is Dart, and my hope is that we move to checking in relatively soon, I didn't invest effort in that here.)

Opportunistic refactoring/cleanup done as part of this PR:

  • Extracted runPigeon to a separate file (unchanged).
  • Extracted runProcess to a separate file, and adjusted it slightly so that code that was currently using Process.start directly can share runProcess instead.
  • Added convenience wrappers for running Flutter, Xcode, and Gradle commands to make the main script slightly higher level. (These are essentially light-weight versions of wrappers that exist in flutter_plugin_tools, where they have been useful abstractions.)
  • ObjC output now uses camel-case files, as is the standard convention.
  • ObjC prefixes are no longer used, since collisions were eliminated from the input pigeons during the Swift generator bringup.
  • Generated files in the shared code have standardized on .gen.* instead of some using that and some using .g.*.

Prep for flutter/flutter#111505
Part of flutter/flutter#115169
Part of flutter/flutter#85068

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@stuartmorgan-g stuartmorgan-g added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Nov 18, 2022
@stuartmorgan-g
Copy link
Collaborator Author

Adding overrides as this is a dev-only change, the scripts just don't know about pigeon's test structure. (Eventually we should fix that; it wouldn't be that big a deal to special-case it in the tooling.)

Copy link
Collaborator Author

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

This seemed like a reasonably sized cut-point for this prep work, but let me know if you want me to split anything out.

objects = {

/* Begin PBXBuildFile section */
0D02163D27BC7B48009BD76F /* nullable_returns.gen.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D02163C27BC7B48009BD76F /* nullable_returns.gen.m */; };
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These project changes are all mechanical renames due to switching over to camel-casing for ObjC generation.

#import <XCTest/XCTest.h>
#import "EchoMessenger.h"
#import "all_datatypes.gen.h"
#import "AllDatatypes.gen.h"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The ObjC test changes are all:

  • import renames for CamelCase files, or
  • removal of prefixes.

}

// A map of pigeons/ files to the languages that they can't yet be generated
// for due to limitations of that generator.
Copy link
Collaborator Author

@stuartmorgan-g stuartmorgan-g Nov 18, 2022

Choose a reason for hiding this comment

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

This is a behavioral change; we used to generate an opted-in list of files for each language, whereas now we generate everything that doesn't actively fail. That means we're generating files that we aren't using yet, but

  • that should be harmless
  • it can be useful for manual generator change checking
  • it'll be one less thing to change when backfilling missing platform tests
  • [pigeon] Reorganize test pigeons flutter#115168 will render the difference moot anyway

@stuartmorgan-g
Copy link
Collaborator Author

Hm, I'm not sure what's going on with Windows; it passes for me locally now. I suspect we're missing some log output, as we've seen with other Windows LUCI hangs.

@tarrinneal
Copy link
Contributor

Still hanging :/

@stuartmorgan-g
Copy link
Collaborator Author

With verbose build logging it looks suspiciously like it's hanging in the package resolution failure stage, which generally means a resolution conflict. But I didn't change anything about the Dart dependencies, so now I'm even more confused.

@stuartmorgan-g
Copy link
Collaborator Author

It turns out I forgot to update the header includes in the unit tests, so it may be that this was actually just the tests failing to compile (and passing for me locally because I apparently forgot to clean the output directory, so had the old files?). Why even just failing to compile would hang the CI, I have no idea; I'll file an issue with a repro case if that's really all it was.

- (void)testEcho {
ACDataWithEnum *data = [[ACDataWithEnum alloc] init];
data.state = ACEnumStateError;
DataWithEnum *data = [[DataWithEnum alloc] init];
Copy link
Member

Choose a reason for hiding this comment

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

How come we lost all the prefixes to class names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the PR description:

ObjC prefixes are no longer used, since collisions were eliminated from the input pigeons during the Swift generator bringup.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

This looks good with a few recommendations:

  1. Fill in some of the docstrings, nothing exhaustive needed, just a simple sentence that explains what public procedures are doing
  2. I'd keep the class prefix on objc generation. Since there is no namespaces in objc its easy to get collisions and we don't want people coming up with goofy names just to avoid collisions.

final String iosObjCBase =
p.join(baseDir, 'platform_tests', 'ios_unit_tests');

for (final String input in inputs) {
Copy link
Member

Choose a reason for hiding this comment

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

It worth trying parallelizing this: https://pub.dev/packages/pmap The input size is small and the execution time is large.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to move your existing TODO about this; I've added it. (But also, flutter/flutter#115168 will largely make this much less of an issue.)

return process;
}

Future<int> runProcess(String command, List<String> arguments,
Copy link
Member

Choose a reason for hiding this comment

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

docstring please


import 'process_utils.dart';

Future<int> runFlutterCommand(
Copy link
Member

Choose a reason for hiding this comment

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

docstrings would help here too

return specialCases[inputName] ?? _snakeToPascalCase(inputName);
}

Future<int> generatePigeons({required String baseDir}) async {
Copy link
Member

Choose a reason for hiding this comment

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

docstrings

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I completely forgot to go back and add them! Done everywhere.

Copy link
Collaborator Author

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

I'd keep the class prefix on objc generation. Since there is no namespaces in objc its easy to get collisions and we don't want people coming up with goofy names just to avoid collisions.

We already need different names to make things work in Swift (and maybe Kotlin?). And it'll be moot when we do flutter/flutter#115168 anyway.

final String iosObjCBase =
p.join(baseDir, 'platform_tests', 'ios_unit_tests');

for (final String input in inputs) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to move your existing TODO about this; I've added it. (But also, flutter/flutter#115168 will largely make this much less of an issue.)

return specialCases[inputName] ?? _snakeToPascalCase(inputName);
}

Future<int> generatePigeons({required String baseDir}) async {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I completely forgot to go back and add them! Done everywhere.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

👍

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 23, 2022
@auto-submit auto-submit bot merged commit 9134c12 into flutter:main Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: pigeon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants