Skip to content

Commit 3da3ca9

Browse files
authored
fix(bazel-module): Revert "feat(bazel-module): Add support for rules_img" (#37501)
1 parent 643d489 commit 3da3ca9

File tree

9 files changed

+6
-393
lines changed

9 files changed

+6
-393
lines changed

lib/modules/manager/bazel-module/extract.spec.ts

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -618,121 +618,5 @@ describe('modules/manager/bazel-module/extract', () => {
618618
],
619619
});
620620
});
621-
622-
it('returns rules_img pull dependencies', async () => {
623-
const input = codeBlock`
624-
pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")
625-
626-
pull(
627-
name = "ubuntu",
628-
digest = "sha256:1e622c5f073b4f6bfad6632f2616c7f59ef256e96fe78bf6a595d1dc4376ac02",
629-
registry = "index.docker.io",
630-
repository = "library/ubuntu",
631-
tag = "24.04",
632-
)
633-
`;
634-
const res = await extractPackageFile(input, 'MODULE.bazel');
635-
636-
expect(res).toEqual({
637-
deps: [
638-
{
639-
datasource: 'docker',
640-
depType: 'rules_img_pull',
641-
depName: 'ubuntu',
642-
packageName: 'index.docker.io/library/ubuntu',
643-
currentValue: '24.04',
644-
currentDigest:
645-
'sha256:1e622c5f073b4f6bfad6632f2616c7f59ef256e96fe78bf6a595d1dc4376ac02',
646-
replaceString: expect.stringContaining('pull('),
647-
},
648-
],
649-
});
650-
});
651-
652-
it('returns rules_img pull dependencies without tag', async () => {
653-
const input = codeBlock`
654-
pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")
655-
656-
pull(
657-
name = "distroless_cc",
658-
digest = "sha256:d1b8e4c52be1111aa108e959ef2a822299bb70fd1819dd250871a2601ca1e4b6",
659-
registry = "gcr.io",
660-
repository = "distroless/cc-debian12",
661-
)
662-
`;
663-
const res = await extractPackageFile(input, 'MODULE.bazel');
664-
665-
expect(res).toEqual({
666-
deps: [
667-
{
668-
datasource: 'docker',
669-
depType: 'rules_img_pull',
670-
depName: 'distroless_cc',
671-
packageName: 'gcr.io/distroless/cc-debian12',
672-
currentDigest:
673-
'sha256:d1b8e4c52be1111aa108e959ef2a822299bb70fd1819dd250871a2601ca1e4b6',
674-
replaceString: expect.stringContaining('pull('),
675-
},
676-
],
677-
});
678-
});
679-
680-
it('ignores non-rules_img use_repo_rule calls', async () => {
681-
const input = codeBlock`
682-
other_rule = use_repo_rule("@some_other//path:rule.bzl", "other_rule")
683-
684-
pull(
685-
name = "ubuntu",
686-
digest = "sha256:1e622c5f073b4f6bfad6632f2616c7f59ef256e96fe78bf6a595d1dc4376ac02",
687-
registry = "index.docker.io",
688-
repository = "library/ubuntu",
689-
tag = "24.04",
690-
)
691-
`;
692-
const res = await extractPackageFile(input, 'MODULE.bazel');
693-
694-
expect(res).toBeNull();
695-
});
696-
697-
it('ignores non-rules_img use_repo_rule calls that use the name pull', async () => {
698-
const input = codeBlock`
699-
pull = use_repo_rule("@some_other//path:rule.bzl", "pull")
700-
701-
pull(
702-
name = "test",
703-
value = "ignored",
704-
)
705-
`;
706-
const res = await extractPackageFile(input, 'MODULE.bazel');
707-
708-
expect(res).toBeNull();
709-
});
710-
711-
it('handles multiple rules_img pulls', async () => {
712-
const input = codeBlock`
713-
pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")
714-
715-
pull(
716-
name = "ubuntu",
717-
digest = "sha256:1e622c5f073b4f6bfad6632f2616c7f59ef256e96fe78bf6a595d1dc4376ac02",
718-
registry = "index.docker.io",
719-
repository = "library/ubuntu",
720-
tag = "24.04",
721-
)
722-
723-
pull(
724-
name = "cuda",
725-
digest = "sha256:f353ffca86e0cd93ab2470fe274ecf766519c24c37ed58cc2f91d915f7ebe53c",
726-
registry = "index.docker.io",
727-
repository = "nvidia/cuda",
728-
tag = "12.8.1-cudnn-devel-ubuntu20.04",
729-
)
730-
`;
731-
const res = await extractPackageFile(input, 'MODULE.bazel');
732-
733-
expect(res?.deps).toHaveLength(2);
734-
expect(res?.deps[0].depName).toBe('ubuntu');
735-
expect(res?.deps[1].depName).toBe('cuda');
736-
});
737621
});
738622
});

