mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
compile: fix file renaming check in optimization (#4154)
This was resulting in a max of 2 optimized entrypoints in a single file. Signed-off-by: davidmarne-wf <david.marne@workiva.com>
This commit is contained in:
+4
-3
@@ -862,12 +862,13 @@ func (o *optimizer) getSupportModuleFilename(used map[string]int, module *ast.Mo
|
||||
|
||||
if err == nil && safePathPattern.MatchString(fileName) {
|
||||
fileName = o.outputprefix + "/" + fileName
|
||||
uniqueFileName := fileName
|
||||
if c, ok := used[fileName]; ok {
|
||||
fileName += fmt.Sprintf(".%d", c)
|
||||
uniqueFileName += fmt.Sprintf(".%d", c)
|
||||
}
|
||||
used[fileName]++
|
||||
fileName += ".rego"
|
||||
return fileName
|
||||
uniqueFileName += ".rego"
|
||||
return uniqueFileName
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v/%v/%v/%v.rego", o.outputprefix, o.nsprefix, entrypointIndex, supportIndex)
|
||||
|
||||
+10
-1
@@ -891,7 +891,7 @@ func TestOptimizerOutput(t *testing.T) {
|
||||
},
|
||||
{
|
||||
note: "multiple entrypoints",
|
||||
entrypoints: []string{"data.test.p", "data.test.r"},
|
||||
entrypoints: []string{"data.test.p", "data.test.r", "data.test.s"},
|
||||
modules: map[string]string{
|
||||
"test.rego": `
|
||||
package test
|
||||
@@ -904,6 +904,10 @@ func TestOptimizerOutput(t *testing.T) {
|
||||
q[input.x]
|
||||
}
|
||||
|
||||
s {
|
||||
q[input.x]
|
||||
}
|
||||
|
||||
q[1]
|
||||
`,
|
||||
},
|
||||
@@ -918,6 +922,11 @@ func TestOptimizerOutput(t *testing.T) {
|
||||
|
||||
r = __result__ { 1 = input.x; __result__ = true }
|
||||
`,
|
||||
"optimized/test.2.rego": `
|
||||
package test
|
||||
|
||||
s = __result__ { 1 = input.x; __result__ = true }
|
||||
`,
|
||||
"test.rego": `
|
||||
package test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user