-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
275 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package module | ||
|
||
import "context" | ||
|
||
type errBuildError struct { | ||
name contextKey | ||
err error | ||
} | ||
|
||
type buildContext struct { | ||
context.Context | ||
mod ModuleKey | ||
dependOn map[contextKey]struct{} | ||
repo *Repo | ||
} | ||
|
||
func newBuildContext(ctx context.Context, repo *Repo) *buildContext { | ||
return &buildContext{ | ||
Context: ctx, | ||
repo: repo, | ||
} | ||
} | ||
|
||
func (ctx *buildContext) Child(mod ModuleKey) *buildContext { | ||
return &buildContext{ | ||
Context: ctx.Context, | ||
mod: mod, | ||
dependOn: make(map[contextKey]struct{}), | ||
repo: ctx.repo, | ||
} | ||
} | ||
|
||
func (ctx *buildContext) Value(name any) any { | ||
key, ok := name.(ModuleKey) | ||
if !ok { | ||
return ctx.Context.Value(name) | ||
} | ||
|
||
ctx.dependOn[key.contextKey()] = struct{}{} | ||
|
||
if ret := ctx.repo.Value(key); ret != nil { | ||
return ret | ||
} | ||
|
||
if err := key.build(ctx); err != nil { | ||
panic(errBuildError{name: key.contextKey(), err: err}) | ||
} | ||
|
||
return ctx.repo.Value(key) | ||
} | ||
|
||
func (ctx *buildContext) addInstance(instance Instance) { | ||
deps := make([]contextKey, 0, len(ctx.dependOn)) | ||
for key := range ctx.dependOn { | ||
deps = append(deps, key) | ||
} | ||
|
||
ctx.repo.addInstance(ctx.mod, deps, instance) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.