bp2build: codegen singleton lists on one line.

This CL refactors the bp2build code generator to pretty print lists with
a single element on one line, instead of taking up three lines, which
can make BUILD files unnecessarily long. A single line singleton list is
also more commonly used in BUILD files.

Test: TH
Change-Id: Ic9e44741bbb070c8f45925466b9ccdd0608498b2
This commit is contained in:
Jingwen Chen 2021-04-08 14:40:57 +00:00
parent 6393098ecf
commit b4628eb03f
8 changed files with 142 additions and 354 deletions

View File

@ -394,21 +394,34 @@ func prettyPrint(propertyValue reflect.Value, indent int) (string, error) {
return "", nil return "", nil
} }
ret = "[\n" if propertyValue.Len() == 1 {
for i := 0; i < propertyValue.Len(); i++ { // Single-line list for list with only 1 element
indexedValue, err := prettyPrint(propertyValue.Index(i), indent+1) ret += "["
indexedValue, err := prettyPrint(propertyValue.Index(0), indent)
if err != nil { if err != nil {
return "", err return "", err
} }
ret += indexedValue
ret += "]"
} else {
// otherwise, use a multiline list.
ret += "[\n"
for i := 0; i < propertyValue.Len(); i++ {
indexedValue, err := prettyPrint(propertyValue.Index(i), indent+1)
if err != nil {
return "", err
}
if indexedValue != "" { if indexedValue != "" {
ret += makeIndent(indent + 1) ret += makeIndent(indent + 1)
ret += indexedValue ret += indexedValue
ret += ",\n" ret += ",\n"
}
} }
ret += makeIndent(indent)
ret += "]"
} }
ret += makeIndent(indent)
ret += "]"
case reflect.Struct: case reflect.Struct:
// Special cases where the bp2build sends additional information to the codegenerator // Special cases where the bp2build sends additional information to the codegenerator
// by wrapping the attributes in a custom struct type. // by wrapping the attributes in a custom struct type.

View File

