diff --git a/compile/compile.go b/compile/compile.go index 70177f2499..9d7fdca94d 100644 --- a/compile/compile.go +++ b/compile/compile.go @@ -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) diff --git a/compile/compile_test.go b/compile/compile_test.go index 0cd1ee0fd4..4b6524dfbe 100644 --- a/compile/compile_test.go +++ b/compile/compile_test.go @@ -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