Lines Matching refs:namespace
42 items []*Namespace
46 func (s *sortedNamespaces) add(namespace *Namespace) {
52 s.items = append(s.items, namespace)
55 func (s *sortedNamespaces) sortedItems() []*Namespace {
68 func (s *sortedNamespaces) index(namespace *Namespace) int {
70 if namespace == candidate {
81 rootNamespace *Namespace
89 // Map from dir to namespace. Will have duplicates if two dirs are part of the same namespace.
90 namespacesByDir sync.Map // if generics were supported, this would be sync.Map[string]*Namespace
92 // func telling whether to export a namespace to Kati
93 namespaceExportFilter func(*Namespace) bool
96 func NewNameResolver(namespaceExportFilter func(*Namespace) bool) *NameResolver {
104 r.rootNamespace.visibleNamespaces = []*Namespace{r.rootNamespace}
110 func (r *NameResolver) newNamespace(path string) *Namespace {
111 namespace := NewNamespace(path)
113 namespace.exportToKati = r.namespaceExportFilter(namespace)
115 return namespace
121 return errors.New("A namespace may only be declared in a file named Android.bp")
125 namespace := r.newNamespace(dir)
126 module.namespace = namespace
128 namespace.importedNamespaceNames = module.properties.Imports
129 return r.addNamespace(namespace)
132 func (r *NameResolver) addNamespace(namespace *Namespace) (err error) {
133 existingNamespace, exists := r.namespaceAt(namespace.Path)
135 if existingNamespace.Path == namespace.Path {
136 return fmt.Errorf("namespace %v already exists", namespace.Path)
140 return fmt.Errorf("a namespace must be the first module in the file")
143 r.sortedNamespaces.add(namespace)
145 r.namespacesByDir.Store(namespace.Path, namespace)
149 // non-recursive check for namespace
150 func (r *NameResolver) namespaceAt(path string) (namespace *Namespace, found bool) {
155 return mapVal.(*Namespace), true
158 // recursive search upward for a namespace
159 func (r *NameResolver) findNamespace(path string) (namespace *Namespace) {
160 namespace, found := r.namespaceAt(path)
162 return namespace
168 namespace = r.findNamespace(parentDir)
169 r.namespacesByDir.Store(path, namespace)
170 return namespace
173 func (r *NameResolver) NewModule(ctx blueprint.NamespaceContext, moduleGroup blueprint.ModuleGroup, module blueprint.Module) (namespace blueprint.Namespace, errs []error) {
174 // if this module is a namespace, then save it to our list of namespaces
184 // if this module is not a namespace, then save it into the appropriate namespace
194 // inform the module whether its namespace is one that we want to export to Make
204 for _, namespace := range r.sortedNamespaces.sortedItems() {
205 newModules := namespace.moduleContainer.AllModules()
217 // parses a fully-qualified path (like "//namespace_path:module_name") into a namespace name and a
232 func (r *NameResolver) getNamespacesToSearchForModule(sourceNamespace *Namespace) (searchOrder []*Namespace) {
236 func (r *NameResolver) ModuleFromName(name string, namespace blueprint.Namespace) (group blueprint.ModuleGroup, found bool) {
240 namespace, found := r.namespaceAt(nsName)
244 container := namespace.moduleContainer
247 for _, candidate := range r.getNamespacesToSearchForModule(namespace.(*Namespace)) {
257 func (r *NameResolver) Rename(oldName string, newName string, namespace blueprint.Namespace) []error {
258 return namespace.(*Namespace).moduleContainer.Rename(oldName, newName, namespace)
261 // resolve each element of namespace.importedNamespaceNames and put the result in namespace.visibleNamespaces
262 func (r *NameResolver) FindNamespaceImports(namespace *Namespace) (err error) {
263 namespace.visibleNamespaces = make([]*Namespace, 0, 2+len(namespace.importedNamespaceNames))
265 namespace.visibleNamespaces = append(namespace.visibleNamespaces, namespace)
267 for _, name := range namespace.importedNamespaceNames {
270 return fmt.Errorf("namespace %v does not exist", name)
272 namespace.visibleNamespaces = append(namespace.visibleNamespaces, imp)
274 // search the root namespace last
275 namespace.visibleNamespaces = append(namespace.visibleNamespaces, r.rootNamespace)
279 func (r *NameResolver) chooseId(namespace *Namespace) {
280 id := r.sortedNamespaces.index(namespace)
282 panic(fmt.Sprintf("Namespace not found: %v\n", namespace.id))
284 namespace.id = strconv.Itoa(id)
287 func (r *NameResolver) MissingDependencyError(depender string, dependerNamespace blueprint.Namespace, depName string) (err error) {
299 for _, namespace := range r.sortedNamespaces.sortedItems() {
300 _, found := namespace.moduleContainer.ModuleFromName(depName, nil)
302 foundInNamespaces = append(foundInNamespaces, namespace.Path)
307 dependerNs := dependerNamespace.(*Namespace)
313 text += fmt.Sprintf("\nModule %q is defined in namespace %q which can read these %v namespaces: %q", depender, dependerNs.Path, len(importedNames), importedNames)
320 func (r *NameResolver) GetNamespace(ctx blueprint.NamespaceContext) blueprint.Namespace {
324 func (r *NameResolver) findNamespaceFromCtx(ctx blueprint.NamespaceContext) *Namespace {
338 type Namespace struct {
342 // names of namespaces listed as imports by this namespace
344 // all namespaces that should be searched when a module in this namespace declares a dependency
345 visibleNamespaces []*Namespace
354 func NewNamespace(path string) *Namespace {
355 return &Namespace{Path: path, moduleContainer: blueprint.NewSimpleNameInterface()}
358 var _ blueprint.Namespace = (*Namespace)(nil)
363 namespace *Namespace
401 err := module.resolver.FindNamespaceImports(module.namespace)
406 module.resolver.chooseId(module.namespace)