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

Adding a helper script for Bzlmod migration. #74

Merged
merged 4 commits into from
Mar 15, 2022

Conversation

meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Mar 9, 2022

The script does the following things:

  1. Run the build without Bzlmod enabled to generate resolved external
    dependencies with --experimental_repository_resolved_file
  2. Run the build with Bzlmod enabled and identify recongnized error message
  3. Use the resolved external deps info to give migration suggestions.
  4. Repeat 2 and 3 until all external deps are available via Bzlmod (or WORKSPACE.bzlmod).

To start the migration, clone the Bazel central registry repo and run the following command from your project root:

<path to your local BCR repo>/tools/migrate_to_bzlmod.py <build flags> <build targets>

The script does the following things:
  - 1. Run the build without Bzlmod enabled to generate resolved external
    dependencies with --experimental_repository_resolved_file
  - 2. Run the build with Bzlmod enabled and identify recongnized error message
  - 3. Use the resolved external deps info to give migration suggestions.
  - 4. Repeat 2 and 3 until all external deps are available via Bzlmod (or WORKSPACE.bzlmod).

To start the migration, clone the Bazel central registry repo and run the following command from your project root:
```
<path to a local BCR repo>/tools/migrate_to_bzlmod.py <build flags> <build targets>
```
f"Please remove the usages of refering your own repo via `@{repo}//`, targets should be referenced directly with `//`. ")
eprint("If it's used in a macro, you can use `Label(\"//foo/bar\")` to make sure it alwasy points to your repo no matter where the macro is used.")
eprint(f"You can temporarily work around this by changing your module name to {WORKSPACE_NAME} and adding `workspace(name = '{WORKSPACE_NAME}')` in the WORKSPACE.bzlmod file.")
return yes_or_no("Do you wish to retry the build after fixes?", True)
Copy link
Member

Choose a reason for hiding this comment

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

maybe remove the "after fixes" part since it can be slightly confusing

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

return None, None


def address_unavailable_repo_error(repo, from_repo, resolved_deps):
Copy link
Member

Choose a reason for hiding this comment

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

the "from_repo" param no longer seems to be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, I'm keeping it in the return value of detect_unavailable_repo_error just in case we need it later.



# Create MODULE.bazel file if it doesn't exist already.
scratch_file("MODULE.bazel", [], mode="a")
Copy link
Member

Choose a reason for hiding this comment

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

maybe create these with the current workspace name? (or do you think it's better to let the user manually add a module name later on?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think let the user be aware of this is better.

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.

None yet

2 participants