lib/modules/manager/bazel-module/extract.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { parse } from './parser';
88
import type { ResultFragment } from './parser/fragments';
99
import { RuleToMavenPackageDep, fillRegistryUrls } from './parser/maven';
1010
import { RuleToDockerPackageDep } from './parser/oci';
11-
import { RulesImgPullToDockerPackageDep } from './parser/rules-img';
1211
import {
1312
GitRepositoryToPackageDep,
1413
RuleToBazelModulePackageDep,
@@ -25,7 +24,6 @@ export async function extractPackageFile(
2524
const gitRepositoryDeps = extractGitRepositoryDeps(records);
2625
const mavenDeps = extractMavenDeps(records);
2726
const dockerDeps = LooseArray(RuleToDockerPackageDep).parse(records);
28-
const rulesImgDeps = extractRulesImgDeps(records);
2927

3028
if (gitRepositoryDeps.length) {
3129
pfc.deps.push(...gitRepositoryDeps);
@@ -39,10 +37,6 @@ export async function extractPackageFile(
3937
pfc.deps.push(...dockerDeps);
4038
}
4139

42-
if (rulesImgDeps.length) {
43-
pfc.deps.push(...rulesImgDeps);
44-
}
45-
4640
return pfc.deps.length ? pfc : null;
4741
} catch (err) {
4842
logger.debug({ err, packageFile }, 'Failed to parse bazel module file.');
@@ -82,7 +76,3 @@ function extractMavenDeps(records: ResultFragment[]): PackageDependency[] {
8276
.transform(fillRegistryUrls)
8377
.parse(records);
8478
}
85-
86-
function extractRulesImgDeps(records: ResultFragment[]): PackageDependency[] {
87-
return LooseArray(RulesImgPullToDockerPackageDep).parse(records);
88-
}

lib/modules/manager/bazel-module/parser/context.ts

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
ArrayFragment,
44
ExtensionTagFragment,
55
PreparedExtensionTagFragment,
6-
RepoRuleFunctionCallFragment,
76
ResultFragment,
87
RuleFragment,
98
} from './fragments';
@@ -34,22 +33,10 @@ export class Ctx implements CtxCompatible {
3433
results: ResultFragment[];
3534
stack: AllFragments[];
3635

37-
// Track repo rule assignments and function mappings
38-
private repoRuleFunctions: Map<
39-
string,
40-
{ loadPath: string; originalFunctionName: string }
41-
>;
42-
private currentRepoRuleAssignment?: {
43-
variableName: string;
44-
loadPath?: string;
45-
originalFunctionName?: string;
46-
};
47-
4836
constructor(source: string) {
4937
this.source = source;
5038
this.results = [];
5139
this.stack = [];
52-
this.repoRuleFunctions = new Map();
5340
}
5441

5542
private get safeCurrent(): AllFragments | undefined {
@@ -80,16 +67,6 @@ export class Ctx implements CtxCompatible {
8067
throw new Error('Requested current extension tag, but does not exist.');
8168
}
8269

83-
private get currentRepoRuleFunctionCall(): RepoRuleFunctionCallFragment {
84-
const current = this.current;
85-
if (current.type === 'repoRuleFunctionCall') {
86-
return current;
87-
}
88-
throw new Error(
89-
'Requested current repo rule function call, but does not exist.',
90-
);
91-
}
92-
9370
private get currentArray(): ArrayFragment {
9471
const current = this.current;
9572
if (current.type === 'array') {
@@ -133,20 +110,14 @@ export class Ctx implements CtxCompatible {
133110
return true;
134111
}
135112
if (
136-
(parent.type === 'rule' ||
137-
parent.type === 'extensionTag' ||
138-
parent.type === 'repoRuleFunctionCall') &&
113+
(parent.type === 'rule' || parent.type === 'extensionTag') &&
139114
current.type === 'attribute' &&
140115
current.value !== undefined
141116
) {
142117
parent.children[current.name] = current.value;
143118
return true;
144119
}
145-
} else if (
146-
current.type === 'rule' ||
147-
current.type === 'extensionTag' ||
148-
current.type === 'repoRuleFunctionCall'
149-
) {
120+
} else if (current.type === 'rule' || current.type === 'extensionTag') {
150121
this.results.push(current);
151122
return true;
152123
}
@@ -232,79 +203,4 @@ export class Ctx implements CtxCompatible {
232203
array.isComplete = true;
233204
return this.processStack();
234205
}
235-
236-
// Repo rule assignment methods
237-
startRepoRuleAssignment(variableName: string): Ctx {
238-
this.currentRepoRuleAssignment = { variableName };
239-
return this;
240-
}
241-
242-
addRepoRuleLoadPath(loadPath: string): Ctx {
243-
if (this.currentRepoRuleAssignment) {
244-
this.currentRepoRuleAssignment.loadPath = loadPath;
245-
}
246-
return this;
247-
}
248-
249-
addRepoRuleFunctionName(originalFunctionName: string): Ctx {
250-
if (this.currentRepoRuleAssignment) {
251-
this.currentRepoRuleAssignment.originalFunctionName =
252-
originalFunctionName;
253-
}
254-
return this;
255-
}
256-
257-
endRepoRuleAssignment(): Ctx {
258-
if (
259-
this.currentRepoRuleAssignment?.loadPath &&
260-
this.currentRepoRuleAssignment?.originalFunctionName
261-
) {
262-
// Only track rules_img repo rules - support both load paths used in tests
263-
const rulesImgLoadPaths = [
264-
'@rules_img//img:pull.bzl',
265-
'@rules_img//img/private/repository_rules:pull.bzl',
266-
];
267-
268-
if (rulesImgLoadPaths.includes(this.currentRepoRuleAssignment.loadPath)) {
269-
this.repoRuleFunctions.set(
270-
this.currentRepoRuleAssignment.variableName,
271-
{
272-
loadPath: this.currentRepoRuleAssignment.loadPath,
273-
originalFunctionName:
274-
this.currentRepoRuleAssignment.originalFunctionName,
275-
},
276-
);
277-
}
278-
}
279-
this.currentRepoRuleAssignment = undefined;
280-
return this;
281-
}
282-
283-
// Dynamic function call methods
284-
isRulesImgFunction(functionName: string): boolean {
285-
return this.repoRuleFunctions.has(functionName);
286-
}
287-
288-
startDynamicFunctionCall(functionName: string, offset: number): Ctx {
289-
const repoRuleInfo = this.repoRuleFunctions.get(functionName);
290-
if (!repoRuleInfo) {
291-
throw new Error(`Function ${functionName} not found in repo rules`);
292-
}
293-
294-
const functionCall = fragments.repoRuleFunctionCall(
295-
functionName,
296-
repoRuleInfo.loadPath,
297-
repoRuleInfo.originalFunctionName,
298-
offset,
299-
);
300-
this.stack.push(functionCall);
301-
return this;
302-
}
303-
304-
endDynamicFunctionCall(offset: number): Ctx {
305-
const functionCall = this.currentRepoRuleFunctionCall;
306-
functionCall.isComplete = true;
307-
functionCall.rawString = this.source.slice(functionCall.offset, offset);
308-
return this.processStack();
309-
}
310206
}

lib/modules/manager/bazel-module/parser/fragments.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,6 @@ export const ExtensionTagFragmentSchema = z.object({
5757
offset: z.number(), // start offset in the source string
5858
rawString: z.string().optional(), // raw source string
5959
});
60-
export const RepoRuleFunctionCallSchema = z.object({
61-
type: z.literal('repoRuleFunctionCall'),
62-
// The variable name used for the function call (e.g. "pull")
63-
functionName: z.string(),
64-
// The load path that was imported (e.g. "@rules_img//img:pull.bzl")
65-
loadPath: z.string(),
66-
// The original function name from use_repo_rule (e.g. "pull")
67-
originalFunctionName: z.string(),
68-
children: LooseRecord(ValueFragmentsSchema),
69-
isComplete: z.boolean(),
70-
offset: z.number(), // start offset in the source string
71-
rawString: z.string().optional(), // raw source string
72-
});
7360
export const AttributeFragmentSchema = z.object({
7461
type: z.literal('attribute'),
7562
name: z.string(),
@@ -83,7 +70,6 @@ export const AllFragmentsSchema = z.discriminatedUnion('type', [
8370
RuleFragmentSchema,
8471
PreparedExtensionTagFragmentSchema,
8572
ExtensionTagFragmentSchema,
86-
RepoRuleFunctionCallSchema,
8773
StringFragmentSchema,
8874
]);
8975

@@ -98,15 +84,9 @@ export type PreparedExtensionTagFragment = z.infer<
9884
typeof PreparedExtensionTagFragmentSchema
9985
>;
10086
export type ExtensionTagFragment = z.infer<typeof ExtensionTagFragmentSchema>;
101-
export type RepoRuleFunctionCallFragment = z.infer<
102-
typeof RepoRuleFunctionCallSchema
103-
>;
10487
export type StringFragment = z.infer<typeof StringFragmentSchema>;
10588
export type ValueFragments = z.infer<typeof ValueFragmentsSchema>;
106-
export type ResultFragment =
107-
| RuleFragment
108-
| ExtensionTagFragment
109-
| RepoRuleFunctionCallFragment;
89+
export type ResultFragment = RuleFragment | ExtensionTagFragment;
11090

11191
export function string(value: string): StringFragment {
11292
return {
@@ -172,27 +152,6 @@ export function extensionTag(
172152
};
173153
}
174154

175-
export function repoRuleFunctionCall(
176-
functionName: string,
177-
loadPath: string,
178-
originalFunctionName: string,
179-
offset: number,
180-
children: ChildFragments = {},
181-
rawString?: string,
182-
isComplete = false,
183-
): RepoRuleFunctionCallFragment {
184-
return {
185-
type: 'repoRuleFunctionCall',
186-
functionName,
187-
loadPath,
188-
originalFunctionName,
189-
offset,
190-
rawString,
191-
isComplete,
192-
children,
193-
};
194-
}
195-
196155
export function attribute(
197156
name: string,
198157
value?: ValueFragments,

lib/modules/manager/bazel-module/parser/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ import { lang, query as q } from 'good-enough-parser';
22
import { Ctx } from './context';
33
import { extensionTags } from './extension-tags';
44
import type { ResultFragment } from './fragments';
5-
import { dynamicFunctionCall, repoRuleAssignment } from './repo-rules';
65
import { rules } from './rules';
76

8-
const rule = q.alt<Ctx>(
9-
rules,
10-
extensionTags,
11-
repoRuleAssignment,
12-
dynamicFunctionCall,
13-
);
7+
const rule = q.alt<Ctx>(rules, extensionTags);
148

159
const query = q.tree<Ctx>({
1610
type: 'root-tree',

0 commit comments

Comments
 (0)