@ -27,9 +27,7 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
expectedBazelTarget string expectedBazelTarget string
}{ }{
{ {
bp: `custom { bp: `custom { name: "foo" }
name: "foo",
}
`, `,
expectedBazelTarget: `soong_module( expectedBazelTarget: `soong_module(
name = "foo", name = "foo",
@ -85,9 +83,7 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
soong_module_variant = "", soong_module_variant = "",
soong_module_deps = [ soong_module_deps = [
], ],
required = [ required = ["bar"],
"bar",
],
)`, )`,
}, },
{ {
@ -116,12 +112,10 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
targets: ["goal_foo"], targets: ["goal_foo"],
tag: ".foo", tag: ".foo",
}, },
dists: [ dists: [{
{ targets: ["goal_bar"],
targets: ["goal_bar"], tag: ".bar",
tag: ".bar", }],
},
],
} }
`, `,
expectedBazelTarget: `soong_module( expectedBazelTarget: `soong_module(
@ -133,18 +127,12 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
], ],
dist = { dist = {
"tag": ".foo", "tag": ".foo",
"targets": [ "targets": ["goal_foo"],
"goal_foo",
],
}, },
dists = [ dists = [{
{ "tag": ".bar",
"tag": ".bar", "targets": ["goal_bar"],
"targets": [ }],
"goal_bar",
],
},
],
)`, )`,
}, },
{ {
@ -169,19 +157,13 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
soong_module_variant = "", soong_module_variant = "",
soong_module_deps = [ soong_module_deps = [
], ],
dists = [ dists = [{
{ "tag": ".tag",
"tag": ".tag", "targets": ["my_goal"],
"targets": [ }],
"my_goal",
],
},
],
owner = "custom_owner", owner = "custom_owner",
ramdisk = True, ramdisk = True,
required = [ required = ["bar"],
"bar",
],
target_required = [ target_required = [
"qux", "qux",
"bazqux", "bazqux",
@ -553,9 +535,7 @@ genrule {
}`, }`,
expectedBazelTargets: []string{`filegroup( expectedBazelTargets: []string{`filegroup(
name = "fg_foo", name = "fg_foo",
srcs = [ srcs = ["b"],
"b",
],
)`, )`,
}, },
}, },
@ -625,7 +605,7 @@ genrule {
bp: `filegroup { bp: `filegroup {
name: "foobar", name: "foobar",
srcs: [ srcs: [
":foo", ":foo",
"c", "c",
], ],
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
@ -671,25 +651,15 @@ genrule {
`genrule( `genrule(
name = "foo", name = "foo",
cmd = "$(location :foo.tool) --genDir=$(GENDIR) arg $(SRCS) $(OUTS)", cmd = "$(location :foo.tool) --genDir=$(GENDIR) arg $(SRCS) $(OUTS)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["foo.in"],
], tools = [":foo.tool"],
srcs = [
"foo.in",
],
tools = [
":foo.tool",
],
)`, )`,
`genrule( `genrule(
name = "foo.tool", name = "foo.tool",
cmd = "cp $(SRCS) $(OUTS)", cmd = "cp $(SRCS) $(OUTS)",
outs = [ outs = ["foo_tool.out"],
"foo_tool.out", srcs = ["foo_tool.in"],
],
srcs = [
"foo_tool.in",
],
)`, )`,
}, },
}, },
@ -718,15 +688,9 @@ genrule {
expectedBazelTargets: []string{`genrule( expectedBazelTargets: []string{`genrule(
name = "foo", name = "foo",
cmd = "$(locations :foo.tools) -s $(OUTS) $(SRCS)", cmd = "$(locations :foo.tools) -s $(OUTS) $(SRCS)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["foo.in"],
], tools = [":foo.tools"],
srcs = [
"foo.in",
],
tools = [
":foo.tools",
],
)`, )`,
`genrule( `genrule(
name = "foo.tools", name = "foo.tools",
@ -735,9 +699,7 @@ genrule {
"foo_tool.out", "foo_tool.out",
"foo_tool2.out", "foo_tool2.out",
], ],
srcs = [ srcs = ["foo_tool.in"],
"foo_tool.in",
],
)`, )`,
}, },
}, },
@ -758,15 +720,9 @@ genrule {
expectedBazelTargets: []string{`genrule( expectedBazelTargets: []string{`genrule(
name = "foo", name = "foo",
cmd = "$(locations //other:foo.tool) -s $(OUTS) $(SRCS)", cmd = "$(locations //other:foo.tool) -s $(OUTS) $(SRCS)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["foo.in"],
], tools = ["//other:foo.tool"],
srcs = [
"foo.in",
],
tools = [
"//other:foo.tool",
],
)`, )`,
}, },
fs: otherGenruleBp, fs: otherGenruleBp,
@ -788,15 +744,9 @@ genrule {
expectedBazelTargets: []string{`genrule( expectedBazelTargets: []string{`genrule(
name = "foo", name = "foo",
cmd = "$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)", cmd = "$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["//other:other.tool"],
], tools = ["//other:foo.tool"],
srcs = [
"//other:other.tool",
],
tools = [
"//other:foo.tool",
],
)`, )`,
}, },
fs: otherGenruleBp, fs: otherGenruleBp,
@ -818,12 +768,8 @@ genrule {
expectedBazelTargets: []string{`genrule( expectedBazelTargets: []string{`genrule(
name = "foo", name = "foo",
cmd = "$(location //other:foo.tool) -s $(OUTS) $(SRCS)", cmd = "$(location //other:foo.tool) -s $(OUTS) $(SRCS)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["foo.in"],
],
srcs = [
"foo.in",
],
tools = [ tools = [
"//other:foo.tool", "//other:foo.tool",
"//other:other.tool", "//other:other.tool",
@ -849,12 +795,8 @@ genrule {
expectedBazelTargets: []string{`genrule( expectedBazelTargets: []string{`genrule(
name = "foo", name = "foo",
cmd = "$(locations //other:foo.tool) -s $(OUTS) $(SRCS)", cmd = "$(locations //other:foo.tool) -s $(OUTS) $(SRCS)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["foo.in"],
],
srcs = [
"foo.in",
],
tools = [ tools = [
"//other:foo.tool", "//other:foo.tool",
"//other:other.tool", "//other:other.tool",
@ -879,12 +821,8 @@ genrule {
expectedBazelTargets: []string{`genrule( expectedBazelTargets: []string{`genrule(
name = "foo", name = "foo",
cmd = "cp $(SRCS) $(OUTS)", cmd = "cp $(SRCS) $(OUTS)",
outs = [ outs = ["foo.out"],
"foo.out", srcs = ["foo.in"],
],
srcs = [
"foo.in",
],
)`, )`,
}, },
}, },
@ -988,12 +926,8 @@ genrule {
expectedBazelTarget: `genrule( expectedBazelTarget: `genrule(
name = "gen", name = "gen",
cmd = "do-something $(SRCS) $(OUTS)", cmd = "do-something $(SRCS) $(OUTS)",
outs = [ outs = ["out"],
"out", srcs = ["in1"],
],
srcs = [
"in1",
],
)`, )`,
description: "genrule applies properties from a genrule_defaults dependency if not specified", description: "genrule applies properties from a genrule_defaults dependency if not specified",
}, },
@ -1062,12 +996,8 @@ genrule {
expectedBazelTarget: `genrule( expectedBazelTarget: `genrule(
name = "gen", name = "gen",
cmd = "cp $(SRCS) $(OUTS)", cmd = "cp $(SRCS) $(OUTS)",
outs = [ outs = ["out"],
"out", srcs = ["in1"],
],
srcs = [
"in1",
],
)`, )`,
description: "genrule applies properties from list of genrule_defaults", description: "genrule applies properties from list of genrule_defaults",
}, },

View File

@ -109,12 +109,8 @@ cc_library {
`, `,
expectedBazelTargets: []string{`cc_library( expectedBazelTargets: []string{`cc_library(
name = "foo-lib", name = "foo-lib",
copts = [ copts = ["-Wall"],
"-Wall", deps = [":some-headers"],
],
deps = [
":some-headers",
],
hdrs = [ hdrs = [
"header.h", "header.h",
"header.hh", "header.hh",
@ -127,40 +123,20 @@ cc_library {
"header.h.generic", "header.h.generic",
"foo-dir/a.h", "foo-dir/a.h",
], ],
includes = [ includes = ["foo-dir"],
"foo-dir", linkopts = ["-Wl,--exclude-libs=bar.a"] + select({
], "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"],
linkopts = [ "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"],
"-Wl,--exclude-libs=bar.a",
] + select({
"//build/bazel/platforms/arch:x86": [
"-Wl,--exclude-libs=baz.a",
],
"//build/bazel/platforms/arch:x86_64": [
"-Wl,--exclude-libs=qux.a",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
srcs = [ srcs = ["impl.cpp"] + select({
"impl.cpp", "//build/bazel/platforms/arch:x86": ["x86.cpp"],
] + select({ "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
"//build/bazel/platforms/arch:x86": [
"x86.cpp",
],
"//build/bazel/platforms/arch:x86_64": [
"x86_64.cpp",
],
"//conditions:default": [], "//conditions:default": [],
}) + select({ }) + select({
"//build/bazel/platforms/os:android": [ "//build/bazel/platforms/os:android": ["android.cpp"],
"android.cpp", "//build/bazel/platforms/os:darwin": ["darwin.cpp"],
], "//build/bazel/platforms/os:linux": ["linux.cpp"],
"//build/bazel/platforms/os:darwin": [
"darwin.cpp",
],
"//build/bazel/platforms/os:linux": [
"linux.cpp",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
)`}, )`},
@ -215,9 +191,7 @@ cc_library {
"-Wunused", "-Wunused",
"-Werror", "-Werror",
], ],
deps = [ deps = [":libc_headers"],
":libc_headers",
],
hdrs = [ hdrs = [
"linked_list.h", "linked_list.h",
"linker.h", "linker.h",
@ -232,17 +206,11 @@ cc_library {
"-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
] + select({ ] + select({
"//build/bazel/platforms/arch:x86": [ "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=libgcc_eh.a"],
"-Wl,--exclude-libs=libgcc_eh.a", "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"],
],
"//build/bazel/platforms/arch:x86_64": [
"-Wl,--exclude-libs=libgcc_eh.a",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
srcs = [ srcs = ["ld_android.cpp"],
"ld_android.cpp",
],
)`}, )`},
}, },
} }

View File

@ -141,30 +141,18 @@ cc_library_headers {
"dir-2/dir2a.h", "dir-2/dir2a.h",
"dir-2/dir2b.h", "dir-2/dir2b.h",
] + select({ ] + select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": ["arch_arm64_exported_include_dir/a.h"],
"arch_arm64_exported_include_dir/a.h", "//build/bazel/platforms/arch:x86": ["arch_x86_exported_include_dir/b.h"],
], "//build/bazel/platforms/arch:x86_64": ["arch_x86_64_exported_include_dir/c.h"],
"//build/bazel/platforms/arch:x86": [
"arch_x86_exported_include_dir/b.h",
],
"//build/bazel/platforms/arch:x86_64": [
"arch_x86_64_exported_include_dir/c.h",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
includes = [ includes = [
"dir-1", "dir-1",
"dir-2", "dir-2",
] + select({ ] + select({
"//build/bazel/platforms/arch:arm64": [ "//build/bazel/platforms/arch:arm64": ["arch_arm64_exported_include_dir"],
"arch_arm64_exported_include_dir", "//build/bazel/platforms/arch:x86": ["arch_x86_exported_include_dir"],
], "//build/bazel/platforms/arch:x86_64": ["arch_x86_64_exported_include_dir"],
"//build/bazel/platforms/arch:x86": [
"arch_x86_exported_include_dir",
],
"//build/bazel/platforms/arch:x86_64": [
"arch_x86_64_exported_include_dir",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
)`, `cc_library_headers( )`, `cc_library_headers(
@ -173,18 +161,14 @@ cc_library_headers {
"lib-1/lib1a.h", "lib-1/lib1a.h",
"lib-1/lib1b.h", "lib-1/lib1b.h",
], ],
includes = [ includes = ["lib-1"],
"lib-1",
],
)`, `cc_library_headers( )`, `cc_library_headers(
name = "lib-2", name = "lib-2",
hdrs = [ hdrs = [
"lib-2/lib2a.h", "lib-2/lib2a.h",
"lib-2/lib2b.h", "lib-2/lib2b.h",
], ],
includes = [ includes = ["lib-2"],
"lib-2",
],
)`}, )`},
}, },
{ {
@ -223,27 +207,13 @@ cc_library_headers {
name = "darwin-lib", name = "darwin-lib",
)`, `cc_library_headers( )`, `cc_library_headers(
name = "foo_headers", name = "foo_headers",
deps = [ deps = [":base-lib"] + select({
":base-lib", "//build/bazel/platforms/os:android": [":android-lib"],
] + select({ "//build/bazel/platforms/os:darwin": [":darwin-lib"],
"//build/bazel/platforms/os:android": [ "//build/bazel/platforms/os:fuchsia": [":fuchsia-lib"],
":android-lib", "//build/bazel/platforms/os:linux": [":linux-lib"],
], "//build/bazel/platforms/os:linux_bionic": [":linux_bionic-lib"],
"//build/bazel/platforms/os:darwin": [ "//build/bazel/platforms/os:windows": [":windows-lib"],
":darwin-lib",
],
"//build/bazel/platforms/os:fuchsia": [
":fuchsia-lib",
],
"//build/bazel/platforms/os:linux": [
":linux-lib",
],
"//build/bazel/platforms/os:linux_bionic": [
":linux_bionic-lib",
],
"//build/bazel/platforms/os:windows": [
":windows-lib",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
)`, `cc_library_headers( )`, `cc_library_headers(

View File

@ -231,9 +231,7 @@ cc_library_static {
"implicit_include_1.h", "implicit_include_1.h",
"implicit_include_2.h", "implicit_include_2.h",
], ],
includes = [ includes = ["."],
".",
],
linkstatic = True, linkstatic = True,
srcs = [ srcs = [
"static_lib_1.cc", "static_lib_1.cc",
@ -246,9 +244,7 @@ cc_library_static {
"implicit_include_1.h", "implicit_include_1.h",
"implicit_include_2.h", "implicit_include_2.h",
], ],
includes = [ includes = ["."],
".",
],
linkstatic = True, linkstatic = True,
srcs = [ srcs = [
"static_lib_2.cc", "static_lib_2.cc",
@ -261,9 +257,7 @@ cc_library_static {
"implicit_include_1.h", "implicit_include_1.h",
"implicit_include_2.h", "implicit_include_2.h",
], ],
includes = [ includes = ["."],
".",
],
linkstatic = True, linkstatic = True,
srcs = [ srcs = [
"whole_static_lib_1.cc", "whole_static_lib_1.cc",
@ -276,9 +270,7 @@ cc_library_static {
"implicit_include_1.h", "implicit_include_1.h",
"implicit_include_2.h", "implicit_include_2.h",
], ],
includes = [ includes = ["."],
".",
],
linkstatic = True, linkstatic = True,
srcs = [ srcs = [
"whole_static_lib_2.cc", "whole_static_lib_2.cc",

View File

@ -75,9 +75,7 @@ func TestCcObjectBp2Build(t *testing.T) {
"include", "include",
".", ".",
], ],
srcs = [ srcs = ["a/b/c.c"],
"a/b/c.c",
],
)`, )`,
}, },
}, },
@ -124,9 +122,7 @@ cc_defaults {
"include", "include",
".", ".",
], ],
srcs = [ srcs = ["a/b/c.c"],
"a/b/c.c",
],
)`, )`,
}, },
}, },
@ -156,29 +152,15 @@ cc_object {
`, `,
expectedBazelTargets: []string{`cc_object( expectedBazelTargets: []string{`cc_object(
name = "bar", name = "bar",
copts = [ copts = ["-fno-addrsig"],
"-fno-addrsig", local_include_dirs = ["."],
], srcs = ["x/y/z.c"],
local_include_dirs = [
".",
],
srcs = [
"x/y/z.c",
],
)`, `cc_object( )`, `cc_object(
name = "foo", name = "foo",
copts = [ copts = ["-fno-addrsig"],
"-fno-addrsig", deps = [":bar"],
], local_include_dirs = ["."],
deps = [ srcs = ["a/b/c.c"],
":bar",
],
local_include_dirs = [
".",
],
srcs = [
"a/b/c.c",
],
)`, )`,
}, },
}, },
@ -201,12 +183,8 @@ cc_object {
`, `,
expectedBazelTargets: []string{`cc_object( expectedBazelTargets: []string{`cc_object(
name = "foo", name = "foo",
copts = [ copts = ["-fno-addrsig"],
"-fno-addrsig", srcs = ["a/b/c.c"],
],
srcs = [
"a/b/c.c",
],
)`, )`,
}, },
}, },
@ -229,12 +207,8 @@ cc_object {
`, `,
expectedBazelTargets: []string{`cc_object( expectedBazelTargets: []string{`cc_object(
name = "foo", name = "foo",
asflags = [ asflags = ["-DPLATFORM_SDK_VERSION={Platform_sdk_version}"],
"-DPLATFORM_SDK_VERSION={Platform_sdk_version}", copts = ["-fno-addrsig"],
],
copts = [
"-fno-addrsig",
],
)`, )`,
}, },
}, },
@ -322,23 +296,13 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
expectedBazelTargets: []string{ expectedBazelTargets: []string{
`cc_object( `cc_object(
name = "foo", name = "foo",
copts = [ copts = ["-fno-addrsig"] + select({
"-fno-addrsig", "//build/bazel/platforms/arch:x86": ["-fPIC"],
] + select({
"//build/bazel/platforms/arch:x86": [
"-fPIC",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
local_include_dirs = [ local_include_dirs = ["."],
".", srcs = ["a.cpp"] + select({
], "//build/bazel/platforms/arch:arm": ["arch/arm/file.S"],
srcs = [
"a.cpp",
] + select({
"//build/bazel/platforms/arch:arm": [
"arch/arm/file.S",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
)`, )`,
@ -376,41 +340,19 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
expectedBazelTargets: []string{ expectedBazelTargets: []string{
`cc_object( `cc_object(
name = "foo", name = "foo",
copts = [ copts = ["-fno-addrsig"] + select({
"-fno-addrsig", "//build/bazel/platforms/arch:arm": ["-Wall"],
] + select({ "//build/bazel/platforms/arch:arm64": ["-Wall"],
"//build/bazel/platforms/arch:arm": [ "//build/bazel/platforms/arch:x86": ["-fPIC"],
"-Wall", "//build/bazel/platforms/arch:x86_64": ["-fPIC"],
],
"//build/bazel/platforms/arch:arm64": [
"-Wall",
],
"//build/bazel/platforms/arch:x86": [
"-fPIC",
],
"//build/bazel/platforms/arch:x86_64": [
"-fPIC",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
local_include_dirs = [ local_include_dirs = ["."],
".", srcs = ["base.cpp"] + select({
], "//build/bazel/platforms/arch:arm": ["arm.cpp"],
srcs = [ "//build/bazel/platforms/arch:arm64": ["arm64.cpp"],
"base.cpp", "//build/bazel/platforms/arch:x86": ["x86.cpp"],
] + select({ "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
"//build/bazel/platforms/arch:arm": [
"arm.cpp",
],
"//build/bazel/platforms/arch:arm64": [
"arm64.cpp",
],
"//build/bazel/platforms/arch:x86": [
"x86.cpp",
],
"//build/bazel/platforms/arch:x86_64": [
"x86_64.cpp",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
)`, )`,
@ -441,26 +383,14 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
expectedBazelTargets: []string{ expectedBazelTargets: []string{
`cc_object( `cc_object(
name = "foo", name = "foo",
copts = [ copts = ["-fno-addrsig"] + select({
"-fno-addrsig", "//build/bazel/platforms/os:android": ["-fPIC"],
] + select({ "//build/bazel/platforms/os:darwin": ["-Wall"],
"//build/bazel/platforms/os:android": [ "//build/bazel/platforms/os:windows": ["-fPIC"],
"-fPIC",
],
"//build/bazel/platforms/os:darwin": [
"-Wall",
],
"//build/bazel/platforms/os:windows": [
"-fPIC",
],
"//conditions:default": [], "//conditions:default": [],
}), }),
local_include_dirs = [ local_include_dirs = ["."],
".", srcs = ["base.cpp"],
],
srcs = [
"base.cpp",
],
)`, )`,
}, },
}, },

View File

@ -33,24 +33,15 @@ func TestPythonBinaryHost(t *testing.T) {
blueprint: `python_binary_host { blueprint: `python_binary_host {
name: "foo", name: "foo",
main: "a.py", main: "a.py",
srcs: [ srcs: ["**/*.py"],
"**/*.py" exclude_srcs: ["b/e.py"],
], data: ["files/data.txt",],
exclude_srcs: [
"b/e.py"
],
data: [
"files/data.txt",
],
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
} }
`, `,
expectedBazelTargets: []string{`py_binary( expectedBazelTargets: []string{`py_binary(
name = "foo", name = "foo",
data = [ data = ["files/data.txt"],
"files/data.txt",
],
main = "a.py", main = "a.py",
srcs = [ srcs = [
"a.py", "a.py",
@ -83,9 +74,7 @@ func TestPythonBinaryHost(t *testing.T) {
expectedBazelTargets: []string{`py_binary( expectedBazelTargets: []string{`py_binary(
name = "foo", name = "foo",
python_version = "PY2", python_version = "PY2",
srcs = [ srcs = ["a.py"],
"a.py",
],
)`, )`,
}, },
}, },
@ -113,9 +102,7 @@ func TestPythonBinaryHost(t *testing.T) {
// python_version is PY3 by default. // python_version is PY3 by default.
`py_binary( `py_binary(
name = "foo", name = "foo",
srcs = [ srcs = ["a.py"],
"a.py",
],
)`, )`,
}, },
}, },

View File

@ -74,9 +74,7 @@ func TestShBinaryBp2Build(t *testing.T) {
}`, }`,
expectedBazelTargets: []string{`sh_binary( expectedBazelTargets: []string{`sh_binary(
name = "foo", name = "foo",
srcs = [ srcs = ["foo.sh"],
"foo.sh",
],
)`}, )`},
}, },
} }