Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion buildozer/buildozer_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,20 @@ function test_set_custom_code() {
)'
}

function test_set_custom_code_with_whitespace() {
in='cc_test(name = "a")'

run "$in" 'set attr foo(\
\ \ a\ =\ 1,\
)' '//pkg:a'
assert_equals 'cc_test(
name = "a",
attr = foo(
a = 1,
),
)'
}

function assert_output() {
echo "$1" > "expected"
diff -u "expected" "$log" || fail "Output didn't match"
Expand Down Expand Up @@ -1658,14 +1672,20 @@ add deps x#|a/pkg2:foo
add deps y|a/pkg2:bar|add deps c|a/pkg1:foo
add deps z|a/pkg2:bar
add deps a|//a/pkg1:bar
add deps b|a/pkg1:foo" > commands
add deps b|a/pkg1:foo

set attr func(a=1)|a/pkg1:foo
set attr func(\\
\ \ a\ =\ 1\\
)|a/pkg2:foo" > commands
}

function check_file_test() {
# Check that all dependencies have been added
cat > expected_pkg_1 <<EOF
cc_library(
name = "foo",
attr = func(a = 1),
deps = [
"a",
"b",
Expand All @@ -1689,6 +1709,9 @@ EOF
cat > expected_pkg_2 <<EOF
cc_library(
name = "foo",
attr = func(
a = 1,
),
deps = ["x#"],
)

Expand Down
22 changes: 15 additions & 7 deletions edit/buildozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,14 +1367,22 @@ func appendCommandsFromReader(opts *Options, reader io.Reader, commandsByFile ma
r := bufio.NewReader(reader)
atEOF := false
for !atEOF {
line, err := r.ReadString('\n')
if err == io.EOF {
atEOF = true
err = nil
}
if err != nil {
return fmt.Errorf("error while reading commands file: %v", err)
lineBuilder := strings.Builder{}
for !atEOF {
linePart, err := r.ReadString('\n')
if err == io.EOF {
atEOF = true
err = nil
}
if err != nil {
return fmt.Errorf("error while reading commands file: %v", err)
}
lineBuilder.WriteString(linePart)
if !strings.HasSuffix(linePart, "\\\n") {
break
}
}
line := lineBuilder.String()
line = strings.TrimSpace(line)
if line == "" || line[0] == '#' {
continue
Expand Down