-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
ee731da
commit ad7af52
Showing
22 changed files
with
552 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
file | ||
dir |
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,19 @@ | ||
target( | ||
name="gen_file", | ||
driver = "bash", | ||
run = "echo hello > $OUT", | ||
out = "file", | ||
codegen = 'copy', | ||
) | ||
|
||
target( | ||
name="gen_dir", | ||
driver = "bash", | ||
run = [ | ||
"mkdir $OUT", | ||
"echo hello > $OUT/hello", | ||
"echo world > $OUT/world", | ||
], | ||
out = "dir", | ||
codegen = 'copy', | ||
) |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package engine | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/hephbuild/heph/internal/hartifact" | ||
pluginv1 "github.com/hephbuild/heph/plugin/gen/heph/plugin/v1" | ||
) | ||
|
||
func (e *Engine) codegenTree(ctx context.Context, def *LightLinkedTarget, outputs []ExecuteResultArtifact) error { | ||
if def.CodegenTree == nil { | ||
return nil | ||
} | ||
|
||
switch def.CodegenTree.GetMode() { | ||
case pluginv1.TargetDef_CodegenTree_CODEGEN_MODE_COPY: | ||
err := e.codegenCopyTree(ctx, def, outputs) | ||
if err != nil { | ||
return fmt.Errorf("copy: %w", err) | ||
} | ||
case pluginv1.TargetDef_CodegenTree_CODEGEN_MODE_LINK: | ||
err := e.codegenLinkTree(ctx, def, outputs) | ||
if err != nil { | ||
return fmt.Errorf("link: %w", err) | ||
} | ||
case pluginv1.TargetDef_CodegenTree_CODEGEN_MODE_UNSPECIFIED: | ||
default: | ||
return fmt.Errorf("unknown codegen mode %v", def.CodegenTree.GetMode()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Engine) codegenCopyTree(ctx context.Context, def *LightLinkedTarget, outputs []ExecuteResultArtifact) error { | ||
codegenPaths := make([]string, 0, len(outputs)) | ||
for _, path := range def.CodegenTree.GetPaths() { | ||
codegenPaths = append(codegenPaths, filepath.Join(def.Ref.GetPackage(), path)) | ||
} | ||
|
||
isUnderCodegenPath := func(p string) bool { | ||
if slices.Contains(codegenPaths, p) { | ||
return true | ||
} | ||
|
||
for _, codegenPath := range codegenPaths { | ||
if strings.HasPrefix(p, codegenPath) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
for _, output := range outputs { | ||
if output.Type != pluginv1.Artifact_TYPE_OUTPUT { | ||
continue | ||
} | ||
|
||
err := hartifact.Unpack(ctx, output.Artifact, e.Root, hartifact.WithFilter(isUnderCodegenPath)) | ||
if err != nil { | ||
return fmt.Errorf("unpack: %v: %w", output.Group, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *Engine) codegenLinkTree(ctx context.Context, def *LightLinkedTarget, outputs []ExecuteResultArtifact) error { | ||
// TODO | ||
|
||
return e.codegenCopyTree(ctx, def, outputs) | ||
} |
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
Oops, something went wrong.