rust: Add features list to rust_project.json
Bug: 183679729 Test: SOONG_GEN_RUST_PROJECT=1 m nothing Test: manually check v1 feature resolution for libprofcollectd Change-Id: Ib59b63372865f7f4545fe327e92d1642d76ce9c9
This commit is contained in:
@@ -49,7 +49,7 @@ type rustProjectCrate struct {
|
|||||||
RootModule string `json:"root_module"`
|
RootModule string `json:"root_module"`
|
||||||
Edition string `json:"edition,omitempty"`
|
Edition string `json:"edition,omitempty"`
|
||||||
Deps []rustProjectDep `json:"deps"`
|
Deps []rustProjectDep `json:"deps"`
|
||||||
Cfgs []string `json:"cfgs"`
|
Cfg []string `json:"cfg"`
|
||||||
Env map[string]string `json:"env"`
|
Env map[string]string `json:"env"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
|
|||||||
RootModule: rootModule,
|
RootModule: rootModule,
|
||||||
Edition: comp.edition(),
|
Edition: comp.edition(),
|
||||||
Deps: make([]rustProjectDep, 0),
|
Deps: make([]rustProjectDep, 0),
|
||||||
Cfgs: make([]string, 0),
|
Cfg: make([]string, 0),
|
||||||
Env: make(map[string]string),
|
Env: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +238,10 @@ func (singleton *projectGeneratorSingleton) addCrate(ctx android.SingletonContex
|
|||||||
crate.Env["OUT_DIR"] = comp.CargoOutDir().String()
|
crate.Env["OUT_DIR"] = comp.CargoOutDir().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, feature := range comp.Properties.Features {
|
||||||
|
crate.Cfg = append(crate.Cfg, "feature=\""+feature+"\"")
|
||||||
|
}
|
||||||
|
|
||||||
deps := make(map[string]int)
|
deps := make(map[string]int)
|
||||||
singleton.mergeDependencies(ctx, rModule, &crate, deps)
|
singleton.mergeDependencies(ctx, rModule, &crate, deps)
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -115,6 +116,41 @@ func TestProjectJsonDep(t *testing.T) {
|
|||||||
validateJsonCrates(t, jsonContent)
|
validateJsonCrates(t, jsonContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProjectJsonFeature(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
rust_library {
|
||||||
|
name: "liba",
|
||||||
|
srcs: ["a/src/lib.rs"],
|
||||||
|
crate_name: "a",
|
||||||
|
features: ["f1", "f2"]
|
||||||
|
}
|
||||||
|
`
|
||||||
|
jsonContent := testProjectJson(t, bp)
|
||||||
|
crates := validateJsonCrates(t, jsonContent)
|
||||||
|
for _, c := range crates {
|
||||||
|
crate := validateCrate(t, c)
|
||||||
|
cfgs, ok := crate["cfg"].([]interface{})
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Unexpected type for cfgs: %v", crate)
|
||||||
|
}
|
||||||
|
expectedCfgs := []string{"feature=\"f1\"", "feature=\"f2\""}
|
||||||
|
foundCfgs := []string{}
|
||||||
|
for _, cfg := range cfgs {
|
||||||
|
cfg, ok := cfg.(string)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Unexpected type for cfg: %v", cfg)
|
||||||
|
}
|
||||||
|
foundCfgs = append(foundCfgs, cfg)
|
||||||
|
}
|
||||||
|
sort.Strings(foundCfgs)
|
||||||
|
for i, foundCfg := range foundCfgs {
|
||||||
|
if foundCfg != expectedCfgs[i] {
|
||||||
|
t.Errorf("Incorrect features: got %v; want %v", foundCfg, expectedCfgs[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProjectJsonBinary(t *testing.T) {
|
func TestProjectJsonBinary(t *testing.T) {
|
||||||
bp := `
|
bp := `
|
||||||
rust_binary {
|
rust_binary {
|
||||||
|
Reference in New Issue
Block a user