Skip to contentSkip to conversation

initial idea for hooks needed for source tracing

DISCUSSION Alberto Pianon 3 participants 21 messages Sep 12, 2023 – Sep 27, 2023

lore
Share & tools
lore
#0 lore raw

Hi Richard,

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

When you find some time, could you please have a look and tell me if this may be the right direction?

Thanks!

Cheers

Alberto

#1 lore raw
Quoted 12 lines · Alberto Pianon

Hi Richard,

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

Quoted 7 lines

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

When you find some time, could you please have a look and tell me if this may be the right direction?

I think this is much better; there's still a few rough edges (function.__name__ == "unpack_submodules" is kinda gross :), but this is much simpler and I think easier to understand. Also, I feel like this is actually reasonably testable; presumably there would be some mechanism to "plug" a different Trace class in instead of the pre-canned one, and tests could be written that use a special test implementation of that class to verify that it is being called correctly. This also means your special source tracing classes can live elsewhere instead of needing to be integrated into bitbake immediately

My thoughts at least.

Quoted 7 lines

Thanks!

Cheers

Alberto

#2 lore raw
Quoted 18 lines · Joshua Watt
Quoted 17 lines · Alberto Pianon

Hi Richard,

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

Quoted 5 lines
Quoted 2 lines

When you find some time, could you please have a look and tell me if this may be the right direction?

I think this is much better; there's still a few rough edges (function.__name__ == "unpack_submodules" is kinda gross :),

I know :) but I couldn't figure out something better off the top of my head...

The thing is that "function" is passed to process_submodules:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n43

and it's executed for each submodule:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n152

I want to collect some metadata only when that "function" is "unpack_submodules" and not some other function.

May you suggest a better way to do it? Maybe with inspect?

Quoted 1 line

but this is much simpler and I think easier to understand.

Thanks!

Quoted 8 lines

Also, I feel
like this is actually reasonably testable; presumably there would be some mechanism to "plug" a different Trace class in instead of the pre-canned one, and tests could be written that use a special test implementation of that class to verify that it is being called correctly. This also means your special source tracing classes can live elsewhere instead of needing to be integrated into bitbake immediately

Yes, that was the idea. Maybe a variable where to store the module to load, like SRCTRACE_PYMODULE = "mybb.fetch2.trace"? And something like SRCTRACE_PYTEST = "mybb.tests.trace" for bitbake-selftest?

#3 lore raw
Quoted 29 lines · Alberto Pianon
Quoted 20 lines · Joshua Watt
Quoted 18 lines · Alberto Pianon

Hi Richard,

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

Quoted 5 lines
Quoted 2 lines

When you find some time, could you please have a look and tell me if this may be the right direction?

I think this is much better; there's still a few rough edges (function.__name__ == "unpack_submodules" is kinda gross :),

Quoted 8 lines

I know :) but I couldn't figure out something better off the top of my head...

The thing is that "function" is passed to process_submodules:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n43

and it's executed for each submodule:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n152

Maybe process_submodules could take an optional argument that indicates if the data should be added?

Quoted 25 lines

I want to collect some metadata only when that "function" is "unpack_submodules" and not some other function.

May you suggest a better way to do it? Maybe with inspect?

Quoted 1 line

but this is much simpler and I think easier to understand.

Thanks!

Quoted 8 lines

Also, I feel
like this is actually reasonably testable; presumably there would be some mechanism to "plug" a different Trace class in instead of the pre-canned one, and tests could be written that use a special test implementation of that class to verify that it is being called correctly. This also means your special source tracing classes can live elsewhere instead of needing to be integrated into bitbake immediately

Yes, that was the idea. Maybe a variable where to store the module to load, like SRCTRACE_PYMODULE = "mybb.fetch2.trace"?
And something like SRCTRACE_PYTEST = "mybb.tests.trace" for bitbake-selftest?

#4 lore raw
Quoted 10 lines · Joshua Watt
Quoted 9 lines · Alberto Pianon
Quoted 2 lines · Joshua Watt

I think this is much better; there's still a few rough edges (function.__name__ == "unpack_submodules" is kinda gross :),

I know :) but I couldn't figure out something better off the top of my head...

Quoted 9 lines
Quoted 5 lines

The thing is that "function" is passed to process_submodules:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n43

and it's executed for each submodule:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n152

Maybe process_submodules could take an optional argument that indicates if the data should be added?

Yes :)
Like this? http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4

#5 lore raw
In reply to Alberto Pianon
Quoted 57 lines · Alberto Pianon
Quoted 20 lines · Joshua Watt
Quoted 18 lines · Alberto Pianon

Hi Richard,

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

Quoted 5 lines
Quoted 2 lines

When you find some time, could you please have a look and tell me if this may be the right direction?

I think this is much better; there's still a few rough edges (function.__name__ == "unpack_submodules" is kinda gross :),

I know :) but I couldn't figure out something better off the top of my head...

The thing is that "function" is passed to process_submodules:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n43

and it's executed for each submodule:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n152

I want to collect some metadata only when that "function" is "unpack_submodules" and not some other function.

May you suggest a better way to do it? Maybe with inspect?

Quoted 1 line

but this is much simpler and I think easier to understand.

Thanks!

Quoted 8 lines

Also, I feel
like this is actually reasonably testable; presumably there would be some mechanism to "plug" a different Trace class in instead of the pre-canned one, and tests could be written that use a special test implementation of that class to verify that it is being called correctly. This also means your special source tracing classes can live elsewhere instead of needing to be integrated into bitbake immediately

Quoted 4 lines

Yes, that was the idea. Maybe a variable where to store the module to load, like SRCTRACE_PYMODULE = "mybb.fetch2.trace"?
And something like SRCTRACE_PYTEST = "mybb.tests.trace" for bitbake-selftest?

Ya (assuming you meant SRCTRACE_PYMODULE in both places). You might even be able to combine the ENABLE and PYMODULE (or maybe CLASS?) into the same function. If the variable is empty do nothing, otherwise load the class. I'm pretty sure we've done that elsewhere in the codebase.... see siggen.py in bitbake where it loads a module using import_module. IDK if you'll run into trouble with the import path doing that or not.

Quoted 1 line
#6 lore raw
Signature · 7 lines
-- 
Avv. Alberto Pianon
Contrà Pedemuro San Biagio 45
36100 Vicenza (Italy)
Tel +39 0444 1836651
Fax +39 0444 546505
[email protected]
Quoted 63 lines · Joshua Watt
Quoted 57 lines · Alberto Pianon
Quoted 20 lines · Joshua Watt
Quoted 18 lines · Alberto Pianon

Hi Richard,

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

Quoted 5 lines
Quoted 2 lines

When you find some time, could you please have a look and tell me if this may be the right direction?

I think this is much better; there's still a few rough edges (function.__name__ == "unpack_submodules" is kinda gross :),

I know :) but I couldn't figure out something better off the top of my head...

The thing is that "function" is passed to process_submodules:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n43

and it's executed for each submodule:
http://cgit.openembedded.org/bitbake-contrib/tree/lib/bb/fetch2/gitsm.py?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8#n152

I want to collect some metadata only when that "function" is "unpack_submodules" and not some other function.

May you suggest a better way to do it? Maybe with inspect?

Quoted 1 line

but this is much simpler and I think easier to understand.

Thanks!

Quoted 8 lines

Also, I feel
like this is actually reasonably testable; presumably there would be some mechanism to "plug" a different Trace class in instead of the pre-canned one, and tests could be written that use a special test implementation of that class to verify that it is being called correctly. This also means your special source tracing classes can live elsewhere instead of needing to be integrated into bitbake immediately

Quoted 4 lines

Yes, that was the idea. Maybe a variable where to store the module to load, like SRCTRACE_PYMODULE = "mybb.fetch2.trace"?
And something like SRCTRACE_PYTEST = "mybb.tests.trace" for bitbake-selftest?

Quoted 8 lines

Ya (assuming you meant SRCTRACE_PYMODULE in both places). You might even be able to combine the ENABLE and PYMODULE (or maybe CLASS?) into the same function. If the variable is empty do nothing, otherwise load the class. I'm pretty sure we've done that elsewhere in the codebase.... see siggen.py in bitbake where it loads a module using import_module. IDK if you'll run into trouble with the import path doing that or not.

Do you mean something like SRCTRACE_PYCLASS = "mybb.trace.TraceUnpack" ?

And IIUC the test module should be a separately set anyway, like in SRCTRACE_PYTESTMODULE = "mybb.tests.trace_unpack"... or am I missing something?

In any case I've seen the example in siggen.py and I will try to use it, thanks

#7 lore raw
In reply to Alberto Pianon
Quoted 9 lines · Alberto Pianon

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

Quoted 7 lines

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

When you find some time, could you please have a look and tell me if this may be the right direction?

I think what we should do for now is something like the code below, basically to instrument the unpack process but not change it's code.

This leaves all the "messy" state engine pieces you need to your own backend where you can develop them as needed.

Obviously you'd need to implement something to swap unpack_tracer to your own module but that shouldn't be too difficult to do. I don't really like globals but for this particular situation, it is probably inevitable. I am limiting the use of the global to __init__.py deliberately.

I only converted crate.py as an example but I think this approach should work for the other modules too.

Some general thoughts on various things:

* destdir is a problematic name to have in the urldata object as it is easily confused with a concept used in do_install tasks. "unpackdir" would have been more accurate and less confusing. Obviously it could easily be renamed in your patches and it is following naming within the fetchers but I think it is better to use a clearer name. Something to keep in mind in the tracing code in general.

* I don't like the parameters that were being added to unpack() (checkout_destdir and is_module) as their meaning is unclear and appear fetcher module specific. The intention of a generic "tracer" module pointer is clear.

* As we discussed, the unpack to a temp location and move into position seemed like a good idea but the implementation is too complex unfortunately. Sorry to point in the wrong direction on that one.

* Adding any kind of unpackdir derived directory to urldata in general seems like it is a bad idea as it is only valid for the life of the unpack() call. When I suggested poking into ud, I had something like the patch below in mind where we can use it to help the tracing without adding more parameters, instead using function calls.

* Ultimately we may need to have some basic tracer by default, mainly to get a idea of the end result of the fetching. I remain unconvinced we need to map every file back to a specific entry in SRC_URI though.

* Ideally the "unpack_type" parameter to DummyUnpackTracer might not be needed, or becomes optional.

Cheers,

Richard

bitbake/lib/bb/fetch2/__init__.py +28 -0
index 0ead303ca16..2b8de4da10b 100644
@@ -139,6 +139,25 @@ class MissingChecksumEvent(bb.event.Event):
         self.checksums = checksums
         bb.event.Event.__init__(self)
 
+class DummyUnpackTracer(object):
+
+    def start(self, unpackdir, urldata, d):
+        return
+
+    def start_url(self, url):
+        return
+
+    def unpack(self, unpack_type, destdir):
+        return
+
+    def finish_url(self, url):
+        return
+
+    def complete(self):
+        return
+
+unpack_tracer = DummyUnpackTracer()
+
 
 class URI(object):
     """
@@ -1591,6 +1610,8 @@ class FetchMethod(object):
                     if urlpath.find("/") != -1:
                         destdir = urlpath.rsplit("/", 1)[0] + '/'
                         bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir))
+
+                ud.unpack_tracer.unpack("extract", destdir)
                 cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 
         if not cmd:
@@ -1707,6 +1728,7 @@ class Fetch(object):
             if url not in self.ud:
                 try:
                     self.ud[url] = FetchData(url, d, localonly)
+                    self.ud.unpack_tracer = unpack_tracer
                 except NonLocalMethod:
                     if localonly:
                         self.ud[url] = None
@@ -1882,6 +1904,8 @@ class Fetch(object):
         if not urls:
             urls = self.urls
 
+        unpack_tracer.start(root, self.ud, self.d)
+
         for u in urls:
             ud = self.ud[u]
             ud.setup_localpath(self.d)
@@ -1889,11 +1913,15 @@ class Fetch(object):
             if ud.lockfile:
                 lf = bb.utils.lockfile(ud.lockfile)
 
+            ud.unpack_tracer.start_url(u)
             ud.method.unpack(ud, root, self.d)
+            ud.unpack_tracer.finish_url(u)
 
             if ud.lockfile:
                 bb.utils.unlockfile(lf)
 
+        unpack_tracer.complete()
+
     def clean(self, urls=None):
         """
         Clean files that the fetcher gets or places
