2

Say I've got a file structure like so:

/top_lib
    Android.mk
    /sub_lib1
        Android.mk
        __init__.py
        cheese_maker.py
/middle_lib/
    Android.mk
    /sub_lib2
        Android.mk
        __init__.py
        bread_baker.py
/another_lib
    Android.mk
    /sub_lib3
        Android.mk
        __init__.py
        leaf_raker.py

And have defined a make function within top_lib/Android.mk and another_lib/Android/mk and middle_lib/Android.mk

define add-file
    include $$(PROJECT_DEFAULTS)
    LOCAL_MODULE := $(1)
    LOCAL_MODULE_TAGS := job_stuff
    LOCAL_MODULE_CLASS := ETC
    LOCAL_MODULE_PATH := $(DESTINATION_DIR)/job_stuff/$(strip $(2))
    LOCAL_SRC_FILES := $(1)
    include $$(PROJECT_PREBUILT)
endef

define add-files-to-job
    $(foreach f,$(2),$(eval $(call add-file,$f,$(1))))
endef

include $(call all-subdir-makefiles)

Within each sub_lib/Android.mk I have the following:

LOCAL_PATH := $(call my-dir)
FileList  := $(notdir $(wildcard $(LOCAL_PATH)/*.py))
DirName := $(notdir $(LOCAL_PATH:%/=%))

$(call add-files-to-job, $(DirName), $(FileList))

Within another_lib, if I do mm, it all works nicely. Or even within middle_lib or top_lib. But if I'm at the top of the tree, and say run m job_stuff, eventually I hit an error:

build/core/base_rules.mk:147 ** path/to/middle_lib: MODULE.TARGET.ETC.__init__.py already defined by path/to/top_lib Stop.

I think I understand what's happening. It's staging the files in MODULE.TARGET.ETC, and having files with the same name throws the error. But what I have no idea about is how to fix it. I tried changing LOCAL_MODULE := $(1) to LOCAL_MODULE := $(2).$(1) and that made the folder name show up before each file name (ex: sub_lib1.cheese_maker.py), which is I suppose what I told it to do.

I know if I change the LOCAL_MODULE_CLASS := ETC to anything else, like LOCAL_MODULE_CLASS := ETCA in one of the Android.mk files, it'll work for that file. But I can't seem to find much documentation on LOCAL_MODULE_CLASS and how to utilize it, and since the build system is pretty complex, I'm not sure the repercussions of creating new classes all over the place.

I also tried changing the file adding from add-file to be more along the lines of

LOCAL_PATH := $(call my-dir)
FileList  := $(notdir $(wildcard $(LOCAL_PATH)/*.py))
DirName := $(notdir $(LOCAL_PATH:%/=%))

include $$(PROJECT_DEFAULTS)
LOCAL_MODULE := $(DirName)
LOCAL_MODULE_TAGS := job_stuff
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(DESTINATION_DIR)/job_stuff/$(DirName)
LOCAL_SRC_FILES := $(FileList)
include $$(PROJECT_PREBUILT)

And that said it did stuff when I ran mm, but at top of tree m job_stuff did nothing (well, it built a lot of stuff but $(DESTINATION_DIR) was empty)

So I'm stuck. How do I get around having more than one init.py file within different libraries?

polkid
  • 313
  • 4
  • 15

0 Answers0