Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 22ece62

Browse files
Parser: added Herdoc struct and list to Command on Go side, not yet on Python side
1 parent a15dfd0 commit 22ece62

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

parse.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
"github.com/moby/buildkit/frontend/dockerfile/parser"
1010
)
1111

12+
// Represents info about a heredoc.
13+
type Heredoc struct {
14+
Name string
15+
FileDescriptor uint
16+
Content string
17+
}
18+
1219
// Represents a single line (layer) in a Dockerfile.
1320
// For example `FROM ubuntu:xenial`
1421
type Command struct {
@@ -20,6 +27,7 @@ type Command struct {
2027
EndLine int // The original source line number which ends this command
2128
Flags []string // Any flags such as `--from=...` for `COPY`.
2229
Value []string // The contents of the command (ex: `ubuntu:xenial`)
30+
Heredocs []Heredoc // Extra heredoc content attachments
2331
}
2432

2533
// A failure in opening a file for reading.
@@ -88,6 +96,9 @@ func ParseReader(file io.Reader) ([]Command, error) {
8896
for _, heredoc := range child.Heredocs {
8997
cmd.Original = cmd.Original + heredoc.Content + heredoc.Name + "\n"
9098
cmd.Value = append(cmd.Value, heredoc.Content)
99+
cmd.Heredocs = append(cmd.Heredocs, Heredoc{Name: heredoc.Name,
100+
FileDescriptor: heredoc.FileDescriptor,
101+
Content: heredoc.Content})
91102
}
92103
}
93104

parse_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ EOF
134134
EndLine: 5,
135135
Flags: []string{},
136136
Value: []string{"source $HOME/.bashrc && echo $HOME\necho \"Hello\" >> /hello\necho \"World!\" >> /hello\n"},
137+
Heredocs: []Heredoc{Heredoc{Name: "EOF",
138+
FileDescriptor: 0,
139+
Content: "source $HOME/.bashrc && echo $HOME\necho \"Hello\" >> /hello\necho \"World!\" >> /hello\n"},
140+
},
137141
},
138142
}
139143
assert.Equal(t, expected, cmds)
@@ -156,6 +160,13 @@ FILE2
156160
EndLine: 5,
157161
Flags: []string{},
158162
Value: []string{"content 1\n", "content 2\n"},
163+
Heredocs: []Heredoc{Heredoc{Name: "FILE1",
164+
FileDescriptor: 0,
165+
Content: "content 1\n"},
166+
Heredoc{Name: "FILE2",
167+
FileDescriptor: 0,
168+
Content: "content 2\n"},
169+
},
159170
},
160171
}
161172
assert.Equal(t, expected, cmds)

0 commit comments

Comments
 (0)