bitbake/lib/bb/fetch2/crate.py +2 -0
index 3310ed00506..7eb89d28429 100644
@@ -100,10 +100,12 @@ class Crate(Wget):
 
         bp = d.getVar('BP')
         if bp == ud.parm.get('name'):
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
             cmd = "tar -xz --no-same-owner -f %s" % thefile
         else:
             cargo_bitbake = self._cargo_bitbake_path(rootdir)
 
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
             cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, cargo_bitbake)
 
             # ensure we've got these paths made
#8 lore raw
Quoted 15 lines · Richard Purdie
Quoted 14 lines · Alberto Pianon

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

Quoted 6 lines
Quoted 2 lines

When you find some time, could you please have a look and tell me if this may be the right direction?

I think what we should do for now is something like the code below, basically to instrument the unpack process but not change it's code.

I thought I had to avoid putting unpack tracing methods in individual fetchers so I moved them in the core unpack method, but of course it would be much better to put them into fetchers' code in the "right" place (i.e. where the unpack actually happens). That would simplify the logic needed on the backend side, too.

I had tried a similar solution at the beginning; your proposal is much cleaner though, I'll try to follow it and come back to you.

Quoted 4 lines

This leaves all the "messy" state engine pieces you need to your own backend where you can develop them as needed.

Quoted 8 lines

Obviously you'd need to implement something to swap unpack_tracer to your own module but that shouldn't be too difficult to do. I don't really like globals but for this particular situation, it is probably inevitable. I am limiting the use of the global to __init__.py deliberately.

I only converted crate.py as an example but I think this approach should work for the other modules too.

gitsm and npmsw are the tricky ones, so let's start with them :) I will try to implement the same approach there and then ask you to quickly review it, but I have some questions, see inline in your patch below

Quoted 9 lines

Some general thoughts on various things:

* destdir is a problematic name to have in the urldata object as it is easily confused with a concept used in do_install tasks. "unpackdir" would have been more accurate and less confusing. Obviously it could easily be renamed in your patches and it is following naming within the fetchers but I think it is better to use a clearer name. Something to keep in mind in the tracing code in general.

I reckon I chose destdir just because it was already used in git and gitsm fectchers, so I added it also to the other fetchers, but actually it may be confusing, so I will switch to "unpackdir", which is straightforward

Quoted 9 lines

* I don't like the parameters that were being added to unpack() (checkout_destdir and is_module) as their meaning is unclear and appear fetcher module specific. The intention of a generic "tracer" module pointer is clear.

* As we discussed, the unpack to a temp location and move into position seemed like a good idea but the implementation is too complex unfortunately. Sorry to point in the wrong direction on that one.

If we didn't try it, we would never know :)

Quoted 7 lines

* Adding any kind of unpackdir derived directory to urldata in general seems like it is a bad idea as it is only valid for the life of the unpack() call. When I suggested poking into ud, I had something like the patch below in mind where we can use it to help the tracing without adding more parameters, instead using function calls.

OK, I just have one doubt about how to handle that in gitsm and npmsw, that internallly create new Fetch and FetchData (urldata) instances to recursively call the core unpack method. See inline in your patch below

Quoted 54 lines

* Ultimately we may need to have some basic tracer by default, mainly to get a idea of the end result of the fetching. I remain unconvinced we need to map every file back to a specific entry in SRC_URI though.

* Ideally the "unpack_type" parameter to DummyUnpackTracer might not be needed, or becomes optional.

Cheers,

Richard

bitbake/lib/bb/fetch2/__init__.py +21 -0
index 0ead303ca16..2b8de4da10b 100644
@@ -139,6 +139,25 @@ class MissingChecksumEvent(bb.event.Event):
         self.checksums = checksums
         bb.event.Event.__init__(self)
 
+class DummyUnpackTracer(object):
+
+    def start(self, unpackdir, urldata, d):
+        return
+
+    def start_url(self, url):
+        return
+
+    def unpack(self, unpack_type, destdir):
+        return
+
+    def finish_url(self, url):
+        return
+
+    def complete(self):
+        return
+
+unpack_tracer = DummyUnpackTracer()
+
 
 class URI(object):
     """
@@ -1591,6 +1610,8 @@ class FetchMethod(object):
                     if urlpath.find("/") != -1:
                         destdir = urlpath.rsplit("/", 1)[0] + '/'
                         bb.utils.mkdirhier("%s/%s" % (unpackdir, 
 destdir))
+
+                ud.unpack_tracer.unpack("extract", destdir)
                 cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 

if not cmd:

bitbake/lib/bb/fetch2/__init__.py class Fetch(object): · line 1731

Quoted 4 lines
bitbake/lib/bb/fetch2/__init__.py +1 -0
@@ -1707,6 +1728,7 @@ class Fetch(object):
             if url not in self.ud:
                 try:
                     self.ud[url] = FetchData(url, d, localonly)
+                    self.ud.unpack_tracer = unpack_tracer

maybe you mean this? Or am I getting it wrong?

self.ud[url].unpack_tracer = unpack_tracer

In any case, Gitsm and npmsw fetchers create internal Fecth and FetchData (urldata) objects to unpack (sub)modules by recursively calling the core unpack method, so the unpack_tracer object needs to be passed through in some way... Did you already think about a clean way to handle that?

I'm also concerned about npmsw modules, because it may (and it does) happen that the same module, unpacked from the same url, may get unpacked more than once into different locations in the same root dir, because of the way npm works (...). Probably start_url and final_url methods should take also unpackdir as an argument, what do you think?

Quoted 46 lines
bitbake/lib/bb/fetch2/__init__.py +6 -0
                 except NonLocalMethod:
                     if localonly:
                         self.ud[url] = None
@@ -1882,6 +1904,8 @@ class Fetch(object):
         if not urls:
             urls = self.urls
 
+        unpack_tracer.start(root, self.ud, self.d)
+
         for u in urls:
             ud = self.ud[u]
             ud.setup_localpath(self.d)
@@ -1889,11 +1913,15 @@ class Fetch(object):
             if ud.lockfile:
                 lf = bb.utils.lockfile(ud.lockfile)
 
+            ud.unpack_tracer.start_url(u)
             ud.method.unpack(ud, root, self.d)
+            ud.unpack_tracer.finish_url(u)
 
             if ud.lockfile:
                 bb.utils.unlockfile(lf)
 
+        unpack_tracer.complete()
+
     def clean(self, urls=None):
         """
         Clean files that the fetcher gets or places
bitbake/lib/bb/fetch2/crate.py +2 -0
index 3310ed00506..7eb89d28429 100644
@@ -100,10 +100,12 @@ class Crate(Wget):
 
         bp = d.getVar('BP')
         if bp == ud.parm.get('name'):
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
             cmd = "tar -xz --no-same-owner -f %s" % thefile
         else:
             cargo_bitbake = self._cargo_bitbake_path(rootdir)
 
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
             cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, 
 cargo_bitbake)
 
             # ensure we've got these paths made
#9 lore raw
Quoted 24 lines · Alberto Pianon
Quoted 16 lines · Richard Purdie
Quoted 15 lines · Alberto Pianon

as I said at today's meeting there is no hurry, but right after the meeting I had an idea and I wanted to fix it in my mind and test it before losing it :)

It's just a temporary/WIP patch, but it should not be too far from a working implementation of the hooks we were talking about:

http://cgit.openembedded.org/bitbake-contrib/commit/?h=alpianon/srctrace4&id=ecb065e7fe2eece566cd387e24abc3b6079146d8

There is no interference nor modification to the unpack process any more, just collection of needed metadata through the urldata object. Modifications to the core unpack function are minimal and (I hope!) straightforward, and there is no fetcher-specific logic in it ant more.

Quoted 6 lines
Quoted 2 lines

When you find some time, could you please have a look and tell me if this may be the right direction?

I think what we should do for now is something like the code below, basically to instrument the unpack process but not change it's code.

Quoted 5 lines

I thought I had to avoid putting unpack tracing methods in individual fetchers so I moved them in the core unpack method, but of course it would be much better to put them into fetchers' code in the "right" place (i.e. where the unpack actually happens). That would simplify the logic needed on the backend side, too.

I think we can do something as long as they're generic calls to a "proper" tracer API rather than backend specific ones.

Quoted 122 lines

I had tried a similar solution at the beginning; your proposal is much cleaner though, I'll try to follow it and come back to you.

Quoted 4 lines

This leaves all the "messy" state engine pieces you need to your own backend where you can develop them as needed.

Quoted 8 lines

Obviously you'd need to implement something to swap unpack_tracer to your own module but that shouldn't be too difficult to do. I don't really like globals but for this particular situation, it is probably inevitable. I am limiting the use of the global to __init__.py deliberately.

I only converted crate.py as an example but I think this approach should work for the other modules too.

gitsm and npmsw are the tricky ones, so let's start with them :) I will try to implement the same approach there and then ask you to quickly review it, but I have some questions, see inline in your patch below

Quoted 9 lines

Some general thoughts on various things:

* destdir is a problematic name to have in the urldata object as it is easily confused with a concept used in do_install tasks. "unpackdir" would have been more accurate and less confusing. Obviously it could easily be renamed in your patches and it is following naming within the fetchers but I think it is better to use a clearer name. Something to keep in mind in the tracing code in general.

I reckon I chose destdir just because it was already used in git and gitsm fectchers, so I added it also to the other fetchers, but actually it may be confusing, so I will switch to "unpackdir", which is straightforward

Quoted 9 lines

* I don't like the parameters that were being added to unpack() (checkout_destdir and is_module) as their meaning is unclear and appear fetcher module specific. The intention of a generic "tracer" module pointer is clear.

* As we discussed, the unpack to a temp location and move into position seemed like a good idea but the implementation is too complex unfortunately. Sorry to point in the wrong direction on that one.

If we didn't try it, we would never know :)

Quoted 7 lines

* Adding any kind of unpackdir derived directory to urldata in general seems like it is a bad idea as it is only valid for the life of the unpack() call. When I suggested poking into ud, I had something like the patch below in mind where we can use it to help the tracing without adding more parameters, instead using function calls.

OK, I just have one doubt about how to handle that in gitsm and npmsw, that internallly create new Fetch and FetchData (urldata) instances to recursively call the core unpack method. See inline in your patch below

Quoted 55 lines

* Ultimately we may need to have some basic tracer by default, mainly to get a idea of the end result of the fetching. I remain unconvinced we need to map every file back to a specific entry in SRC_URI though.

* Ideally the "unpack_type" parameter to DummyUnpackTracer might not be needed, or becomes optional.

Cheers,

Richard

bitbake/lib/bb/fetch2/__init__.py +21 -0
index 0ead303ca16..2b8de4da10b 100644
@@ -139,6 +139,25 @@ class MissingChecksumEvent(bb.event.Event):
         self.checksums = checksums
         bb.event.Event.__init__(self)
 
