Skip to content

Commit 1c27bdb

Browse files
committed
pkg: make $id in tasks a reference to a hidden field
As suggested by Paul and Marcel, hidden fields are unique to a package, so unlike regular fields like `$id` they cannot be replaced by a field from a different package or a field from unmarshalled data. For each of the task definitions, keep `$id` around for backwards compatibility, but make it a reference to the new `_id`. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I8d1d8ba765f782e2cb9d3f70612c7834fef53fa5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1214986 Reviewed-by: Paul Jolly <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent eebcefc commit 1c27bdb

22 files changed

+186
-145
lines changed

cmd/cue/cmd/testdata/script/cmd_baddisplay.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmp stderr cmd_baddisplay.out
55
-- cmd_baddisplay.out --
66
command.baddisplay.display.text: conflicting values 42 and string (mismatched types int and string):
77
./task_tool.cue:6:9
8-
tool/cli:4:9
8+
tool/cli:5:9
99
-- task.cue --
1010
package home
1111
message: "Hello world!"

cmd/cue/cmd/testdata/script/cmd_err.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ cmp stderr cmd_badfields.out
55
-- cmd_badfields.out --
66
command.ref.task.display.contents: invalid bytes argument: non-concrete value (string|bytes):
77
./task_tool.cue:6:8
8-
tool/file:17:3
8+
tool/file:20:3
99
command.ref.task.display.filename: invalid string argument: non-concrete value string:
1010
./task_tool.cue:6:8
1111
./task_tool.cue:7:9
12-
tool/file:15:3
13-
tool/file:15:16
12+
tool/file:18:3
13+
tool/file:18:16
1414
-- task_tool.cue --
1515
package home
1616

cmd/cue/cmd/testdata/script/cmd_errpos.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ command.prompter.contents: invalid bytes argument: non-concrete value string:
99
./task_tool.cue:9:10
1010
./task_tool.cue:12:13
1111
./task_tool.cue:17:3
12-
tool/file:11:3
12+
tool/file:13:3
1313
command.prompter.filename: invalid string argument: non-concrete value string:
1414
./task_tool.cue:9:10
15-
tool/file:9:3
16-
tool/file:9:16
15+
tool/file:11:3
16+
tool/file:11:16
1717
-- task_tool.cue --
1818
package foo
1919

pkg/tool/cli/cli.cue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ package cli
1616

1717
// Print sends text to the stdout of the current process.
1818
Print: {
19-
$id: *"tool/cli.Print" | "print" // for backwards compatibility
19+
$id: _id
20+
_id: *"tool/cli.Print" | "print" // for backwards compatibility
2021

2122
// text is the text to be printed.
2223
text: string
@@ -30,7 +31,8 @@ Print: {
3031
// response: bool
3132
// })
3233
Ask: {
33-
$id: "tool/cli.Ask"
34+
$id: _id
35+
_id: "tool/cli.Ask"
3436

3537
// prompt sends this message to the output.
3638
prompt: string

pkg/tool/cli/pkg.go

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/tool/exec/exec.cue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ package exec
1616

1717
// Run executes a program with the given arguments.
1818
Run: {
19-
$id: *"tool/exec.Run" | "exec" // exec for backwards compatibility
19+
$id: _id
20+
_id: *"tool/exec.Run" | "exec" // exec for backwards compatibility
2021

2122
// cmd is a non-empty list holding the program name to run
2223
// and the arguments to be passed to it.

pkg/tool/exec/pkg.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/tool/file/file.cue

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ package file
1616

1717
// Read reads the contents of a file.
1818
Read: {
19-
$id: "tool/file.Read"
19+
$id: _id
20+
_id: "tool/file.Read"
2021

2122
// filename names the file to read.
2223
//
@@ -32,7 +33,8 @@ Read: {
3233

3334
// Append writes contents to the given file.
3435
Append: {
35-
$id: "tool/file.Append"
36+
$id: _id
37+
_id: "tool/file.Append"
3638

3739
// filename names the file to append.
3840
//
@@ -49,7 +51,8 @@ Append: {
4951

5052
// Create writes contents to the given file.
5153
Create: {
52-
$id: "tool/file.Create"
54+
$id: _id
55+
_id: "tool/file.Create"
5356

5457
// filename names the file to write.
5558
//
@@ -66,7 +69,8 @@ Create: {
6669

6770
// Glob returns a list of files.
6871
Glob: {
69-
$id: "tool/file.Glob"
72+
$id: _id
73+
_id: "tool/file.Glob"
7074

7175
// glob specifies the pattern to match files with.
7276
//
@@ -78,7 +82,8 @@ Glob: {
7882

7983
// Mkdir creates a directory at the specified path.
8084
Mkdir: {
81-
$id: "tool/file.Mkdir"
85+
$id: _id
86+
_id: "tool/file.Mkdir"
8287

8388
// The directory path to create.
8489
// If path is already a directory, Mkdir does nothing.
@@ -105,7 +110,8 @@ MkdirAll: Mkdir & {
105110
// It is the caller's responsibility to remove the directory when it is no
106111
// longer needed.
107112
MkdirTemp: {
108-
$id: "tool/file.MkdirTemp"
113+
$id: _id
114+
_id: "tool/file.MkdirTemp"
109115

110116
// The temporary directory is created in the directory specified by dir.
111117
// If dir is the empty string, MkdirTemp uses the default directory for
@@ -123,7 +129,8 @@ MkdirTemp: {
123129
// RemoveAll removes path and any children it contains.
124130
// It removes everything it can but returns the first error it encounters.
125131
RemoveAll: {
126-
$id: "tool/file.RemoveAll"
132+
$id: _id
133+
_id: "tool/file.RemoveAll"
127134

128135
// The path to remove.
129136
// If the path does not exist, RemoveAll does nothing.

pkg/tool/file/pkg.go

Lines changed: 28 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/tool/http/http.cue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Put: Do & {method: "PUT"}
2020
Delete: Do & {method: "DELETE"}
2121

2222
Do: {
23-
$id: *"tool/http.Do" | "http" // http for backwards compatibility
23+
$id: _id
24+
_id: *"tool/http.Do" | "http" // http for backwards compatibility
2425

2526
method: string
2627
url: string // TODO: make url.URL type

pkg/tool/http/pkg.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/tool/os/os.cue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,24 @@ Name: !="" & !~"^[$]"
2727
// To define a shorthand, define the shorthand as a new flag referring to
2828
// the flag of which it is a shorthand.
2929
Setenv: {
30-
$id: "tool/os.Setenv"
30+
$id: _id
31+
_id: "tool/os.Setenv"
3132

3233
{[Name]: Value}
3334
}
3435

3536
// Getenv gets and parses the specific command line variables.
3637
Getenv: {
37-
$id: "tool/os.Getenv"
38+
$id: _id
39+
_id: "tool/os.Getenv"
3840

3941
{[Name]: Value}
4042
}
4143

4244
// Environ populates a struct with all environment variables.
4345
Environ: {
44-
$id: "tool/os.Environ"
46+
$id: _id
47+
_id: "tool/os.Environ"
4548

4649
// A map of all populated values.
4750
// Individual entries may be specified ahead of time to enable
@@ -52,5 +55,6 @@ Environ: {
5255

5356
// Clearenv clears all environment variables.
5457
Clearenv: {
55-
$id: "tool/os.Clearenv"
58+
$id: _id
59+
_id: "tool/os.Clearenv"
5660
}

0 commit comments

Comments
 (0)