Skip to content

Add --ios_device flag for running iOS application on a physical device #16

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 28, 2025

Related to this PR in the rules_apple.

In Xcode 15, Apple introduced a new command-line tool that allows management of physical devices. This makes it possible to install and launch *_application targets on a physical device without third-party solutions.
It would be nice to have a Bazel flag to pass a device identifier for this.

Summary by CodeRabbit

  • New Features

    • Added support for specifying a physical iOS device identifier when running iOS applications.
    • Exposed the selected iOS device identifier to Starlark rules for enhanced configurability.
  • Tests

    • Introduced tests to verify Starlark access to the iOS device configuration.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

FYI I think it's unlikely that folks would accept a new iOS specific flag into bazel itself, there's a goal of removing this type of specifics from bazel. If a flag is required it would probably be preferred to add a starlark flag in rules_apple itself

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

FYI I think it's unlikely that folks would accept a new iOS specific flag into bazel itself, there's a goal of removing this type of specifics from bazel. If a flag is required it would probably be preferred to add a starlark flag in rules_apple itself

Thanks for letting me know. I had the same assumption, but I'm curious to hear what folks will say.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

note that it will not get any attention from folks who can merge unless you mark ready for review

Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

A new command-line option for specifying an iOS device identifier was introduced to the Objective-C build system. This option is now accessible through the configuration API and is exposed to Starlark, allowing build rules to retrieve the selected device identifier. Corresponding changes were made to the configuration class and interface, and a new test was added to ensure that Starlark rules can access this field along with other related configuration values.

Changes

File(s) Change Summary
src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java Added ios_device command-line option to allow specifying an iOS device identifier for running applications.
src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java Added private field and public getter for iosDevice, initialized from command-line options.
src/main/java/com/google/devtools/build/lib/starlarkbuildapi/apple/ObjcConfigurationApi.java Added nullable getIosDevice() method, exposed to Starlark as "ios_device".
src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java Added test verifying Starlark access to ios_device and related configuration fields for device builds.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommandLine
    participant ObjcCommandLineOptions
    participant ObjcConfiguration
    participant StarlarkRule

    User->>CommandLine: Runs build with --ios_device=UUID
    CommandLine->>ObjcCommandLineOptions: Parses ios_device option
    ObjcCommandLineOptions->>ObjcConfiguration: Passes iosDevice value
    StarlarkRule->>ObjcConfiguration: Requests ios_device via getIosDevice()
    ObjcConfiguration-->>StarlarkRule: Returns ios_device value
Loading

Poem

A hop, a skip, a brand-new flag,
Now iOS devices join the tag!
From command-line to Starlark's view,
Device IDs are passing through.
Tests confirm the path is right—
🐇 Cheers for options taking flight!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0c98a2 and e318818.

📒 Files selected for processing (4)
  • src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java (1 hunks)
  • src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java (3 hunks)
  • src/main/java/com/google/devtools/build/lib/starlarkbuildapi/apple/ObjcConfigurationApi.java (1 hunks)
  • src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java (1 hunks)
🔇 Additional comments (6)
src/main/java/com/google/devtools/build/lib/starlarkbuildapi/apple/ObjcConfigurationApi.java (1)

51-57: New API addition looks good!

The new method getIosDevice() is properly annotated with @StarlarkMethod and @Nullable, making it consistent with other similar methods like getIosSimulatorDevice(). The documentation clearly explains that this returns the device identifier for running an iOS application.

src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java (1)

51-61: Command-line option implementation looks good!

The new --ios_device option is well-structured with appropriate documentation, default value, and categorization. The help text is informative and includes helpful guidance about listing available devices with xcrun devicectl list devices. The option is correctly categorized under testing and tagged with OptionEffectTag.TEST_RUNNER, consistent with the pattern used for the other iOS simulator options.

src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java (3)

56-56: Field declaration looks good!

The new private field iosDevice follows the same pattern as the existing fields for iOS simulator device.


74-74: Constructor initialization looks good!

The field is properly initialized in the constructor from objcOptions.iosDevice, following the same pattern as the other fields.


103-109: Method implementation looks good!

The new getIosDevice() method is implemented correctly with appropriate JavaDoc comment and @Override annotation. The implementation is consistent with other similar getter methods in the class.

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java (1)

811-864: Test implementation looks good!

