#so I took a hint from this and updated

1 messages · Page 1 of 1 (latest)

ionic glade
#

There was a behavior change in GeneratedContextDirectory in that it used to return the full context dir (original loaded one + generated files) but now just returns the diff (so just the generated files)

I can't tell if that's exactly what would be impacting you. Does scanSource include the original base context dir (i.e. what would be the source var in your code fwict)

Using the example you linked to from the dagger-dev module, src has the original base context and we are just updating it with the generated file layers

unkempt fable
#

This is my updated function (extracted the code to a new function)

func (ci *CI) CodeGenTargets() *dagger.Directory {
    scanSource := dag.Directory()
    // Since we don't commit dagger codegen, we need a way to
    // generate the code for each dagger module. Dagger provides
    // an API to do this with the `source.AsModule` function.
    for _, module := range ci.Modules {
        codegen := ci.Src.AsModule(dagger.DirectoryAsModuleOpts{
            SourceRootPath: module,
        }).GeneratedContextDirectory().
            Directory(module)
        scanSource = scanSource.WithDirectory(module, codegen)
    }

    return scanSource
}

In this ci.Src is the root directory. The parent which hosts all my modules.

ionic glade
# unkempt fable This is my updated function (extracted the code to a new function) ```go func (...

Oh okay, try this:

func (ci *CI) CodeGenTargets() *dagger.Directory {
    scanSource := ci.Src
    // Since we don't commit dagger codegen, we need a way to
    // generate the code for each dagger module. Dagger provides
    // an API to do this with the `source.AsModule` function.
    for _, module := range ci.Modules {
        codegen := ci.Src.AsModule(dagger.DirectoryAsModuleOpts{
            SourceRootPath: module,
        }).GeneratedContextDirectory().
            Directory(module)
        scanSource = scanSource.WithDirectory(module, codegen)
    }

    return scanSource
}
#

(diff is in scanSource at the beginning of the function)

unkempt fable
#

That parent directory does not have a dagger.json fwiw

#

ooh looks like that worked!

#

ok so interesting, I see the change. It's just adding the missing codegen to my existing module dirs.

ionic glade
#

Awesome, yeah just to give some context, that behavior change was made because 99% of the time anyone is calling generatedContextDirectory it's from dagger init/dagger develop, which just call it and export it back to the original context dir on the host. In those cases, it's a bit more optimal to just export the diff since there's less work for filesync (less files to export)

And then for the other 1% of cases where users are actually doing stuff with these APIs, it's always possible to just apply generatedContextDirectory on top of the original context. Some seemed like the tradeoff of making this behave a little different was worth it