Skip to content

Commit 0c01daa

Browse files
committed
feat(cmd/rofl): Add support for build scripts
1 parent 5d8e97d commit 0c01daa

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

build/rofl/manifest.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const (
3232
TEETypeTDX = "tdx"
3333
)
3434

35+
// Well-known scripts.
36+
const (
37+
ScriptBuildPre = "build-pre"
38+
ScriptBuildPost = "build-post"
39+
)
40+
3541
// Manifest is the ROFL app manifest that configures various aspects of the app in a single place.
3642
type Manifest struct {
3743
// Name is the human readable ROFL app name.
@@ -50,6 +56,9 @@ type Manifest struct {
5056
// Deployments are the ROFL app deployments.
5157
Deployments map[string]*Deployment `yaml:"deployments" json:"deployments"`
5258

59+
// Scripts are custom scripts that are executed by the build system at specific stages.
60+
Scripts map[string]string `yaml:"scripts,omitempty" json:"scripts,omitempty"`
61+
5362
// sourceFn is the filename from which the manifest has been loaded.
5463
sourceFn string
5564
}

cmd/rofl/build/build.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ var (
7676
return
7777
}
7878

79+
// Setup some build environment variables.
80+
os.Setenv("ROFL_MANIFEST", manifest.SourceFileName())
81+
os.Setenv("ROFL_DEPLOYMENT", deploymentName)
82+
os.Setenv("ROFL_DEPLOYMENT_NETWORK", deployment.Network)
83+
os.Setenv("ROFL_DEPLOYMENT_PARATIME", deployment.ParaTime)
84+
os.Setenv("ROFL_TMPDIR", tmpDir)
85+
86+
runScript(manifest, buildRofl.ScriptBuildPre)
87+
7988
switch manifest.TEE {
8089
case buildRofl.TEETypeSGX:
8190
// SGX.
@@ -102,6 +111,8 @@ var (
102111
return
103112
}
104113

114+
runScript(manifest, buildRofl.ScriptBuildPost)
115+
105116
// Write the bundle out.
106117
outFn := fmt.Sprintf("%s.%s.orc", manifest.Name, deploymentName)
107118
if outputFn != "" {

cmd/rofl/build/scripts.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package build
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
8+
"github.com/spf13/cobra"
9+
10+
buildRofl "github.com/oasisprotocol/cli/build/rofl"
11+
)
12+
13+
// runScripts executes the specified build script using the current build environment.
14+
func runScript(manifest *buildRofl.Manifest, name string) {
15+
script, ok := manifest.Scripts[name]
16+
if !ok {
17+
return
18+
}
19+
20+
fmt.Printf("Running script '%s'...\n", name)
21+
22+
cmd := exec.Command( //nolint: gosec
23+
os.Getenv("SHELL"),
24+
"-c",
25+
script,
26+
)
27+
cmd.Stdout = os.Stdout
28+
cmd.Stderr = os.Stderr
29+
err := cmd.Run()
30+
if err != nil {
31+
cobra.CheckErr(fmt.Errorf("script '%s' failed to execute: %w", name, err))
32+
}
33+
}

0 commit comments

Comments
 (0)