The new test method testStarlarkCanAccessObjcConfigurationForDevice() is well-structured and follows the same pattern as the existing tests for iOS simulator configuration. It properly configures the test environment, creates a Starlark rule that accesses the objc configuration, and verifies that it can access the ios_device field alongside other fields.

The test correctly uses --ios_device='11111111-1111-1111-1111-11111111111' in the configuration and validates that this value is properly exposed to Starlark.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @arvi18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces a new command-line flag, --ios_device, to specify a physical iOS device for running application targets. This leverages Apple's new command-line tool in Xcode 15 for managing physical devices, allowing Bazel to install and launch applications on a specified device without relying on third-party solutions. The changes include adding the new flag to ObjcCommandLineOptions, updating ObjcConfiguration to store the flag's value, exposing the flag in Starlark, and adding a test to verify Starlark's access to the new flag.

Highlights

  • New Flag: --ios_device: Introduces a new command-line flag --ios_device to specify the identifier of a physical iOS device for running application targets. The flag accepts the device's identifier, ECID, serial number, UDID, user-provided name, or DNS name.
  • Configuration Integration: Integrates the new flag into the ObjcConfiguration to store the specified device identifier, making it accessible during the build process.
  • Starlark Exposure: Exposes the ios_device flag to Starlark, allowing rules to access the specified device identifier within Starlark build files.
  • Testing: Adds a new test case, testStarlarkCanAccessObjcConfigurationForDevice, to verify that Starlark can correctly access the value of the ios_device flag.

Changelog

  • src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java
    • Added the ios_device option with documentation and help text. (lines 51-61)
  • src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java
    • Added iosDevice field to store the value of the ios_device flag. (line 56)
    • Initialized iosDevice in the constructor using the value from ObjcCommandLineOptions. (line 74)
    • Added getter method getIosDevice() to retrieve the value of iosDevice. (lines 103-109)
  • src/main/java/com/google/devtools/build/lib/starlarkbuildapi/apple/ObjcConfigurationApi.java
    • Added getIosDevice() method to the ObjcConfigurationApi interface, exposing the ios_device value to Starlark. (lines 51-57)
  • src/test/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkTest.java
    • Added a new test case, testStarlarkCanAccessObjcConfigurationForDevice, to verify that Starlark can access the ios_device flag. (lines 812-864)
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A new flag appears,
For devices, banish fears,
Xcode's tool now guides.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new flag --ios_device to allow running iOS applications on physical devices using the xcrun devicectl command-line tool. The changes look good overall, and the addition of a test case is appreciated. However, there are a few areas that could be improved for clarity and maintainability.

Summary of Findings

  • Documentation Clarity: The help text for the ios_device flag could be more explicit about the supported device identification methods and potential issues.
  • Error Handling: Consider adding error handling or validation for the ios_device flag to ensure that the provided device identifier is valid.

Merge Readiness

The pull request is almost ready for merging. Addressing the documentation clarity and error handling suggestions would improve the robustness and user-friendliness of the new feature. I am unable to approve this pull request, and users should have others review and approve this code before merging. I recommend that the pull request not be merged until the high severity issues are addressed.

Comment on lines +56 to +60
help =
"The identifier, ECID, serial number, UDID, user-provided name, or DNS name of "
+ "the device for running an iOS application. "
+ "You can get a list of devices by running 'xcrun devicectl list "
+ "devices'.")

Choose a reason for hiding this comment

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

medium

The help text is good, but it could be improved by mentioning that the identifier can be obtained from Xcode as well, and that the tool requires Xcode 15 or later. Also, consider adding a note about potential issues with device access or permissions.

For example, the help text could be reworded as follows:

"The identifier, ECID, serial number, UDID, user-provided name, or DNS name of the device for running an iOS application. You can get a list of devices by running 'xcrun devicectl list devices' (requires Xcode 15 or later) or from Xcode's Devices and Simulators window. Ensure that the device is properly connected and authorized for development."

        "The identifier, ECID, serial number, UDID, user-provided name, or DNS name of "
            + "the device for running an iOS application. "
            + "You can get a list of devices by running 'xcrun devicectl list "
            + "devices' (requires Xcode 15 or later) or from Xcode's Devices and Simulators "
            + "window. Ensure that the device is properly connected and authorized for development."

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.

2 participants