+class DummyUnpackTracer(object):
+
+    def start(self, unpackdir, urldata, d):
+        return
+
+    def start_url(self, url):
+        return
+
+    def unpack(self, unpack_type, destdir):
+        return
+
+    def finish_url(self, url):
+        return
+
+    def complete(self):
+        return
+
+unpack_tracer = DummyUnpackTracer()
+
 
 class URI(object):
     """
@@ -1591,6 +1610,8 @@ class FetchMethod(object):
                     if urlpath.find("/") != -1:
                         destdir = urlpath.rsplit("/", 1)[0] + '/'
                         bb.utils.mkdirhier("%s/%s" % (unpackdir, 
 destdir))
+
+                ud.unpack_tracer.unpack("extract", destdir)
                 cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 

if not cmd:

bitbake/lib/bb/fetch2/__init__.py class Fetch(object): · line 1731

Quoted 4 lines
bitbake/lib/bb/fetch2/__init__.py +1 -0
@@ -1707,6 +1728,7 @@ class Fetch(object):
             if url not in self.ud:
                 try:
                     self.ud[url] = FetchData(url, d, localonly)
+                    self.ud.unpack_tracer = unpack_tracer

maybe you mean this? Or am I getting it wrong?

Quoted 1 line

self.ud[url].unpack_tracer = unpack_tracer

I do indeed mean that :)

Quoted 5 lines

In any case, Gitsm and npmsw fetchers create internal Fecth and FetchData (urldata) objects to unpack (sub)modules by recursively calling the core unpack method, so the unpack_tracer object needs to be passed through in some way... Did you already think about a clean way to handle that?

Python passes by reference so they should all see the same unpack_tracer object. This means if you see a new urldata within the tracer code, you know you're now working on a new url.

You will have to have some kind of state inside the tracer to handle it but I think you should be able to make something work?

Quoted 5 lines

I'm also concerned about npmsw modules, because it may (and it does) happen that the same module, unpacked from the same url, may get unpacked more than once into different locations in the same root dir, because of the way npm works (...). Probably start_url and final_url methods should take also unpackdir as an argument, what do you think?

I think if you have the right tracking inside the tracer, you shouldn't need those extra arguments. I'm not 100% sure on that but I'd at least see what is possible first.

Cheers,

Richard

#10 lore raw

Hi Richard,

I started playing a little bit with a possible implementation handling also gitsm and npmsw fetchers, and I came up with the draft below, based on your proposal (the draft does not include the implementation, just the API).

I'm not sure that all arguments are needed, but this is roughly how the API should look alike. Before I go on with the implementation, could you please tell me if this time we are on the right track?

Moreover, do you have any idea on how and where we may dynamically load the user defined class instead of the dummy one, based on some config parameter, like 'TRACER_UNPACKCLASS == "mytrace.unpack.UnpackTracer"?

Thanks

Cheers,

Alberto

lib/bb/fetch2/__init__.py +30 -0
index 765aedd5..a8b44a4f 100644
@@ -140,6 +140,35 @@ class MissingChecksumEvent(bb.event.Event):
         bb.event.Event.__init__(self)
 
 
+class DummyUnpackTracer(object):
+
+    def start(self, unpackdir, ud_dict, d):
+        return
+
+    def start_url(self, url):
+        return
+
+    def unpack(self, unpack_type, destdir, ud=None):
+        return
+
+    def finish_url(self, url):
+        return
+
+    def start_module(self, module_type, unpackdir, ud_dict, parent_ud, d):
+        return
+
+    def module(self, module_type, url, name, path, revision=None):
+        return
+
+    def finish_module(self, module_type, unpackdir, ud_dict, parent_ud, d):
+        return
+
+    def complete(self):
+        return
+
+unpack_tracer = DummyUnpackTracer()
+
+
 class URI(object):
     """
     A class representing a generic URI, with methods for
@@ -1578,6 +1607,7 @@ class FetchMethod(object):
             unpackdir = rootdir
 
         if not unpack or not cmd:
+            urldata.unpack_tracer.unpack("file-copy", unpackdir)
             # If file == dest, then avoid any copies, as we already put 

the file into dest!
dest = os.path.join(unpackdir, os.path.basename(file)) if file != dest and not (os.path.exists(dest) and
os.path.samefile(file, dest)):
@@ -1591,8 +1621,13 @@ class FetchMethod(object):

                     if urlpath.find("/") != -1:
                         destdir = urlpath.rsplit("/", 1)[0] + '/'
                         bb.utils.mkdirhier("%s/%s" % (unpackdir, 
destdir))
+                        urldata.unpack_tracer.unpack(
+                            "file-copy", "%s/%s" % (unpackdir, destdir))
                 cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)

+ else:
+ urldata.unpack_tracer.unpack("archive-extract", unpackdir)
+
if not cmd:
return

@@ -1707,6 +1742,7 @@ class Fetch(object):
if url not in self.ud:
try:
self.ud[url] = FetchData(url, d, localonly)
+ self.ud[url].unpack_tracer = unpack_tracer
except NonLocalMethod:
if localonly:
self.ud[url] = None
@@ -1882,6 +1918,8 @@ class Fetch(object):
if not urls:
urls = self.urls

+ unpack_tracer.start(root, self.ud, self.d)
+
for u in urls:
ud = self.ud[u] ud.setup_localpath(self.d)
@@ -1889,11 +1927,15 @@ class Fetch(object):
if ud.lockfile:
lf = bb.utils.lockfile(ud.lockfile)

+ unpack_tracer.start_url(u)
ud.method.unpack(ud, root, self.d)
+ unpack_tracer.finish_url(u)

if ud.lockfile:
bb.utils.unlockfile(lf)

+ unpack_tracer.complete()
+
def clean(self, urls=None):
"""
Clean files that the fetcher gets or places

lib/bb/fetch2/crate.py +2 -0
index 3310ed00..01d49435 100644
@@ -101,8 +101,10 @@ class Crate(Wget):
         bp = d.getVar('BP')
         if bp == ud.parm.get('name'):
             cmd = "tar -xz --no-same-owner -f %s" % thefile
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
         else:
             cargo_bitbake = self._cargo_bitbake_path(rootdir)
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
 
             cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, 

cargo_bitbake)

lib/bb/fetch2/git.py +1 -0
index 4385d0b3..567943da 100644
@@ -589,6 +589,7 @@ class Git(FetchMethod):
         destdir = ud.destdir = os.path.join(destdir, destsuffix)
         if os.path.exists(destdir):
             bb.utils.prunedir(destdir)
+        ud.unpack_tracer.unpack("git", destdir, ud)
 
         need_lfs = self._need_lfs(ud)
 
lib/bb/fetch2/gitsm.py +1 -0
index a87361cc..06dda48b 100644
@@ -218,7 +218,9 @@ class GitSM(Git):
 
             try:
                 newfetch = Fetch([url], d, cache=False)
+                ud.unpack_tracer.start_module("git", repo_conf, newfetch.ud, ud, d)
                 

newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 'modules', module)))
+ ud.unpack_tracer.finish_module("git", repo_conf, newfetch.ud, ud, d)
except Exception as e:
logger.error('gitsm: submodule unpack failed: %s %s' %
(type(e).__name__, str(e)))
raise
@@ -238,6 +240,8 @@ class GitSM(Git):
logger.error("Unable to set git config core.bare to
false for %s" % os.path.join(repo_conf, 'modules', module))
raise

+ ud.unpack_tracer.module("git", url, module, modpath, d.getVar("SRCREV_%s" % module))
+
Git.unpack(self, ud, destdir, d)

ret = self.process_submodules(ud, ud.destdir,
unpack_submodules, d)

lib/bb/fetch2/hg.py +1 -0
index 063e1300..cbff8c49 100644
@@ -242,6 +242,7 @@ class Hg(FetchMethod):
         revflag = "-r %s" % ud.revision
         subdir = ud.parm.get("destsuffix", ud.module)
         codir = "%s/%s" % (destdir, subdir)
+        ud.unpack_tracer.unpack("hg", codir)
 
         scmdata = ud.parm.get("scmdata", "")
         if scmdata != "nokeep":
lib/bb/fetch2/npm.py +1 -0
index f83485ad..15f3f19b 100644
@@ -298,6 +298,7 @@ class Npm(FetchMethod):
         destsuffix = ud.parm.get("destsuffix", "npm")
         destdir = os.path.join(rootdir, destsuffix)
         npm_unpack(ud.localpath, destdir, d)
+        ud.unpack_tracer.unpack("npm", destdir)
 
     def clean(self, ud, d):
         """Clean any existing full or partial download"""
lib/bb/fetch2/npmsw.py +0 -0
index 4ff2c8ff..5cab96c4 100644
@@ -192,6 +192,7 @@ class NpmShrinkWrap(FetchMethod):
                 raise ParameterError("Unsupported dependency: %s" % 

name, ud.url)

             ud.deps.append({
+                "name": name,
                 "url": url,
                 "localpath": localpath,
                 "extrapaths": extrapaths,

@@ -270,16 +271,27 @@ class NpmShrinkWrap(FetchMethod):
destsuffix = ud.parm.get("destsuffix") if destsuffix:
destdir = os.path.join(rootdir, destsuffix)
+ ud.unpack_tracer.unpack("npmsw", destdir)

bb.utils.mkdirhier(destdir) bb.utils.copyfile(ud.shrinkwrap_file,
os.path.join(destdir, "npm-shrinkwrap.json"))

+ for dep in ud.deps:
+ ud.unpack_tracer.module(

+                "npm",
+                dep["url"] or dep["localpath"],
+                dep["name"],
+                dep["destsuffix"]

+ )
+
auto = [dep["url"] for dep in ud.deps if not dep["localpath"]] manual = [dep for dep in ud.deps if dep["localpath"]]

if auto:
+ ud.unpack_tracer.start_module("npm", destdir, ud.proxy.ud, ud, d)
ud.proxy.unpack(destdir, auto)
+ ud.unpack_tracer.finish_module("npm", destdir, ud.proxy.ud, ud, d)

for dep in manual:
depdestdir = os.path.join(destdir, dep["destsuffix"])

#11 lore raw

Hi Alberto,

Quoted 4 lines · Alberto Pianon

I started playing a little bit with a possible implementation handling also gitsm and npmsw fetchers, and I came up with the draft below, based on your proposal (the draft does not include the implementation, just the API).

I'll comment below. Your code was line wrapped so it isn't entirely pretty but i've tried to clean it up a bit in my reply to make it readable.

Quoted 3 lines

I'm not sure that all arguments are needed, but this is roughly how the API should look alike. Before I go on with the implementation, could you please tell me if this time we are on the right track?

I would like to reduce some of the arguments being passed around if we can.

Quoted 3 lines

Moreover, do you have any idea on how and where we may dynamically load the user defined class instead of the dummy one, based on some config parameter, like 'TRACER_UNPACKCLASS == "mytrace.unpack.UnpackTracer"?

I don't have anything offhand, I'd have to experiment with some code to come up with something. I can try and find some time to do so but that problem is definitely one we can solve as we do this elsewhere.

Quoted 49 lines
lib/bb/fetch2/__init__.py +30 -0
index 765aedd5..a8b44a4f 100644
@@ -140,6 +140,35 @@ class MissingChecksumEvent(bb.event.Event):
          bb.event.Event.__init__(self)
 
 
+class DummyUnpackTracer(object):
+
+    def start(self, unpackdir, ud_dict, d):
+        return
+
+    def start_url(self, url):
+        return
+
+    def unpack(self, unpack_type, destdir, ud=None):
+        return
+
+    def finish_url(self, url):
+        return
+
+    def start_module(self, module_type, unpackdir, ud_dict, parent_ud, d):
+        return
+
+    def module(self, module_type, url, name, path, revision=None):
+        return
+
+    def finish_module(self, module_type, unpackdir, ud_dict, parent_ud, d):
+        return
+
+    def complete(self):
+        return
+
+unpack_tracer = DummyUnpackTracer()
+
+
  class URI(object):
      """
      A class representing a generic URI, with methods for
@@ -1578,6 +1607,7 @@ class FetchMethod(object):
              unpackdir = rootdir
 
          if not unpack or not cmd:
+            urldata.unpack_tracer.unpack("file-copy", unpackdir)
              # If file == dest, then avoid any copies, as we already put the file into dest!
              dest = os.path.join(unpackdir, os.path.basename(file))
              if file != dest and not (os.path.exists(dest) and os.path.samefile(file, dest)):

lib/bb/fetch2/__init__.py class FetchMethod(object): · line 1625

Quoted 5 lines
lib/bb/fetch2/__init__.py +2 -0
@@ -1591,8 +1621,13 @@ class FetchMethod(object):
                      if urlpath.find("/") != -1:
                          destdir = urlpath.rsplit("/", 1)[0] + '/'
                          bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir))
+                        urldata.unpack_tracer.unpack(
+                            "file-copy", "%s/%s" % (unpackdir, destdir))

I'm not too happy about having two different "file-copy" callbacks with different return values. Either you need the two endpoints or the initial one but do you really need both?

Quoted 74 lines
lib/bb/fetch2/__init__.py +10 -0
                  cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 
+        else:
+            urldata.unpack_tracer.unpack("archive-extract", unpackdir)
+
          if not cmd:
              return
 
@@ -1707,6 +1742,7 @@ class Fetch(object):
              if url not in self.ud:
                  try:
                      self.ud[url] = FetchData(url, d, localonly)
+                    self.ud[url].unpack_tracer = unpack_tracer
                  except NonLocalMethod:
                      if localonly:
                          self.ud[url] = None
