Include proc macro crates in rust-project.json

These crates were skipped before, leaving dependencies missing in
rust-project.json. Include them and mark them as `"is_proc_macro": true`
so that rust-analyzer can process them.

Fixes: 202290038
Test: SOONG_GEN_RUST_PROJECT=1 m nothing
Change-Id: Ia80e6f5e2f56a76608ba057075600e6b4424281b
This commit is contained in:
Seth Moore 2021-10-06 10:45:34 -07:00
parent f79f4c3199
commit af96f99d83
2 changed files with 58 additions and 0 deletions

View file

@ -51,6 +51,7 @@ type rustProjectCrate struct {
Deps []rustProjectDep `json:"deps"` Deps []rustProjectDep `json:"deps"`
Cfg []string `json:"cfg"` Cfg []string `json:"cfg"`
Env map[string]string `json:"env"` Env map[string]string `json:"env"`
ProcMacro bool `json:"is_proc_macro"`
} }
type rustProjectJson struct { type rustProjectJson struct {
@ -208,6 +209,8 @@ func isModuleSupported(ctx android.SingletonContext, module android.Module) (*Mo
comp = c.baseCompiler comp = c.baseCompiler
case *testDecorator: case *testDecorator:
comp = c.binaryDecorator.baseCompiler comp = c.binaryDecorator.baseCompiler
case *procMacroDecorator:
comp = c.baseCompiler
default: default:
return nil, nil, false return nil, nil, false
} }
@ -224,6 +227,8 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
return 0, false return 0, false
} }
_, procMacro := rModule.compiler.(*procMacroDecorator)
crate := rustProjectCrate{ crate := rustProjectCrate{
DisplayName: rModule.Name(), DisplayName: rModule.Name(),
RootModule: rootModule, RootModule: rootModule,
@ -231,6 +236,7 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
Deps: make([]rustProjectDep, 0), Deps: make([]rustProjectDep, 0),
Cfg: make([]string, 0), Cfg: make([]string, 0),
Env: make(map[string]string), Env: make(map[string]string),
ProcMacro: procMacro,
} }
if comp.CargoOutDir().Valid() { if comp.CargoOutDir().Valid() {

View file

@ -117,6 +117,58 @@ func TestProjectJsonDep(t *testing.T) {
validateJsonCrates(t, jsonContent) validateJsonCrates(t, jsonContent)
} }
func TestProjectJsonProcMacroDep(t *testing.T) {
bp := `
rust_proc_macro {
name: "libproc_macro",
srcs: ["a/src/lib.rs"],
crate_name: "proc_macro"
}
rust_library {
name: "librust",
srcs: ["b/src/lib.rs"],
crate_name: "rust",
proc_macros: ["libproc_macro"],
}
`
jsonContent := testProjectJson(t, bp)
crates := validateJsonCrates(t, jsonContent)
libproc_macro_count := 0
librust_count := 0
for _, c := range crates {
crate := validateCrate(t, c)
procMacro, ok := crate["is_proc_macro"].(bool)
if !ok {
t.Fatalf("Unexpected type for is_proc_macro: %v", crate["is_proc_macro"])
}
name, ok := crate["display_name"].(string)
if !ok {
t.Fatalf("Unexpected type for display_name: %v", crate["display_name"])
}
switch name {
case "libproc_macro":
libproc_macro_count += 1
if !procMacro {
t.Fatalf("'libproc_macro' is marked with is_proc_macro=false")
}
case "librust":
librust_count += 1
if procMacro {
t.Fatalf("'librust' is not a proc macro crate, but is marked with is_proc_macro=true")
}
default:
break
}
}
if libproc_macro_count != 1 || librust_count != 1 {
t.Fatalf("Unexpected crate counts: libproc_macro_count: %v, librust_count: %v",
libproc_macro_count, librust_count)
}
}
func TestProjectJsonFeature(t *testing.T) { func TestProjectJsonFeature(t *testing.T) {
bp := ` bp := `
rust_library { rust_library {