Merge "Use bazel syntax for fully qualified name in path property"
This commit is contained in:
@@ -2812,30 +2812,57 @@ func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
|
|||||||
return m.bp
|
return m.bp
|
||||||
}
|
}
|
||||||
|
|
||||||
// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
|
// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name"
|
||||||
// was not a module reference.
|
// into the module name, or empty string if the input was not a module reference.
|
||||||
func SrcIsModule(s string) (module string) {
|
func SrcIsModule(s string) (module string) {
|
||||||
if len(s) > 1 && s[0] == ':' {
|
if len(s) > 1 {
|
||||||
return s[1:]
|
if s[0] == ':' {
|
||||||
|
module = s[1:]
|
||||||
|
if !isUnqualifiedModuleName(module) {
|
||||||
|
// The module name should be unqualified but is not so do not treat it as a module.
|
||||||
|
module = ""
|
||||||
|
}
|
||||||
|
} else if s[0] == '/' && s[1] == '/' {
|
||||||
|
module = s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
|
// SrcIsModule decodes module references in the format ":unqualified-name{.tag}" or
|
||||||
// module name and an empty string for the tag, or empty strings if the input was not a module reference.
|
// "//namespace:name{.tag}" into the module name and an empty string for the tag, or empty strings
|
||||||
|
// if the input was not a module reference.
|
||||||
func SrcIsModuleWithTag(s string) (module, tag string) {
|
func SrcIsModuleWithTag(s string) (module, tag string) {
|
||||||
if len(s) > 1 && s[0] == ':' {
|
if len(s) > 1 {
|
||||||
module = s[1:]
|
if s[0] == ':' {
|
||||||
if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
|
module = s[1:]
|
||||||
if module[len(module)-1] == '}' {
|
} else if s[0] == '/' && s[1] == '/' {
|
||||||
tag = module[tagStart+1 : len(module)-1]
|
module = s
|
||||||
module = module[:tagStart]
|
}
|
||||||
return module, tag
|
|
||||||
|
if module != "" {
|
||||||
|
if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
|
||||||
|
if module[len(module)-1] == '}' {
|
||||||
|
tag = module[tagStart+1 : len(module)-1]
|
||||||
|
module = module[:tagStart]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if s[0] == ':' && !isUnqualifiedModuleName(module) {
|
||||||
|
// The module name should be unqualified but is not so do not treat it as a module.
|
||||||
|
module = ""
|
||||||
|
tag = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return module, ""
|
|
||||||
}
|
}
|
||||||
return "", ""
|
|
||||||
|
return module, tag
|
||||||
|
}
|
||||||
|
|
||||||
|
// isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e.
|
||||||
|
// does not contain any /.
|
||||||
|
func isUnqualifiedModuleName(module string) bool {
|
||||||
|
return strings.IndexByte(module, '/') == -1
|
||||||
}
|
}
|
||||||
|
|
||||||
type sourceOrOutputDependencyTag struct {
|
type sourceOrOutputDependencyTag struct {
|
||||||
|
@@ -55,6 +55,27 @@ func TestSrcIsModule(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantModule: "foo:bar",
|
wantModule: "foo:bar",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "fully qualified",
|
||||||
|
args: args{
|
||||||
|
s: "//foo:bar",
|
||||||
|
},
|
||||||
|
wantModule: "//foo:bar",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "fully qualified with tag",
|
||||||
|
args: args{
|
||||||
|
s: "//foo:bar{.tag}",
|
||||||
|
},
|
||||||
|
wantModule: "//foo:bar{.tag}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid unqualified name",
|
||||||
|
args: args{
|
||||||
|
s: ":foo/bar",
|
||||||
|
},
|
||||||
|
wantModule: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@@ -128,6 +149,35 @@ func TestSrcIsModuleWithTag(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantModule: "foo.bar}",
|
wantModule: "foo.bar}",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "fully qualified",
|
||||||
|
args: args{
|
||||||
|
s: "//foo:bar",
|
||||||
|
},
|
||||||
|
wantModule: "//foo:bar",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "fully qualified with tag",
|
||||||
|
args: args{
|
||||||
|
s: "//foo:bar{.tag}",
|
||||||
|
},
|
||||||
|
wantModule: "//foo:bar",
|
||||||
|
wantTag: ".tag",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid unqualified name",
|
||||||
|
args: args{
|
||||||
|
s: ":foo/bar",
|
||||||
|
},
|
||||||
|
wantModule: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid unqualified name with tag",
|
||||||
|
args: args{
|
||||||
|
s: ":foo/bar{.tag}",
|
||||||
|
},
|
||||||
|
wantModule: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
@@ -1351,7 +1351,6 @@ func TestPathForModuleSrc(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// This test makes sure that an unqualified module name cannot contain characters that make
|
// This test makes sure that an unqualified module name cannot contain characters that make
|
||||||
// it appear as a qualified module name.
|
// it appear as a qualified module name.
|
||||||
// TODO(b/193228441): Fix broken test.
|
|
||||||
name: "output file provider, invalid fully qualified name",
|
name: "output file provider, invalid fully qualified name",
|
||||||
bp: `
|
bp: `
|
||||||
test {
|
test {
|
||||||
@@ -1372,13 +1371,12 @@ func TestPathForModuleSrc(t *testing.T) {
|
|||||||
outs: ["gen/c"],
|
outs: ["gen/c"],
|
||||||
}
|
}
|
||||||
`),
|
`),
|
||||||
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
|
src: "foo/:/other:b",
|
||||||
`"foo": missing dependencies: //other:b, is the property annotated with android:"path"`,
|
rel: ":/other:b",
|
||||||
`"foo": missing dependency on "//other:c", is the property annotated with android:"path"`,
|
srcs: []string{"foo/:/other:c"},
|
||||||
}),
|
rels: []string{":/other:c"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// TODO(b/193228441): Fix broken test.
|
|
||||||
name: "output file provider, missing fully qualified name",
|
name: "output file provider, missing fully qualified name",
|
||||||
bp: `
|
bp: `
|
||||||
test {
|
test {
|
||||||
@@ -1386,13 +1384,9 @@ func TestPathForModuleSrc(t *testing.T) {
|
|||||||
src: "//other:b",
|
src: "//other:b",
|
||||||
srcs: ["//other:c"],
|
srcs: ["//other:c"],
|
||||||
}`,
|
}`,
|
||||||
src: "foo",
|
|
||||||
rel: "foo",
|
|
||||||
srcs: []string{"foo"},
|
|
||||||
rels: []string{"foo"},
|
|
||||||
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
|
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
|
||||||
`"foo": Path is outside directory: /other:b`,
|
`"foo" depends on undefined module "//other:b"`,
|
||||||
`"foo": Path is outside directory: /other:c`,
|
`"foo" depends on undefined module "//other:c"`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1417,13 +1411,9 @@ func TestPathForModuleSrc(t *testing.T) {
|
|||||||
outs: ["gen/c"],
|
outs: ["gen/c"],
|
||||||
}
|
}
|
||||||
`),
|
`),
|
||||||
src: "foo",
|
|
||||||
rel: "foo",
|
|
||||||
srcs: []string{"foo"},
|
|
||||||
rels: []string{"foo"},
|
|
||||||
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
|
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
|
||||||
`"foo": Path is outside directory: /other:b`,
|
`"foo": missing dependencies: //other:b, is the property annotated with android:"path"`,
|
||||||
`"foo": Path is outside directory: /other:c`,
|
`"foo": missing dependency on "//other:c", is the property annotated with android:"path"`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user