@@ -1882,6 +1918,8 @@ class Fetch(object):
          if not urls:
              urls = self.urls
 
+        unpack_tracer.start(root, self.ud, self.d)
+
          for u in urls:
              ud = self.ud[u]
              ud.setup_localpath(self.d)
@@ -1889,11 +1927,15 @@ class Fetch(object):
              if ud.lockfile:
                  lf = bb.utils.lockfile(ud.lockfile)
 
+            unpack_tracer.start_url(u)
              ud.method.unpack(ud, root, self.d)
+            unpack_tracer.finish_url(u)
 
              if ud.lockfile:
                  bb.utils.unlockfile(lf)
 
+        unpack_tracer.complete()
+
      def clean(self, urls=None):
          """
          Clean files that the fetcher gets or places
lib/bb/fetch2/crate.py +2 -0
index 3310ed00..01d49435 100644
@@ -101,8 +101,10 @@ class Crate(Wget):
          bp = d.getVar('BP')
          if bp == ud.parm.get('name'):
              cmd = "tar -xz --no-same-owner -f %s" % thefile
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
          else:
              cargo_bitbake = self._cargo_bitbake_path(rootdir)
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
 
              cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile,
 cargo_bitbake)
lib/bb/fetch2/git.py +1 -0
index 4385d0b3..567943da 100644
@@ -589,6 +589,7 @@ class Git(FetchMethod):
          destdir = ud.destdir = os.path.join(destdir, destsuffix)
          if os.path.exists(destdir):
              bb.utils.prunedir(destdir)
+        ud.unpack_tracer.unpack("git", destdir, ud)
 
          need_lfs = self._need_lfs(ud)
 
lib/bb/fetch2/gitsm.py +0 -0
index a87361cc..06dda48b 100644

lib/bb/fetch2/gitsm.py class GitSM(Git): · line 223

Quoted 6 lines
lib/bb/fetch2/gitsm.py +2 -0
@@ -218,7 +218,9 @@ class GitSM(Git):
 
              try:
                  newfetch = Fetch([url], d, cache=False)
+                ud.unpack_tracer.start_module("git", repo_conf, newfetch.ud, ud, d)
                  newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 'modules', module)))
+                ud.unpack_tracer.finish_module("git", repo_conf, newfetch.ud, ud, d)

I don't understand the need for this piece since you'd get start/finish events from the tracer here for the newfetch object?

lib/bb/fetch2/gitsm.py class GitSM(Git): · line 244

Quoted 9 lines
lib/bb/fetch2/gitsm.py +2 -0
              except Exception as e:
                  logger.error('gitsm: submodule unpack failed: %s %s' % (type(e).__name__, str(e)))
                  raise
@@ -238,6 +240,8 @@ class GitSM(Git):
                  logger.error("Unable to set git config core.bare to false for %s" % os.path.join(repo_conf, 'modules', module))
                  raise
 
+            ud.unpack_tracer.module("git", url, module, modpath, d.getVar("SRCREV_%s" % module))
+

Again, you'd get the git unpack events for this?

Quoted 58 lines
lib/bb/fetch2/gitsm.py +0 -0
          Git.unpack(self, ud, destdir, d)
 
          ret = self.process_submodules(ud, ud.destdir, 

unpack_submodules, d)

lib/bb/fetch2/hg.py +1 -0
index 063e1300..cbff8c49 100644
@@ -242,6 +242,7 @@ class Hg(FetchMethod):
          revflag = "-r %s" % ud.revision
          subdir = ud.parm.get("destsuffix", ud.module)
          codir = "%s/%s" % (destdir, subdir)
+        ud.unpack_tracer.unpack("hg", codir)
 
          scmdata = ud.parm.get("scmdata", "")
          if scmdata != "nokeep":
lib/bb/fetch2/npm.py +1 -0
index f83485ad..15f3f19b 100644
@@ -298,6 +298,7 @@ class Npm(FetchMethod):
          destsuffix = ud.parm.get("destsuffix", "npm")
          destdir = os.path.join(rootdir, destsuffix)
          npm_unpack(ud.localpath, destdir, d)
+        ud.unpack_tracer.unpack("npm", destdir)
 
      def clean(self, ud, d):
          """Clean any existing full or partial download"""
lib/bb/fetch2/npmsw.py +1 -0
index 4ff2c8ff..5cab96c4 100644
@@ -192,6 +192,7 @@ class NpmShrinkWrap(FetchMethod):
                  raise ParameterError("Unsupported dependency: %s" %
 name, ud.url)
 
              ud.deps.append({
+                "name": name,
                  "url": url,
                  "localpath": localpath,

"extrapaths": extrapaths,

lib/bb/fetch2/npmsw.py +8 -0
@@ -270,16 +271,27 @@ class NpmShrinkWrap(FetchMethod):
          destsuffix = ud.parm.get("destsuffix")
          if destsuffix:
              destdir = os.path.join(rootdir, destsuffix)
+        ud.unpack_tracer.unpack("npmsw", destdir)
 
          bb.utils.mkdirhier(destdir)
          bb.utils.copyfile(ud.shrinkwrap_file,
                            os.path.join(destdir, "npm-shrinkwrap.json"))
 
+        for dep in ud.deps:
+            ud.unpack_tracer.module(
+                "npm",
+                dep["url"] or dep["localpath"],
+                dep["name"],
+                dep["destsuffix"]
+            )

lib/bb/fetch2/npmsw.py class NpmShrinkWrap(FetchMethod): · line 296

Quoted 10 lines
lib/bb/fetch2/npmsw.py +3 -0
+
          auto = [dep["url"] for dep in ud.deps if not dep["localpath"]]
          manual = [dep for dep in ud.deps if dep["localpath"]]
 
          if auto:
+            ud.unpack_tracer.start_module("npm", destdir, ud.proxy.ud, 
 ud, d)
              ud.proxy.unpack(destdir, auto)
+            ud.unpack_tracer.finish_module("npm", destdir, ud.proxy.ud, 
 ud, d)

Don't you get the information from the inner fetch so we no longer need this markup here?

Quoted 4 lines
lib/bb/fetch2/npmsw.py +0 -0
          for dep in manual:

depdestdir = os.path.join(destdir, dep["destsuffix"])

It does feel like either you're misunderstanding the intent of why I suggested some of the higher level intercept calls as they should reduce the need for the internal module additions, or I'm missing some key detail of why those outer tracepoints can't handle everything you need :/.

Cheers,

Richard

#12 lore raw

thanks for the instant response!
my comments inline below

Cheers,

Alberto

Quoted 12 lines · Richard Purdie

Hi Alberto,

Quoted 4 lines · Alberto Pianon

I started playing a little bit with a possible implementation handling also gitsm and npmsw fetchers, and I came up with the draft below, based on your proposal (the draft does not include the implementation, just the API).

I'll comment below. Your code was line wrapped so it isn't entirely pretty but i've tried to clean it up a bit in my reply to make it readable.

Quoted 6 lines
Quoted 3 lines

I'm not sure that all arguments are needed, but this is roughly how the API should look alike. Before I go on with the implementation, could you please tell me if this time we are on the right track?

I would like to reduce some of the arguments being passed around if we can.

of course. First I need to have a working PoC of the implementation (even if it will not be included in the patch) to be 100% sure of what is strictly needed and what is not

Quoted 66 lines
Quoted 4 lines

Moreover, do you have any idea on how and where we may dynamically load the user defined class instead of the dummy one, based on some config parameter, like 'TRACER_UNPACKCLASS == "mytrace.unpack.UnpackTracer"?

I don't have anything offhand, I'd have to experiment with some code to come up with something. I can try and find some time to do so but that problem is definitely one we can solve as we do this elsewhere.

Quoted 56 lines
lib/bb/fetch2/__init__.py +15 -0
index 765aedd5..a8b44a4f 100644
@@ -140,6 +140,35 @@ class MissingChecksumEvent(bb.event.Event):
          bb.event.Event.__init__(self)
 
 
+class DummyUnpackTracer(object):
+
+    def start(self, unpackdir, ud_dict, d):
+        return
+
+    def start_url(self, url):
+        return
+
+    def unpack(self, unpack_type, destdir, ud=None):
+        return
+
+    def finish_url(self, url):
+        return
+
+    def start_module(self, module_type, unpackdir, ud_dict, 

parent_ud, d):

lib/bb/fetch2/__init__.py +6 -0
+        return
+
+    def module(self, module_type, url, name, path, revision=None):
+        return
+
+    def finish_module(self, module_type, unpackdir, ud_dict, 

parent_ud, d):

lib/bb/fetch2/__init__.py +9 -0
+        return
+
+    def complete(self):
+        return
+
+unpack_tracer = DummyUnpackTracer()
+
+
  class URI(object):
      """
      A class representing a generic URI, with methods for
@@ -1578,6 +1607,7 @@ class FetchMethod(object):
              unpackdir = rootdir
 
          if not unpack or not cmd:
+            urldata.unpack_tracer.unpack("file-copy", unpackdir)
              # If file == dest, then avoid any copies, as we already 

put the file into dest!
dest = os.path.join(unpackdir, os.path.basename(file)) if file != dest and not (os.path.exists(dest) and
os.path.samefile(file, dest)):

lib/bb/fetch2/__init__.py +0 -0
@@ -1591,8 +1621,13 @@ class FetchMethod(object):
                      if urlpath.find("/") != -1:
                          destdir = urlpath.rsplit("/", 1)[0] + '/'
                          bb.utils.mkdirhier("%s/%s" % (unpackdir, 
Quoted 8 lines

lib/bb/fetch2/__init__.py class FetchMethod(object): · line 1627

Quoted 4 lines
lib/bb/fetch2/__init__.py +2 -0
 destdir))
+                        urldata.unpack_tracer.unpack(
+                            "file-copy", "%s/%s" % (unpackdir, 
 destdir))

I'm not too happy about having two different "file-copy" callbacks with different return values. Either you need the two endpoints or the initial one but do you really need both?

The information that I need here is that a file named, say, 'hello', whose url is 'file://examples/hello' and whose path in the corresponding upstream repo is something like 'meta/foo/examples/hello', gets copied/unpacked into '<workdir>/examples/' ("%s/%s" % (unpackdir, destdir)). I may get rid of the second "file-copy" callback above and reconstruct the same information ex post, but this would require an assumption on how this kind of urls are handled by bitbake. If this won't reasonably change in the future, I can assume it and delete the callback :)

Quoted 82 lines
Quoted 82 lines
lib/bb/fetch2/__init__.py +3 -0
                  cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 
+        else:
+            urldata.unpack_tracer.unpack("archive-extract", 
 unpackdir)
+

if not cmd:
return

lib/bb/fetch2/__init__.py +7 -0
@@ -1707,6 +1742,7 @@ class Fetch(object):
              if url not in self.ud:
                  try:
                      self.ud[url] = FetchData(url, d, localonly)
+                    self.ud[url].unpack_tracer = unpack_tracer
                  except NonLocalMethod:
                      if localonly:
                          self.ud[url] = None
@@ -1882,6 +1918,8 @@ class Fetch(object):
          if not urls:
              urls = self.urls
 
+        unpack_tracer.start(root, self.ud, self.d)
+
          for u in urls:
              ud = self.ud[u]
              ud.setup_localpath(self.d)
@@ -1889,11 +1927,15 @@ class Fetch(object):
              if ud.lockfile:
                  lf = bb.utils.lockfile(ud.lockfile)
 
+            unpack_tracer.start_url(u)
              ud.method.unpack(ud, root, self.d)
+            unpack_tracer.finish_url(u)
 
              if ud.lockfile:
                  bb.utils.unlockfile(lf)
 
