Skip to content

Commit

Permalink
Add pulumi.rootDirectory to the yaml project generation and evalution.
Browse files Browse the repository at this point in the history
This is a part of pulumi/pulumi#18565
  • Loading branch information
brandonpollack23 committed Feb 20, 2025
1 parent d39c8a5 commit d8015ae
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Improvements-716.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
component: codegen
kind: Improvements
body: Add rootDirectory to codegen, runtime, and convert
time: 2025-02-18T23:42:18.755925+09:00
custom:
PR: "716"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
outputs:
rootDirectoryOutput: ${pulumi.rootDirectory}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l1-builtin-project-root
runtime: yaml
2 changes: 2 additions & 0 deletions pkg/pulumiyaml/analyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ func newTypeCache() *typeCache {
ast.ObjectProperty{Key: ast.String("project")},
ast.ObjectProperty{Key: ast.String("stack")},
ast.ObjectProperty{Key: ast.String("organization")},
ast.ObjectProperty{Key: ast.String("rootDirectory")},
)
return &typeCache{
exprs: map[ast.Expr]schema.Type{
Expand All @@ -1187,6 +1188,7 @@ func newTypeCache() *typeCache {
{Name: "project", Type: schema.StringType},
{Name: "stack", Type: schema.StringType},
{Name: "organization", Type: schema.StringType},
{Name: "rootDirectory", Type: schema.StringType},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/pulumiyaml/codegen/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func (g *generator) function(f *model.FunctionCallExpression) syn.Node {
return rng
}
switch f.Name {
case "stack", "project", "organization":
case "stack", "project", "organization", "rootDirectory":
return syn.String(fmt.Sprintf("${pulumi.%s}", f.Name))
case pcl.Invoke:
return g.MustInvoke(f, "")
Expand Down
18 changes: 12 additions & 6 deletions pkg/pulumiyaml/codegen/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (imp *importer) pulumiPropertyAccess(node ast.Expr, accessors []ast.Propert
Name: "organization",
Signature: simple,
}, true, nil
case "rootDirectory":
return &model.FunctionCallExpression{
Name: "rootDirectory",
Signature: simple,
}, true, nil
default:
return nil, true, wrapDiag("Unknown property of the `pulumi` variable: '%s'", prop.Name)
}
Expand Down Expand Up @@ -963,6 +968,7 @@ func (imp *importer) assignNames() {
// PCL has only one namspace with respect to binding, so we can't use any of
// these as names.
assigned := codegen.NewStringSet(
"cwd",
"element",
"entries",
"fileArchive",
Expand All @@ -974,18 +980,18 @@ func (imp *importer) assignNames() {
"join",
"length",
"lookup",
"organization",
"project",
"range",
"readFile",
"readDir",
"readFile",
"rootDirectory",
"secret",
"sha1",
"split",
"stack",
"toBase64",
"toJSON",
"sha1",
"stack",
"project",
"cwd",
"organization",
)

assign := func(name, suffix string) *model.Variable {
Expand Down
12 changes: 7 additions & 5 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,17 +918,19 @@ func (r *Runner) ensureSetup(ctx *pulumi.Context) {
return
}

var project, stack, organization string
var project, stack, organization, rootDirectory string
if ctx != nil {
project = ctx.Project()
stack = ctx.Stack()
organization = ctx.Organization()
rootDirectory = ctx.RootDirectory()
}
r.variables[PulumiVarName] = map[string]interface{}{
"cwd": cwd,
"project": project,
"stack": stack,
"organization": organization,
"cwd": cwd,
"organization": organization,
"project": project,
"rootDirectory": rootDirectory,
"stack": stack,
}
r.cwd = cwd
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (host *yamlLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest
fmt.Sprintf(`PULUMI_ORGANIZATION=%s`, req.GetOrganization()),
fmt.Sprintf(`PULUMI_PROJECT=%s`, req.GetProject()),
fmt.Sprintf(`PULUMI_CONFIG=%s`, jsonConfigValue),
fmt.Sprintf(`PULUMI_PROJECT_ROOT=%s`, req.Info.RootDirectory),
}

projPath, err := workspace.DetectProjectPathFrom(req.Info.RootDirectory)
Expand Down Expand Up @@ -233,6 +234,7 @@ func (host *yamlLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest
// This encapsulates a fair bit of the boilerplate otherwise needed to do RPCs, etc.
pctx, err := pulumi.NewContext(ctx, pulumi.RunInfo{
Project: req.GetProject(),
RootDirectory: req.Info.RootDirectory,
Stack: req.GetStack(),
Config: req.GetConfig(),
ConfigSecretKeys: req.GetConfigSecretKeys(),
Expand Down

0 comments on commit d8015ae

Please sign in to comment.