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

Add module_ctx.template Starlark function #24829

Open
phst opened this issue Jan 5, 2025 · 4 comments
Open

Add module_ctx.template Starlark function #24829

phst opened this issue Jan 5, 2025 · 4 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@phst
Copy link
Contributor

phst commented Jan 5, 2025

Description of the feature request:

Create function module_ctx.template with the same interface and semantics as repository_ctx.template.

Which category does this issue belong to?

Rules API

What underlying problem are you trying to solve with this feature?

There's repository_ctx.template to expand a template as part of a repository rule, but no equivalent in module_ctx. This means that module rule implementations that want to expand a template either have to instantiate a private repository rule, or implement template expansion by hand.

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 8.0.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

Didn't find anything on these sites using the search query "module_ctx template"

Any other information, logs, or outputs that you want to share?

Maybe it would be enough to move StarlarkRepositoryContext.createFileFromTemplate into StarlarkBaseExternalContext.

A similar argument could be made for other functions in StarlarkRepositoryContext: delete, rename, patch, symlink.

@github-actions github-actions bot added the team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts label Jan 5, 2025
@phst
Copy link
Contributor Author

phst commented Jan 5, 2025

Similar issues: #16144, #22825

phst added a commit to phst/rules_elisp that referenced this issue Jan 5, 2025
phst added a commit to phst/rules_elisp that referenced this issue Jan 5, 2025
This reverts commit 61c3f7c.

This comment is wrong, see https://groups.google.com/g/bazel-discuss/c/vGWAMaziGCU/m/bt5Uu7TDAQAJ:

    Module extensions aren't meant to replace repository rules - in fact, module extensions can create repositories only
    by instantiating repository rules. The files created by a module extension's implementation function are only kept in a
    temporary location. It is thus both perfectly fine and necessary to continue to use repository rules and orchestrate
    them via module extensions.
@fmeum
Copy link
Collaborator

fmeum commented Jan 6, 2025

Moving template to StarlarkBaseExternalContext should be all it takes.

An argument in favor of not moving the other methods is that files created by module extensions are temporary in nature and the working directory is deleted after execution. delete, rename, patch and symlink tend to be less useful in that situation and their availability may give a false impression about what module extensions can do. At the same time, they could be occasionally useful.

@meteorcloudy @Wyverald What do you think, should we just go for parity with repository_ctx? template does seem useful for package manager interactions in a module extension.

@comius comius added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. and removed team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts labels Jan 7, 2025
@comius
Copy link
Contributor

comius commented Jan 7, 2025

@satyanandak: Repository and module rules (mention of either repository_ctx, module_ctx) are owned by OSS team in their effort to solve problems with external dependencies.

cc @meteorcloudy @Wyverald

@Wyverald Wyverald added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website labels Jan 8, 2025
@Wyverald
Copy link
Member

Wyverald commented Jan 8, 2025

basically exactly what @fmeum said above. I'm happy to review a PR that adds mctx.template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

7 participants