+        unpack_tracer.complete()
+
      def clean(self, urls=None):
          """
          Clean files that the fetcher gets or places
lib/bb/fetch2/crate.py +2 -0
index 3310ed00..01d49435 100644
@@ -101,8 +101,10 @@ class Crate(Wget):
          bp = d.getVar('BP')
          if bp == ud.parm.get('name'):
              cmd = "tar -xz --no-same-owner -f %s" % thefile
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
          else:
              cargo_bitbake = self._cargo_bitbake_path(rootdir)
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
 
              cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile,
 cargo_bitbake)
lib/bb/fetch2/git.py +1 -0
index 4385d0b3..567943da 100644
@@ -589,6 +589,7 @@ class Git(FetchMethod):
          destdir = ud.destdir = os.path.join(destdir, destsuffix)
          if os.path.exists(destdir):
              bb.utils.prunedir(destdir)
+        ud.unpack_tracer.unpack("git", destdir, ud)
 
          need_lfs = self._need_lfs(ud)
 
lib/bb/fetch2/gitsm.py +1 -0
index a87361cc..06dda48b 100644
@@ -218,7 +218,9 @@ class GitSM(Git):
 
              try:
                  newfetch = Fetch([url], d, cache=False)
+                ud.unpack_tracer.start_module("git", repo_conf, 
 newfetch.ud, ud, d)
 
Quoted 6 lines

lib/bb/fetch2/gitsm.py class GitSM(Git): · line 226

Quoted 3 lines
lib/bb/fetch2/gitsm.py +1 -0
 newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 'modules', module)))
+                ud.unpack_tracer.finish_module("git", repo_conf, 
 newfetch.ud, ud, d)

I don't understand the need for this piece since you'd get start/finish events from the tracer here for the newfetch object?

start_module is actually like a 'pre-start' method, aimed at telling the "nested" start method that will be invoked inside newfetch.unpack that we are processing a submodule and not the main repo (and also at calculating the checkout dir for nested git submodules, which is not known to gitsm).
The alternative would be to add parameters to the core unpack method, but you don't want that :)
I don't have other ideas, what do you think about it?

As to finish_module. it should aggregate nested submodules data. I'm not sure it's strictly needed, though: I have to develop a working PoC of the implementation to see if data may be aggregated in another place.

Quoted 11 lines
Quoted 11 lines

except Exception as e:
logger.error('gitsm: submodule unpack failed: %s %s'
% (type(e).__name__, str(e)))
raise

lib/bb/fetch2/gitsm.py +0 -0
@@ -238,6 +240,8 @@ class GitSM(Git):
                  logger.error("Unable to set git config core.bare to 
 false for %s" % os.path.join(repo_conf, 'modules', module))
                  raise
 
Quoted 5 lines

lib/bb/fetch2/gitsm.py class GitSM(Git): · line 246

Quoted 3 lines
lib/bb/fetch2/gitsm.py +2 -0
+            ud.unpack_tracer.module("git", url, module, modpath, 
 d.getVar("SRCREV_%s" % module))
+

Again, you'd get the git unpack events for this?

This method passes git submodule's url, name, relative checkout path and revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files again and use git commands to reconstruct the same information?

Quoted 65 lines
Quoted 65 lines
lib/bb/fetch2/gitsm.py +0 -0
          Git.unpack(self, ud, destdir, d)

ret = self.process_submodules(ud, ud.destdir,
unpack_submodules, d)

lib/bb/fetch2/hg.py +1 -0
index 063e1300..cbff8c49 100644
@@ -242,6 +242,7 @@ class Hg(FetchMethod):
          revflag = "-r %s" % ud.revision
          subdir = ud.parm.get("destsuffix", ud.module)
          codir = "%s/%s" % (destdir, subdir)
+        ud.unpack_tracer.unpack("hg", codir)
 
          scmdata = ud.parm.get("scmdata", "")
          if scmdata != "nokeep":
lib/bb/fetch2/npm.py +1 -0
index f83485ad..15f3f19b 100644
@@ -298,6 +298,7 @@ class Npm(FetchMethod):
          destsuffix = ud.parm.get("destsuffix", "npm")
          destdir = os.path.join(rootdir, destsuffix)
          npm_unpack(ud.localpath, destdir, d)
+        ud.unpack_tracer.unpack("npm", destdir)
 
      def clean(self, ud, d):
          """Clean any existing full or partial download"""
lib/bb/fetch2/npmsw.py +1 -0
index 4ff2c8ff..5cab96c4 100644
@@ -192,6 +192,7 @@ class NpmShrinkWrap(FetchMethod):
                  raise ParameterError("Unsupported dependency: %s" %
 name, ud.url)
 
              ud.deps.append({
+                "name": name,
                  "url": url,
                  "localpath": localpath,

"extrapaths": extrapaths,

lib/bb/fetch2/npmsw.py +9 -0
@@ -270,16 +271,27 @@ class NpmShrinkWrap(FetchMethod):
          destsuffix = ud.parm.get("destsuffix")
          if destsuffix:
              destdir = os.path.join(rootdir, destsuffix)
+        ud.unpack_tracer.unpack("npmsw", destdir)
 
          bb.utils.mkdirhier(destdir)
          bb.utils.copyfile(ud.shrinkwrap_file,
                            os.path.join(destdir, 
 "npm-shrinkwrap.json"))
 
+        for dep in ud.deps:
+            ud.unpack_tracer.module(
+                "npm",
+                dep["url"] or dep["localpath"],
+                dep["name"],
+                dep["destsuffix"]
+            )
+
          auto = [dep["url"] for dep in ud.deps if not 

dep["localpath"]]
manual = [dep for dep in ud.deps if dep["localpath"]]

Quoted 11 lines
Quoted 8 lines

if auto:
+ ud.unpack_tracer.start_module("npm", destdir,
ud.proxy.ud,
ud, d)
ud.proxy.unpack(destdir, auto)
+ ud.unpack_tracer.finish_module("npm", destdir,
ud.proxy.ud,
ud, d)

Don't you get the information from the inner fetch so we no longer need this markup here?

How? As in gitsm, 'module' method passes npm module url, name and relative destination path to the tracer. Do you suggest that the tracer should autonomously parse the npm-shrinkwrap.json file again, to get the same information?

'start_module' here is needed for the same reason as in gitsm (avoiding adding and is_module parameter to the core unpack method)

Quoted 11 lines
Quoted 5 lines

for dep in manual:
depdestdir = os.path.join(destdir, dep["destsuffix"])

It does feel like either you're misunderstanding the intent of why I suggested some of the higher level intercept calls as they should reduce the need for the internal module additions, or I'm missing some key detail of why those outer tracepoints can't handle everything you need :/.

I can reduce internal module additions by externally recalculating/re-collecting npm/git module information, even if this will cause the same data/files to be processed twice.
If you tell me, I'll do that :)
Do you have any other solution in mind?

Cheers,

Alberto

#13 lore raw
Quoted 29 lines · Alberto Pianon
Quoted 18 lines · Richard Purdie
Quoted 16 lines · Alberto Pianon

"""
A class representing a generic URI, with methods for

lib/bb/fetch2/__init__.py +1 -0
@@ -1578,6 +1607,7 @@ class FetchMethod(object):
              unpackdir = rootdir
 
          if not unpack or not cmd:
+            urldata.unpack_tracer.unpack("file-copy", unpackdir)
              # If file == dest, then avoid any copies, as we already 

put the file into dest!
dest = os.path.join(unpackdir, os.path.basename(file)) if file != dest and not (os.path.exists(dest) and
os.path.samefile(file, dest)):

(quoted diff) +0 -0
@@ -1591,8 +1621,13 @@ class FetchMethod(object):
                      if urlpath.find("/") != -1:
                          destdir = urlpath.rsplit("/", 1)[0] + '/'
                          bb.utils.mkdirhier("%s/%s" % (unpackdir, 
Quoted 8 lines

Review class FetchMethod(object): · line 1627

Quoted 4 lines
(quoted diff) +2 -0
 destdir))
+                        urldata.unpack_tracer.unpack(
+                            "file-copy", "%s/%s" % (unpackdir, 
 destdir))

I'm not too happy about having two different "file-copy" callbacks with different return values. Either you need the two endpoints or the initial one but do you really need both?

Quoted 9 lines

The information that I need here is that a file named, say, 'hello', whose url is 'file://examples/hello' and whose path in the corresponding upstream repo is something like 'meta/foo/examples/hello', gets copied/unpacked into '<workdir>/examples/' ("%s/%s" % (unpackdir, destdir)). I may get rid of the second "file-copy" callback above and reconstruct the same information ex post, but this would require an assumption on how this kind of urls are handled by bitbake. If this won't reasonably change in the future, I can assume it and delete the callback :)

In that case do you need the first call to make it work? Basically I'm saying I'd like to see one trace call from this per run, not multiple calls which the tracer has to then make guesses about. Having two with the same name therefore concerned me.

Quoted 92 lines
Quoted 84 lines
Quoted 84 lines
(quoted diff) +3 -0
                  cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 
+        else:
+            urldata.unpack_tracer.unpack("archive-extract", 
 unpackdir)
+

if not cmd:
return

(quoted diff) +7 -0
@@ -1707,6 +1742,7 @@ class Fetch(object):
              if url not in self.ud:
                  try:
                      self.ud[url] = FetchData(url, d, localonly)
+                    self.ud[url].unpack_tracer = unpack_tracer
                  except NonLocalMethod:
                      if localonly:
                          self.ud[url] = None
@@ -1882,6 +1918,8 @@ class Fetch(object):
          if not urls:
              urls = self.urls
 
+        unpack_tracer.start(root, self.ud, self.d)
+
          for u in urls:
              ud = self.ud[u]
              ud.setup_localpath(self.d)
@@ -1889,11 +1927,15 @@ class Fetch(object):
              if ud.lockfile:
                  lf = bb.utils.lockfile(ud.lockfile)
 
+            unpack_tracer.start_url(u)
              ud.method.unpack(ud, root, self.d)
+            unpack_tracer.finish_url(u)
 
              if ud.lockfile:
                  bb.utils.unlockfile(lf)
 
