#[Go] Codegen for module with a local dependency causes an infinite loop

1 messages · Page 1 of 1 (latest)

weak epoch
#

Hey guys, I'm getting an infinite loop when trying to run codegen for a module that contains a relative dependency.

src here is the local module directory.

// Generate Dagger code and merge with source.
codegen := src.AsModule().GeneratedContextDirectory()
src = src.WithDirectory(".", codegen)

dagger.json

{
  "name": "go-lint-tests",
  "engineVersion": "v0.18.16",
  "sdk": {
    "source": "go"
  },
  "dependencies": [
    {
      "name": "go-lint",
      "source": ".."
    }
  ]
}

Output:

▼ .check(
│ ┆ git: Host.directory(path: "/Users/luke.brakel/workspace/library-ci-workflows/.git", exclude: [], noCache: true): Directory!
│ ┆ src: Host.directory(path: "/Users/luke.brakel/workspace/library-ci-workflows/modules/go-lint/tests", exclude: ["*", "!**/*.go", "!**/go.mod", "!**/go.sum", "!**/dagger.json", "!.golangci.yaml"]): Directory!
│ ): Void 7.9s
! context canceled
╰─▼ check 11.5s
  ├─▶ Directory.exists(path: "go.mod"): Boolean! 0.0s
  │
  ├─▶ Directory.exists(path: "dagger.json"): Boolean! 0.0s
  │
  ├─● Directory.file(path: ".golangci.yaml"): File! 0.0s
  │
  ╰─▼ Directory.asModule: Module! 7.8s
    ! context canceled
    ╰─▼ Directory.asModuleSource(sourceRootPath: "."): ModuleSource! 7.8s
      ! context canceled
      ╰─▼ Directory.asModuleSource(sourceRootPath: ".."): ModuleSource! 7.8s
        ! context canceled
        ╰─▼ Directory.asModuleSource(sourceRootPath: "../.."): ModuleSource! 7.8s
          ! context canceled
          ╰─▼ Directory.asModuleSource(sourceRootPath: "../../.."): ModuleSource! 7.8s
...

That will continue on, quickly becoming unresponsive.

Any thoughts?

drifting nest
weak epoch
#

Here you go:

{
  "name": "go-lint",
  "engineVersion": "v0.18.16",
  "sdk": {
    "source": "go"
  }
}
weak epoch
#

Ahh, I'm pretty sure it's because src is the root directory, when it tries to load .. it references itself.

drifting nest
weak epoch
#

I'm working on a Go lint module and need to make sure that the generated Dagger code is available, as we don't commit it. We already do this elsewhere by downloading the cli on to an alpine image, but I wanted to see if it was supported via the SDK. I came across GeneratedContextDirectory() which works well but fails on our test modules ,which are subdirectories of the modules they test. They also have a local dependency on the module they test.

    {
      "name": "tests",
      "source": ".."
    }

So in this case, the directories are:

/my-module
  main.go
  dagger.json
  ...
  /tests
    main.go
    dagger.json
    ...

If I run the following, it will recurse on .. because it's the root directory - seems obvious now.

dagger call codegen --src tests
func (m *Test) Codegen(ctx context.Context, src *dagger.Directory) *dagger.Directory {
    codegen := src.AsModule().GeneratedContextDirectory()
    src = src.WithDirectory(".", codegen)

    return src
}
weak epoch
#

I can generate the sub module by including the dependency in the src /my-module/tests and setting SourceRootPath src.AsModule(dagger.DirectoryAsModuleOpts{SourceRootPath: module}

drifting nest