-
Notifications
You must be signed in to change notification settings - Fork 9
/
codegen.go
54 lines (43 loc) · 1.48 KB
/
codegen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package deploy
import (
"context"
"namespacelabs.dev/foundation/internal/codegen/genpackage"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/internal/planning"
"namespacelabs.dev/foundation/std/execution"
"namespacelabs.dev/foundation/std/pkggraph"
"namespacelabs.dev/foundation/std/tasks"
)
type codegenTrigger struct {
srv planning.Server
compute.LocalScoped[any]
}
func (c *codegenTrigger) Action() *tasks.ActionEvent { return tasks.Action("codegen") }
func (c *codegenTrigger) Inputs() *compute.In {
return compute.Inputs().Indigestible("not cacheable", "true")
}
func (c *codegenTrigger) Compute(ctx context.Context, _ compute.Resolved) (any, error) {
return "codegen", codegenServer(ctx, c.srv)
}
func codegenServer(ctx context.Context, srv planning.Server) error {
// XXX we should be able to disable codegen for pure builds.
if srv.Module().IsExternal() {
return nil
}
codegen, err := genpackage.ForServerAndDeps(ctx, srv)
if err != nil {
return err
}
if len(codegen) == 0 {
return nil
}
r := execution.NewPlan(codegen...)
return execution.Execute(ctx, "workspace.codegen", r, nil,
execution.FromContext(srv.SealedContext()),
pkggraph.MutableModuleInjection.With(srv.Module()),
pkggraph.PackageLoaderInjection.With(srv.SealedContext()),
)
}