+        unpack_tracer.complete()
+
      def clean(self, urls=None):
          """
          Clean files that the fetcher gets or places
lib/bb/fetch2/crate.py +2 -0
index 3310ed00..01d49435 100644
@@ -101,8 +101,10 @@ class Crate(Wget):
          bp = d.getVar('BP')
          if bp == ud.parm.get('name'):
              cmd = "tar -xz --no-same-owner -f %s" % thefile
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
          else:
              cargo_bitbake = self._cargo_bitbake_path(rootdir)
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
 
              cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile,
 cargo_bitbake)
lib/bb/fetch2/git.py +1 -0
index 4385d0b3..567943da 100644
@@ -589,6 +589,7 @@ class Git(FetchMethod):
          destdir = ud.destdir = os.path.join(destdir, destsuffix)
          if os.path.exists(destdir):
              bb.utils.prunedir(destdir)
+        ud.unpack_tracer.unpack("git", destdir, ud)
 
          need_lfs = self._need_lfs(ud)
 
lib/bb/fetch2/gitsm.py +1 -0
index a87361cc..06dda48b 100644
@@ -218,7 +218,9 @@ class GitSM(Git):
 
              try:
                  newfetch = Fetch([url], d, cache=False)
+                ud.unpack_tracer.start_module("git", repo_conf, 
 newfetch.ud, ud, d)
 
Quoted 7 lines
Quoted 4 lines
lib/bb/fetch2/gitsm.py +1 -0
 newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 
 'modules', module)))
+                ud.unpack_tracer.finish_module("git", repo_conf, 

newfetch.ud, ud, d)

I don't understand the need for this piece since you'd get start/finish events from the tracer here for the newfetch object?

Quoted 8 lines

start_module is actually like a 'pre-start' method, aimed at telling the "nested" start method that will be invoked inside newfetch.unpack that we are processing a submodule and not the main repo (and also at calculating the checkout dir for nested git submodules, which is not known to gitsm).
The alternative would be to add parameters to the core unpack method, but you don't want that :)
I don't have other ideas, what do you think about it?

My point is you don't need to do this. The main fetcher has start and end points. If you see a new "start" point and you're already in the middle of a "session", you can know that some fetcher has called a submodule fetch, there is nothing else can have happened. You therefore don't need to markup all the subfetching.

Quoted 4 lines

As to finish_module. it should aggregate nested submodules data. I'm not sure it's strictly needed, though: I have to develop a working PoC of the implementation to see if data may be aggregated in another place.

I think the parent level "finish" pieces mean this isn't necessary here.

Quoted 18 lines
Quoted 12 lines
Quoted 12 lines

except Exception as e:
logger.error('gitsm: submodule unpack failed: %s %s'
% (type(e).__name__, str(e)))
raise

lib/bb/fetch2/gitsm.py +0 -0
@@ -238,6 +240,8 @@ class GitSM(Git):
                  logger.error("Unable to set git config core.bare to 
 false for %s" % os.path.join(repo_conf, 'modules', module))
                  raise
 
Quoted 5 lines

lib/bb/fetch2/gitsm.py class GitSM(Git): · line 246

Quoted 3 lines
lib/bb/fetch2/gitsm.py +2 -0
+            ud.unpack_tracer.module("git", url, module, modpath, 
 d.getVar("SRCREV_%s" % module))
+

Again, you'd get the git unpack events for this?

Quoted 4 lines

This method passes git submodule's url, name, relative checkout path and revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files again and use git commands to reconstruct the same information?

No, you shouldn't need to parse those. Isn't this information included in the ud that is being passed to git unpack in the line immediately below? That will be seen via the git unpack call the tracer will see?

Quoted 78 lines
Quoted 66 lines
Quoted 66 lines
lib/bb/fetch2/gitsm.py +0 -0
          Git.unpack(self, ud, destdir, d)

ret = self.process_submodules(ud, ud.destdir,
unpack_submodules, d)

lib/bb/fetch2/hg.py +1 -0
index 063e1300..cbff8c49 100644
@@ -242,6 +242,7 @@ class Hg(FetchMethod):
          revflag = "-r %s" % ud.revision
          subdir = ud.parm.get("destsuffix", ud.module)
          codir = "%s/%s" % (destdir, subdir)
+        ud.unpack_tracer.unpack("hg", codir)
 
          scmdata = ud.parm.get("scmdata", "")
          if scmdata != "nokeep":
lib/bb/fetch2/npm.py +1 -0
index f83485ad..15f3f19b 100644
@@ -298,6 +298,7 @@ class Npm(FetchMethod):
          destsuffix = ud.parm.get("destsuffix", "npm")
          destdir = os.path.join(rootdir, destsuffix)
          npm_unpack(ud.localpath, destdir, d)
+        ud.unpack_tracer.unpack("npm", destdir)
 
      def clean(self, ud, d):
          """Clean any existing full or partial download"""
lib/bb/fetch2/npmsw.py +1 -0
index 4ff2c8ff..5cab96c4 100644
@@ -192,6 +192,7 @@ class NpmShrinkWrap(FetchMethod):
                  raise ParameterError("Unsupported dependency: %s" %
 name, ud.url)
 
              ud.deps.append({
+                "name": name,
                  "url": url,
                  "localpath": localpath,

"extrapaths": extrapaths,

lib/bb/fetch2/npmsw.py +9 -0
@@ -270,16 +271,27 @@ class NpmShrinkWrap(FetchMethod):
          destsuffix = ud.parm.get("destsuffix")
          if destsuffix:
              destdir = os.path.join(rootdir, destsuffix)
+        ud.unpack_tracer.unpack("npmsw", destdir)
 
          bb.utils.mkdirhier(destdir)
          bb.utils.copyfile(ud.shrinkwrap_file,
                            os.path.join(destdir, 
 "npm-shrinkwrap.json"))
 
+        for dep in ud.deps:
+            ud.unpack_tracer.module(
+                "npm",
+                dep["url"] or dep["localpath"],
+                dep["name"],
+                dep["destsuffix"]
+            )
+
          auto = [dep["url"] for dep in ud.deps if not 

dep["localpath"]]
manual = [dep for dep in ud.deps if dep["localpath"]]

Quoted 11 lines
Quoted 8 lines

if auto:
+ ud.unpack_tracer.start_module("npm", destdir,
ud.proxy.ud,
ud, d)
ud.proxy.unpack(destdir, auto)
+ ud.unpack_tracer.finish_module("npm", destdir,
ud.proxy.ud,
ud, d)

Don't you get the information from the inner fetch so we no longer need this markup here?

Quoted 4 lines

How? As in gitsm, 'module' method passes npm module url, name and relative destination path to the tracer. Do you suggest that the tracer should autonomously parse the npm-shrinkwrap.json file again, to get the same information?

In the gitsm case you will see a call into the tracer from the git unpack method with the information you need. I'd imagine something similar happen here?

Quoted 2 lines

'start_module' here is needed for the same reason as in gitsm (avoiding adding and is_module parameter to the core unpack method)

I'm pretty sure you don't need this in the gitsm case. I don't know enough about the npm fetcher to be 100% sure.

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

for dep in manual:
depdestdir = os.path.join(destdir, dep["destsuffix"])

Quoted 5 lines

It does feel like either you're misunderstanding the intent of why I suggested some of the higher level intercept calls as they should reduce the need for the internal module additions, or I'm missing some key detail of why those outer tracepoints can't handle everything you need :/.

Quoted 6 lines

I can reduce internal module additions by externally recalculating/re-collecting npm/git module information, even if this will
cause the same data/files to be processed twice.
If you tell me, I'll do that :)
Do you have any other solution in mind?

I think you can get the data from the ud that gets passed into the recursive calls. You shouldn't need to parse files, that isn't my intent. I'm not convinced we need the fetcher specific hooks though, probably just some basic state tracing in the tracer.

Cheers,

Richard

#14 lore raw
Quoted 40 lines · Richard Purdie
Quoted 29 lines · Alberto Pianon
Quoted 18 lines · Richard Purdie
Quoted 16 lines · Alberto Pianon

"""
A class representing a generic URI, with methods for

lib/bb/fetch2/__init__.py +1 -0
@@ -1578,6 +1607,7 @@ class FetchMethod(object):
              unpackdir = rootdir
 
          if not unpack or not cmd:
+            urldata.unpack_tracer.unpack("file-copy", unpackdir)
              # If file == dest, then avoid any copies, as we already

put the file into dest!
dest = os.path.join(unpackdir, os.path.basename(file)) if file != dest and not (os.path.exists(dest) and
os.path.samefile(file, dest)):

(quoted diff) +0 -0
@@ -1591,8 +1621,13 @@ class FetchMethod(object):
                      if urlpath.find("/") != -1:
                          destdir = urlpath.rsplit("/", 1)[0] + '/'
                          bb.utils.mkdirhier("%s/%s" % (unpackdir,
Quoted 8 lines

Review class FetchMethod(object): · line 1627

Quoted 4 lines
(quoted diff) +2 -0
 destdir))
+                        urldata.unpack_tracer.unpack(
+                            "file-copy", "%s/%s" % (unpackdir,
 destdir))

I'm not too happy about having two different "file-copy" callbacks with different return values. Either you need the two endpoints or the initial one but do you really need both?

Quoted 9 lines

The information that I need here is that a file named, say, 'hello', whose url is 'file://examples/hello' and whose path in the corresponding upstream repo is something like 'meta/foo/examples/hello', gets copied/unpacked into '<workdir>/examples/' ("%s/%s" % (unpackdir, destdir)). I may get rid of the second "file-copy" callback above and reconstruct the same information ex post, but this would require an assumption on how this kind of urls are handled by bitbake. If this won't reasonably change in the future, I can assume it and delete the callback :)

Quoted 4 lines

In that case do you need the first call to make it work? Basically I'm saying I'd like to see one trace call from this per run, not multiple calls which the tracer has to then make guesses about. Having two with the same name therefore concerned me.

I will try to use only one call. This is not a big issue, though

Quoted 103 lines
Quoted 93 lines
Quoted 85 lines
Quoted 85 lines
(quoted diff) +3 -0
                  cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)
 
+        else:
+            urldata.unpack_tracer.unpack("archive-extract",
 unpackdir)
+

if not cmd:
return

(quoted diff) +7 -0
@@ -1707,6 +1742,7 @@ class Fetch(object):
              if url not in self.ud:
                  try:
                      self.ud[url] = FetchData(url, d, localonly)
+                    self.ud[url].unpack_tracer = unpack_tracer
                  except NonLocalMethod:
                      if localonly:
                          self.ud[url] = None
@@ -1882,6 +1918,8 @@ class Fetch(object):
          if not urls:
              urls = self.urls
 
+        unpack_tracer.start(root, self.ud, self.d)
+
          for u in urls:
              ud = self.ud[u]
              ud.setup_localpath(self.d)
@@ -1889,11 +1927,15 @@ class Fetch(object):
              if ud.lockfile:
                  lf = bb.utils.lockfile(ud.lockfile)
 
+            unpack_tracer.start_url(u)
              ud.method.unpack(ud, root, self.d)
+            unpack_tracer.finish_url(u)
 
              if ud.lockfile:
                  bb.utils.unlockfile(lf)
 
+        unpack_tracer.complete()
+
      def clean(self, urls=None):
          """
          Clean files that the fetcher gets or places
lib/bb/fetch2/crate.py +2 -0
index 3310ed00..01d49435 100644
@@ -101,8 +101,10 @@ class Crate(Wget):
          bp = d.getVar('BP')
          if bp == ud.parm.get('name'):
              cmd = "tar -xz --no-same-owner -f %s" % thefile
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
          else:
              cargo_bitbake = self._cargo_bitbake_path(rootdir)
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
 
              cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile,
 cargo_bitbake)
lib/bb/fetch2/git.py +1 -0
index 4385d0b3..567943da 100644
@@ -589,6 +589,7 @@ class Git(FetchMethod):
          destdir = ud.destdir = os.path.join(destdir, destsuffix)
          if os.path.exists(destdir):
              bb.utils.prunedir(destdir)
+        ud.unpack_tracer.unpack("git", destdir, ud)
 
          need_lfs = self._need_lfs(ud)
 
lib/bb/fetch2/gitsm.py +1 -0
index a87361cc..06dda48b 100644
@@ -218,7 +218,9 @@ class GitSM(Git):
 
              try:
                  newfetch = Fetch([url], d, cache=False)
+                ud.unpack_tracer.start_module("git", repo_conf,
 newfetch.ud, ud, d)
 
Quoted 7 lines
Quoted 4 lines
lib/bb/fetch2/gitsm.py +1 -0
 newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf,
 'modules', module)))
+                ud.unpack_tracer.finish_module("git", repo_conf,

newfetch.ud, ud, d)

I don't understand the need for this piece since you'd get start/finish events from the tracer here for the newfetch object?

Quoted 8 lines

start_module is actually like a 'pre-start' method, aimed at telling the "nested" start method that will be invoked inside newfetch.unpack that we are processing a submodule and not the main repo (and also at calculating the checkout dir for nested git submodules, which is not known to gitsm).
The alternative would be to add parameters to the core unpack method, but you don't want that :)
I don't have other ideas, what do you think about it?

Quoted 5 lines

My point is you don't need to do this. The main fetcher has start and end points. If you see a new "start" point and you're already in the middle of a "session", you can know that some fetcher has called a submodule fetch, there is nothing else can have happened. You therefore don't need to markup all the subfetching.

I sede your point. I will implement that, thanks.

Quoted 8 lines
Quoted 5 lines

As to finish_module. it should aggregate nested submodules data. I'm not sure it's strictly needed, though: I have to develop a working PoC of the implementation to see if data may be aggregated in another place.

I think the parent level "finish" pieces mean this isn't necessary here.

This would be solved by using sessions, actually. I will do that

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 9 lines

except Exception as e:
logger.error('gitsm: submodule unpack failed: %s %s'
% (type(e).__name__, str(e)))
raise

lib/bb/fetch2/gitsm.py class GitSM(Git): · line 246

Quoted 7 lines
lib/bb/fetch2/gitsm.py +2 -0
@@ -238,6 +240,8 @@ class GitSM(Git):
                  logger.error("Unable to set git config core.bare to
 false for %s" % os.path.join(repo_conf, 'modules', module))
                  raise
 
+            ud.unpack_tracer.module("git", url, module, modpath,
 d.getVar("SRCREV_%s" % module))
+

Again, you'd get the git unpack events for this?

Quoted 12 lines
Quoted 4 lines

This method passes git submodule's url, name, relative checkout path and revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files again and use git commands to reconstruct the same information?

No, you shouldn't need to parse those. Isn't this information included in the ud that is being passed to git unpack in the line immediately below? That will be seen via the git unpack call the tracer will see?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
lib/bb/fetch2/gitsm.py +0 -0
          Git.unpack(self, ud, destdir, d)

Partly. The missing piece of information is the checkout path. If you search for 'modpath' in gitsm.py you see that that parameter is passed to multiple functions but never used (apart from module updates) nor stored anywhere (or am I missing something?)

Quoted 110 lines
Quoted 75 lines
Quoted 63 lines
Quoted 63 lines

ret = self.process_submodules(ud, ud.destdir,
unpack_submodules, d)

lib/bb/fetch2/hg.py +1 -0
index 063e1300..cbff8c49 100644
@@ -242,6 +242,7 @@ class Hg(FetchMethod):
          revflag = "-r %s" % ud.revision
          subdir = ud.parm.get("destsuffix", ud.module)
          codir = "%s/%s" % (destdir, subdir)
+        ud.unpack_tracer.unpack("hg", codir)
 
          scmdata = ud.parm.get("scmdata", "")
          if scmdata != "nokeep":
lib/bb/fetch2/npm.py +1 -0
index f83485ad..15f3f19b 100644
@@ -298,6 +298,7 @@ class Npm(FetchMethod):
          destsuffix = ud.parm.get("destsuffix", "npm")
          destdir = os.path.join(rootdir, destsuffix)
          npm_unpack(ud.localpath, destdir, d)
+        ud.unpack_tracer.unpack("npm", destdir)
 
      def clean(self, ud, d):
          """Clean any existing full or partial download"""
lib/bb/fetch2/npmsw.py +1 -0
index 4ff2c8ff..5cab96c4 100644
@@ -192,6 +192,7 @@ class NpmShrinkWrap(FetchMethod):
                  raise ParameterError("Unsupported dependency: %s" %
 name, ud.url)
 
              ud.deps.append({
+                "name": name,
                  "url": url,
                  "localpath": localpath,

"extrapaths": extrapaths,

lib/bb/fetch2/npmsw.py +9 -0
@@ -270,16 +271,27 @@ class NpmShrinkWrap(FetchMethod):
          destsuffix = ud.parm.get("destsuffix")
          if destsuffix:
              destdir = os.path.join(rootdir, destsuffix)
+        ud.unpack_tracer.unpack("npmsw", destdir)
 
          bb.utils.mkdirhier(destdir)
          bb.utils.copyfile(ud.shrinkwrap_file,
                            os.path.join(destdir,
 "npm-shrinkwrap.json"))
 
+        for dep in ud.deps:
+            ud.unpack_tracer.module(
+                "npm",
+                dep["url"] or dep["localpath"],
+                dep["name"],
+                dep["destsuffix"]
+            )
+
          auto = [dep["url"] for dep in ud.deps if not

dep["localpath"]]
manual = [dep for dep in ud.deps if dep["localpath"]]

Quoted 11 lines
Quoted 8 lines

if auto:
+ ud.unpack_tracer.start_module("npm", destdir,
ud.proxy.ud,
ud, d)
ud.proxy.unpack(destdir, auto)
+ ud.unpack_tracer.finish_module("npm", destdir,
ud.proxy.ud,
ud, d)

Don't you get the information from the inner fetch so we no longer need this markup here?

Quoted 4 lines

How? As in gitsm, 'module' method passes npm module url, name and relative destination path to the tracer. Do you suggest that the tracer should autonomously parse the npm-shrinkwrap.json file again, to get the same information?

In the gitsm case you will see a call into the tracer from the git unpack method with the information you need. I'd imagine something similar happen here?

Quoted 2 lines

'start_module' here is needed for the same reason as in gitsm (avoiding adding and is_module parameter to the core unpack method)

I'm pretty sure you don't need this in the gitsm case. I don't know enough about the npm fetcher to be 100% sure.

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

for dep in manual:
depdestdir = os.path.join(destdir, dep["destsuffix"])

Quoted 5 lines

It does feel like either you're misunderstanding the intent of why I suggested some of the higher level intercept calls as they should reduce the need for the internal module additions, or I'm missing some key detail of why those outer tracepoints can't handle everything you need :/.

Quoted 6 lines

I can reduce internal module additions by externally recalculating/re-collecting npm/git module information, even if this will
cause the same data/files to be processed twice.
If you tell me, I'll do that :)
Do you have any other solution in mind?

Quoted 4 lines

I think you can get the data from the ud that gets passed into the recursive calls. You shouldn't need to parse files, that isn't my intent. I'm not convinced we need the fetcher specific hooks though, probably just some basic state tracing in the tracer.

I will try to use sessions for that, and I will tell you the results.

The gitsm checkout dir issue remains, though.

Cheers,

Alberto

Quoted 4 lines

Cheers,

Richard

#15 lore raw
Quoted 17 lines · Alberto Pianon
Quoted 15 lines · Richard Purdie
Quoted 8 lines
Quoted 1 line

Again, you'd get the git unpack events for this?

This method passes git submodule's url, name, relative checkout path and
revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files
again and use git commands to reconstruct the same information?

No, you shouldn't need to parse those. Isn't this information included in the ud that is being passed to git unpack in the line immediately below? That will be seen via the git unpack call the tracer will see?

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Git.unpack(self, ud, destdir, d)

Partly. The missing piece of information is the checkout path. If you search for
'modpath' in gitsm.py you see that that parameter is passed to multiple functions but never used (apart from module updates) nor stored anywhere (or am I missing something?)

"unpack path" is pretty much the thing you're having to instrument the other fetchers for so if that is the only extra information being logged in gitsm, that brings it into line with all the other fetchers and we have a consistent API.

What worried me more was an unbalanced API where some fetchers had to have extra special handling. If the tracer API is consistent with just the unpack/checkout path needing logging/tracing, that is much clearer and consistent and a sign the API is right.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

I can reduce internal module additions by externally recalculating/re-collecting npm/git module information, even if this will
cause the same data/files to be processed twice.
If you tell me, I'll do that :)
Do you have any other solution in mind?

Quoted 8 lines
Quoted 4 lines

I think you can get the data from the ud that gets passed into the recursive calls. You shouldn't need to parse files, that isn't my intent. I'm not convinced we need the fetcher specific hooks though, probably just some basic state tracing in the tracer.

I will try to use sessions for that, and I will tell you the results.

The gitsm checkout dir issue remains, though.

Sounds good, I've commented on that above.

Cheers,

Richard

#16 lore raw
Quoted 31 lines · Richard Purdie
Quoted 17 lines · Alberto Pianon
Quoted 15 lines · Richard Purdie
Quoted 8 lines
Quoted 1 line

Again, you'd get the git unpack events for this?

This method passes git submodule's url, name, relative checkout path and
revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files
again and use git commands to reconstruct the same information?

No, you shouldn't need to parse those. Isn't this information included in the ud that is being passed to git unpack in the line immediately below? That will be seen via the git unpack call the tracer will see?

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Git.unpack(self, ud, destdir, d)

Partly. The missing piece of information is the checkout path. If you search for
'modpath' in gitsm.py you see that that parameter is passed to multiple functions but never used (apart from module updates) nor stored anywhere (or am I missing something?)

"unpack path" is pretty much the thing you're having to instrument the other fetchers for so if that is the only extra information being logged in gitsm, that brings it into line with all the other fetchers and we have a consistent API.

Quoted 4 lines

What worried me more was an unbalanced API where some fetchers had to have extra special handling. If the tracer API is consistent with just the unpack/checkout path needing logging/tracing, that is much clearer and consistent and a sign the API is right.

Unpack path of git submodules (including nested ones) - stored in ud.destdir -corresponds to their bareclone path (like in <workdir>/git/.git/modules/<parent-module-name>/<module-name>) and not to the checkout path, which is not even calculated by gitsm. The bareclone path is of no use for the tracer, and in any case it's not consistent with what other fetchers return as unpack dir to the tracer (which should be the folder with where unpacked files are found).

IIUC, in case of git submodules (nested or not), gitsm fetcher just bareclones them but it does not check them out; all generated subodules urls/urldata have the bareclone parameter set and no information about the checkout path; ud.destdir is set to the bareclone path. Only at the end, when all submodules (including nested ones) have been barecloned, gitsm calls 'git submodule update --recursive --no-fetch' only once, to check out submodules into <workdir>/git/<module-path>, <workdir>/git/<parent-module-path>/<module-path> etc.

So I would apply for an exception here :)
Calculating submodule checkout paths (also for nested submodules) and adding them to urldata would require adding just a couple of lines in gitsm.py and would do no harm, I hope... This would be much better than passing the modpath parameter to the tracer with a special hook: the tracer could just collect the checkout path from urldata and no fetcher-specific hooks would be required. In other words, we would solve the only problem that's still left (the others should be solved by using sessions as you suggested).

What do you think?

Cheers,

Alberto

Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

I can reduce internal module additions by externally recalculating/re-collecting npm/git module information, even if this will
cause the same data/files to be processed twice.
If you tell me, I'll do that :)
Do you have any other solution in mind?

Quoted 8 lines
Quoted 4 lines

I think you can get the data from the ud that gets passed into the recursive calls. You shouldn't need to parse files, that isn't my intent. I'm not convinced we need the fetcher specific hooks though, probably just some basic state tracing in the tracer.

I will try to use sessions for that, and I will tell you the results.

The gitsm checkout dir issue remains, though.

Sounds good, I've commented on that above.

Cheers,

Richard

#17 lore raw
Quoted 66 lines · Alberto Pianon
Quoted 33 lines · Richard Purdie
Quoted 19 lines · Alberto Pianon
Quoted 9 lines · Richard Purdie
Quoted 8 lines
Quoted 1 line

Again, you'd get the git unpack events for this?

This method passes git submodule's url, name, relative checkout path and
revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files
again and use git commands to reconstruct the same information?

Quoted 7 lines

No, you shouldn't need to parse those. Isn't this information included in the ud that is being passed to git unpack in the line immediately below? That will be seen via the git unpack call the tracer will see?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Git.unpack(self, ud, destdir, d)

Quoted 7 lines

Partly. The missing piece of information is the checkout path. If you search for
'modpath' in gitsm.py you see that that parameter is passed to multiple
functions but never used (apart from module updates) nor stored anywhere
(or am I missing something?)

"unpack path" is pretty much the thing you're having to instrument the other fetchers for so if that is the only extra information being logged in gitsm, that brings it into line with all the other fetchers and we have a consistent API.

Quoted 4 lines

What worried me more was an unbalanced API where some fetchers had to have extra special handling. If the tracer API is consistent with just the unpack/checkout path needing logging/tracing, that is much clearer and consistent and a sign the API is right.

Unpack path of git submodules (including nested ones) - stored in ud.destdir -corresponds to their bareclone path (like in <workdir>/git/.git/modules/<parent-module-name>/<module-name>) and not to the checkout path, which is not even calculated by gitsm. The bareclone path is of no use for the tracer, and in any case it's not consistent with what other fetchers return as unpack dir to the tracer (which should be the folder with where unpacked files are found).

IIUC, in case of git submodules (nested or not), gitsm fetcher just bareclones them but it does not check them out; all generated subodules urls/urldata have the bareclone parameter set and no information about the checkout path; ud.destdir is set to the bareclone path. Only at the end, when all submodules (including nested ones) have been barecloned, gitsm calls 'git submodule update --recursive --no-fetch' only once, to check out submodules into <workdir>/git/<module-path>, <workdir>/git/<parent-module-path>/<module-path> etc.

So I would apply for an exception here :)
Calculating submodule checkout paths (also for nested submodules) and adding them to urldata would require adding just a couple of lines in gitsm.py and would do no harm, I hope... This would be much better than passing the modpath parameter to the tracer with a special hook: the tracer could just collect the checkout path from urldata and no fetcher-specific hooks would be required. In other words, we would solve the only problem that's still left (the others should be solved by using sessions as you suggested).

Quoted 1 line

What do you think?

That sounds reasonable.

My concerns are as I previously mentioned, encoding unpack specific data into urldata which is effectively invalid after unpack and the naming "destdir".

Cheers,

Richard

#18 lore raw
Quoted 71 lines · Richard Purdie
Quoted 66 lines · Alberto Pianon
Quoted 33 lines · Richard Purdie
Quoted 19 lines · Alberto Pianon
Quoted 9 lines · Richard Purdie
Quoted 8 lines
Quoted 1 line

Again, you'd get the git unpack events for this?

This method passes git submodule's url, name, relative checkout path and
revision to the tracer: where do you suggest to collect the same information? Should the tracer autonomously parse all .gitmodules files
again and use git commands to reconstruct the same information?

Quoted 7 lines

No, you shouldn't need to parse those. Isn't this information included in the ud that is being passed to git unpack in the line immediately below? That will be seen via the git unpack call the tracer will see?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Git.unpack(self, ud, destdir, d)

Quoted 7 lines

Partly. The missing piece of information is the checkout path. If you search for
'modpath' in gitsm.py you see that that parameter is passed to multiple
functions but never used (apart from module updates) nor stored anywhere
(or am I missing something?)

"unpack path" is pretty much the thing you're having to instrument the other fetchers for so if that is the only extra information being logged in gitsm, that brings it into line with all the other fetchers and we have a consistent API.

Quoted 4 lines

What worried me more was an unbalanced API where some fetchers had to have extra special handling. If the tracer API is consistent with just the unpack/checkout path needing logging/tracing, that is much clearer and consistent and a sign the API is right.

Unpack path of git submodules (including nested ones) - stored in ud.destdir -corresponds to their bareclone path (like in <workdir>/git/.git/modules/<parent-module-name>/<module-name>) and not to the checkout path, which is not even calculated by gitsm. The bareclone path is of no use for the tracer, and in any case it's not consistent with what other fetchers return as unpack dir to the tracer (which should be the folder with where unpacked files are found).

IIUC, in case of git submodules (nested or not), gitsm fetcher just bareclones them but it does not check them out; all generated subodules urls/urldata have the bareclone parameter set and no information about the checkout path; ud.destdir is set to the bareclone path. Only at the end, when all submodules (including nested ones) have been barecloned, gitsm calls 'git submodule update --recursive --no-fetch' only once, to check out submodules into <workdir>/git/<module-path>, <workdir>/git/<parent-module-path>/<module-path> etc.

So I would apply for an exception here :)
Calculating submodule checkout paths (also for nested submodules) and adding them to urldata would require adding just a couple of lines in gitsm.py and would do no harm, I hope... This would be much better than passing the modpath parameter to the tracer with a special hook: the tracer could just collect the checkout path from urldata and no fetcher-specific hooks would be required. In other words, we would solve the only problem that's still left (the others should be solved by using sessions as you suggested).

Quoted 1 line

What do you think?

That sounds reasonable.

Quoted 7 lines

My concerns are as I previously mentioned, encoding unpack specific data into urldata which is effectively invalid after unpack and the naming "destdir".

Cheers,

Richard

OK, let's start with this one, then :)

Does this patch look good to you? Should I submit it separately?

Cheers,

Alberto

lib/bb/fetch2/git.py +0 -0
index 4385d0b3..1b759bc4 100644
@@ -193,6 +193,8 @@ class Git(FetchMethod):
         ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1"
         ud.shallow_extra_refs = (d.getVar("BB_GIT_SHALLOW_EXTRA_REFS") 

or "").split()

+ ud.checkout_dir = None
+
depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH") if depth_default is not None:
try:
@@ -590,6 +592,9 @@ class Git(FetchMethod):
if os.path.exists(destdir):
bb.utils.prunedir(destdir)

+ if ud.checkout_dir is None and not ud.bareclone:
+ ud.checkout_dir = destdir
+
need_lfs = self._need_lfs(ud)

if not need_lfs:

lib/bb/fetch2/gitsm.py +3 -0
index a87361cc..8a6f91e0 100644
@@ -218,6 +218,9 @@ class GitSM(Git):
 
             try:
                 newfetch = Fetch([url], d, cache=False)
+                if ud.checkout_dir is not None:
+                    new_ud = newfetch.ud[url]
+                    new_ud.checkout_dir = os.path.join(ud.checkout_dir, modpath)
                 

newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 'modules', module)))
except Exception as e:
logger.error('gitsm: submodule unpack failed: %s %s' %
(type(e).__name__, str(e)))

#19 lore raw
In reply to Richard Purdie
Quoted 16 lines · Richard Purdie
Quoted 11 lines · Alberto Pianon

So I would apply for an exception here :)
Calculating submodule checkout paths (also for nested submodules) and adding them to urldata would require adding just a couple of lines in gitsm.py and would do no harm, I hope... This would be much better than passing the modpath parameter to the tracer with a special hook: the tracer could just collect the checkout path from urldata and no fetcher-specific hooks would be required. In other words, we would solve the only problem that's still left (the others should be solved by using sessions as you suggested).

Quoted 1 line

What do you think?

That sounds reasonable.

Quoted 7 lines

My concerns are as I previously mentioned, encoding unpack specific data into urldata which is effectively invalid after unpack and the naming "destdir".

Cheers,

Richard

Hi Richard,

finally I got a working patch, tested against a PoC API implementation (implementation that I will *not* submit for now, as agreed). I tried to take into account all of your concerns and recommendations (including your approval to add just checkout dir calculation to the fetcher :) )

I know that this is a busy time for you so I kindly ask you to have just a quick look the patch below and tell me if we are finally on the right track, before officially submitting it to the ML.

Thanks,

Alberto

lib/bb/fetch2/__init__.py +1 -0
index 765aedd5..21f8f77c 100644
@@ -1578,6 +1578,7 @@ class FetchMethod(object):
             unpackdir = rootdir
 
         if not unpack or not cmd:
+            urldata.unpack_tracer.unpack("file-copy", unpackdir)
             # If file == dest, then avoid any copies, as we already put 

the file into dest!
dest = os.path.join(unpackdir, os.path.basename(file)) if file != dest and not (os.path.exists(dest) and
os.path.samefile(file, dest)):
@@ -1592,6 +1593,8 @@ class FetchMethod(object):

                         destdir = urlpath.rsplit("/", 1)[0] + '/'
                         bb.utils.mkdirhier("%s/%s" % (unpackdir, 
destdir))
                 cmd = 'cp -fpPRH "%s" "%s"' % (file, destdir)

+ else:
+ urldata.unpack_tracer.unpack("archive-extract", unpackdir)

if not cmd:
return
@@ -1683,6 +1686,20 @@ class FetchMethod(object):

         """
         return []

+
+class DummyUnpackTracer(object):
+ def start(self, unpackdir, urldata_dict, d):
+ return
+ def start_url(self, url):
+ return
+ def unpack(self, unpack_type, unpackdir):
+ return
+ def finish_url(self, url):
+ return
+ def complete(self):
+ return
+
+
class Fetch(object):
def __init__(self, urls, d, cache = True, localonly = False,
connection_cache = None):
if localonly and cache:
@@ -1703,10 +1720,25 @@ class Fetch(object):
if key in urldata_cache:
self.ud = urldata_cache[key]

+ global unpack_tracer
+ try:
+ unpack_tracer
+ except NameError:
+ class_path = d.getVar("UNPACK_TRACER_CLASS")
+ if class_path:

+                import importlib
+                module_name, _, class_name = class_path.rpartition(".")
+                module = importlib.import_module(module_name)
+                class_ = getattr(module, class_name)
+                unpack_tracer = class_()

+ else:
+ unpack_tracer = DummyUnpackTracer()
+
for url in urls:
if url not in self.ud:
try:
self.ud[url] = FetchData(url, d, localonly)
+ self.ud[url].unpack_tracer = unpack_tracer
except NonLocalMethod:
if localonly:
self.ud[url] = None
@@ -1882,6 +1914,8 @@ class Fetch(object):
if not urls:
urls = self.urls

+ unpack_tracer.start(root, self.ud, self.d)
+
for u in urls:
ud = self.ud[u] ud.setup_localpath(self.d)
@@ -1889,11 +1923,15 @@ class Fetch(object):
if ud.lockfile:
lf = bb.utils.lockfile(ud.lockfile)

+ unpack_tracer.start_url(u)
ud.method.unpack(ud, root, self.d)
+ unpack_tracer.finish_url(u)

if ud.lockfile:
bb.utils.unlockfile(lf)

+ unpack_tracer.complete()
+
def clean(self, urls=None):
"""
Clean files that the fetcher gets or places

lib/bb/fetch2/crate.py +2 -0
index 3310ed00..01d49435 100644
@@ -101,8 +101,10 @@ class Crate(Wget):
         bp = d.getVar('BP')
         if bp == ud.parm.get('name'):
             cmd = "tar -xz --no-same-owner -f %s" % thefile
+            ud.unpack_tracer.unpack("crate-extract", rootdir)
         else:
             cargo_bitbake = self._cargo_bitbake_path(rootdir)
+            ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
 
             cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, 

cargo_bitbake)

lib/bb/fetch2/git.py +3 -0
index 4385d0b3..2039df56 100644
@@ -589,6 +589,9 @@ class Git(FetchMethod):
         destdir = ud.destdir = os.path.join(destdir, destsuffix)
         if os.path.exists(destdir):
             bb.utils.prunedir(destdir)
+        if not ud.bareclone:
+            ud.unpack_tracer.unpack("git", destdir)
+            ud.checkoutdir = destdir
 
         need_lfs = self._need_lfs(ud)
 
lib/bb/fetch2/gitsm.py +9 -0
index a87361cc..5e3a9947 100644
@@ -218,6 +218,15 @@ class GitSM(Git):
 
             try:
                 newfetch = Fetch([url], d, cache=False)
+                # gitsm bareclones submodules into the main repo conf
+                # dir, then leaves the checkout of all submodules
+                # (including nested ones) to an external git command, so
+                # it does not need to know submodule checkout dirs;
+                # however such info is needed by unpack tracer API, so
+                # we set it here. This works also for nested submodules.
+                if hasattr(ud, "checkoutdir"):
+                    new_ud = newfetch.ud[url]
+                    new_ud.checkoutdir = os.path.join(ud.checkoutdir, modpath)
                 

newfetch.unpack(root=os.path.dirname(os.path.join(repo_conf, 'modules', module)))
except Exception as e:
logger.error('gitsm: submodule unpack failed: %s %s' %
(type(e).__name__, str(e)))

lib/bb/fetch2/hg.py +1 -0
index 063e1300..cbff8c49 100644
@@ -242,6 +242,7 @@ class Hg(FetchMethod):
         revflag = "-r %s" % ud.revision
         subdir = ud.parm.get("destsuffix", ud.module)
         codir = "%s/%s" % (destdir, subdir)
+        ud.unpack_tracer.unpack("hg", codir)
 
         scmdata = ud.parm.get("scmdata", "")
         if scmdata != "nokeep":
lib/bb/fetch2/npm.py +1 -0
index f83485ad..15f3f19b 100644
@@ -298,6 +298,7 @@ class Npm(FetchMethod):
         destsuffix = ud.parm.get("destsuffix", "npm")
         destdir = os.path.join(rootdir, destsuffix)
         npm_unpack(ud.localpath, destdir, d)
+        ud.unpack_tracer.unpack("npm", destdir)
 
     def clean(self, ud, d):
         """Clean any existing full or partial download"""
lib/bb/fetch2/npmsw.py +0 -0
index 4ff2c8ff..ff5f8dc7 100644
@@ -191,7 +191,9 @@ class NpmShrinkWrap(FetchMethod):
             else:
                 raise ParameterError("Unsupported dependency: %s" % 

name, ud.url)

+ # name is needed by unpack tracer for module mapping

             ud.deps.append({
+                "name": name,
                 "url": url,
                 "localpath": localpath,
                 "extrapaths": extrapaths,

@@ -270,6 +272,7 @@ class NpmShrinkWrap(FetchMethod):
destsuffix = ud.parm.get("destsuffix") if destsuffix:
destdir = os.path.join(rootdir, destsuffix)
+ ud.unpack_tracer.unpack("npm-shrinkwrap", destdir)

bb.utils.mkdirhier(destdir)
bb.utils.copyfile(ud.shrinkwrap_file,

#20 lore raw
Quoted 8 lines · Alberto Pianon

finally I got a working patch, tested against a PoC API implementation (implementation that I will *not* submit for now, as agreed). I tried to take into account all of your concerns and recommendations (including your approval to add just checkout dir calculation to the fetcher :) )

I know that this is a busy time for you so I kindly ask you to have just a quick look the patch below and tell me if we are finally on the right track, before officially submitting it to the ML.

I think this is the right direction and basically looks ok. I'm not 100% convinced about UNPACK_TRACER_CLASS but that is something we can improve as needed. FWIW new bitbake variables should really start with "BB_" as a prefix.

Thanks for working through this, I think the API does look better for it and it will be more maintainable.

Cheers,

Richard