<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>13186</bug_id>
          
          <creation_ts>2019-02-18 11:14:58 +0000</creation_ts>
          <short_desc>Precompiled python3 bytecode is stale</short_desc>
          <delta_ts>2019-11-07 16:19:59 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>devtools / tool chain</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>3.1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tristan Ramseyer">t</reporter>
          <assigned_to name="Robert Yang">liezhi.yang</assigned_to>
          <cc>alejandro.delcastillo</cc>
    
    <cc>alex.kanavin</cc>
    
    <cc>leon</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>ross.burton</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>83034</commentid>
    <comment_count>0</comment_count>
    <who name="Tristan Ramseyer">t</who>
    <bug_when>2019-02-18 11:14:58 +0000</bug_when>
    <thetext>With both &quot;sumo&quot; 3.5.5 (97ee1f80870745bf6c542ee2f184c9e468672714) and &quot;master&quot; 3.7.2 (c92e780c85523fe860602b947b029d7782afa47a) python3 recipes the generated .pyc files are stale.

This issue can be observed best using a &quot;readonly&quot; rfs and starting the python3 interpreter with -vv such as &apos;python3 -vv -c &quot;&quot;&apos;. Many messages like &quot;bytecode is stale for &apos;site&apos;&quot; should appear indicating that the timestamp in the header of the .pyc files differs from the mtime of the corresponding .py file.

For a possible solution, python&apos;s 3.7 newly introduced hash-based (CHECKED_HASH) or even (UNCHECKED_HASH) invalidation mode could also be used.

Remark: Reading out the mtime from a .pyc file is described at https://qiita.com/amedama/items/698a7c4dbdd34b03b427 whereas python 3.7 has an additional 4-byte value between &quot;magic_str&quot; and &quot;mtime_str&quot; as described in https://www.python.org/dev/peps/pep-0552/.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83037</commentid>
    <comment_count>1</comment_count>
      <attachid>4434</attachid>
    <who name="Tristan Ramseyer">t</who>
    <bug_when>2019-02-19 08:23:09 +0000</bug_when>
    <thetext>Created attachment 4434
Proposed patch for creation of data.tar</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83038</commentid>
    <comment_count>2</comment_count>
    <who name="Tristan Ramseyer">t</who>
    <bug_when>2019-02-19 08:25:42 +0000</bug_when>
    <thetext>With the kind help of Richard Purdie, it was possible to pinpoint the exact cause of the .py files timestamps being altered: http://git.yoctoproject.org/cgit.cgi/opkg-utils/commit/?id=682f8c5e35b8854a9bb858b8ee1714d27e0c00db

The issue is that upon creation of data.tar.$cext, the flags --mtime is used which alters the mtime of every file in it.

I have tested the attached patch successfully on my embedded system.
The python3 interpreter startup time is significantly faster and &quot;-vv&quot; does not show any stale .pyc&apos;s.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83040</commentid>
    <comment_count>3</comment_count>
    <who name="Alejandro del Castillo">alejandro.delcastillo</who>
    <bug_when>2019-02-19 19:46:01 +0000</bug_when>
    <thetext>Sent patch to opkg mailing list [1] and to OE mailing list [2]

[1] https://groups.google.com/forum/#!topic/opkg-devel/fGbjrKXbOG4
[2] http://lists.openembedded.org/pipermail/openembedded-core/2019-February/279217.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83063</commentid>
    <comment_count>4</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2019-02-21 15:43:16 +0000</bug_when>
    <thetext>The fix was merged into master: http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=a79bc39033c07e5cb0aa5ca95afe8f035c403f33  (thanks Alejandro)

I&apos;d really like to have a test case for this to close the issue out, would you be able to help with that?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83067</commentid>
    <comment_count>5</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2019-02-21 15:58:20 +0000</bug_when>
    <thetext>Just to get you started with the test, this is the right place for it:

https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/lib/oeqa/runtime/cases/python.py

The existing test gives a good example of how to run python and check the output. (I guess checking for absence of certain strings would be right).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83069</commentid>
    <comment_count>6</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2019-02-21 16:08:36 +0000</bug_when>
    <thetext>On second thought, this might not be the right place. By the time the test would be run (on a read-write filesystem), python might have already rebuilt all the .pyc files (with dnf tests running ahead of python tests in particular).

So not sure how to test this, really. There is a test for read-only images in meta/lib/oeqa/selftest/cases/buildoptions.py, but it only tests that the image builds, and won&apos;t boot it (but could be extended for that).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83108</commentid>
    <comment_count>7</comment_count>
    <who name="Tristan Ramseyer">t</who>
    <bug_when>2019-02-25 09:33:54 +0000</bug_when>
    <thetext>I have written a working test for this (for .ipk&apos;s only at the moment).
The test itself is located in do_package_write_ipk_append.
This solution works for my build process and if you deem it worthy for merging it into the master, feel free to do it :).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83109</commentid>
    <comment_count>8</comment_count>
      <attachid>4445</attachid>
    <who name="Tristan Ramseyer">t</who>
    <bug_when>2019-02-25 09:34:49 +0000</bug_when>
    <thetext>Created attachment 4445
Test .pyc for stale</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83110</commentid>
    <comment_count>9</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2019-02-25 11:06:06 +0000</bug_when>
    <thetext>You can place this into insane.bbclass, then it will work for all package types as part of package_qa() task, and for all packages that contain .py/.pyc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83116</commentid>
    <comment_count>10</comment_count>
    <who name="Tristan Ramseyer">t</who>
    <bug_when>2019-02-25 20:56:06 +0000</bug_when>
    <thetext>As of now the test is done by taking a .py file which is believed to be in every python3 installation &quot;__future.py__&quot;.
The test would have to be adopted to e.g. take the first .pyc it finds and the corresponding .py file or even to the test all .pyc files.

Also it would have to be ideally able to extract any package format the build process may generate: ipk, deb, rpm and possibly tar.
Whereas for extracting rpm files &quot;rpm2cpio&quot; and &quot;cpio&quot; or similar tools are required, which (I guess) would result in a such dependency of every recipe using the insane.bbclass.
Is this really what we want?
Might it be better to split this up into two tests?:
- QA: Test if .pyc files in PKGDEST are not stale (this should be doable without special tools)
- ??: Test if package manager&apos;s are packing files using undesired options such as --mtime.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83220</commentid>
    <comment_count>11</comment_count>
    <who name="Leon Woestenberg">leon</who>
    <bug_when>2019-03-08 22:50:46 +0000</bug_when>
    <thetext>sumo yocto-2.5.2-127-gd3ad243 (d3ad2438222050faf33e83598c1f6ecd25ff65b6) with .deb packages, I am getting stale .pyc on my read-only target filesystem.

I am using reproducible builds, and the .py files have timestamp 0 seconds since epoch, whereas the 4 byte timestamp (at byte offset 4) in each .pyc file are substantially larger.

By erasing the timestamp in a .pyc file (remounting rw, dd if=/dev/zero of=some.pyc bs=1 count=4 seek=4 conv=notrunc) the .pyc file is no longer considered stale.

Has this issue been fixed for all package types?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83221</commentid>
    <comment_count>12</comment_count>
    <who name="Leon Woestenberg">leon</who>
    <bug_when>2019-03-08 23:18:58 +0000</bug_when>
    <thetext>I have debugged my case further, and the issue seems not so much in the python build itself, but in the fact that my files end up with timestamp 0 seconds since epoch on my read-only filesystem, whereas the .py files have file timestamp matching SOURCE_DATE_EPOCH=1517788422, which also matches the internal timestamp in the .pyc file.

my local.conf:
INHERIT += &quot;reproducible_build&quot;
BUILD_REPRODUCIBLE_BINARIES=&quot;1&quot;
REPRODUCIBLE_TIMESTAMP_ROOTFS=&quot;1549187940&quot;
LDCONFIGDEPEND=&quot;&quot;


temp/run.do_compile.3316:83:export SOURCE_DATE_EPOCH=&quot;1517788422&quot;

this matches the last modification time of the .py file in image/

00:06 $ ls -a --full-time image/usr/lib/python3.5/json/encoder.py
-rw-r--r-- 3 leon leon 15961 2018-02-05 00:53:42.000000000 +0100 image/usr/lib/python3.5/json/encoder.py

or directly printing last modification time of the file as seconds since epoch:

00:08 $ find image/usr/lib/python3.5/json/encoder.py | xargs -L1 stat -c%Y
1517788422

which in turn matches the internal timestamp in .pyc:

dd if=./image/usr/lib/python3.5/json/__pycache__/encoder.cpython-35.pyc skip=4 bs=1 count=4 | od -An -tu4
4+0 records in
4+0 records out
4 bytes copied, 4.6492e-05 s, 86.0 kB/s
 1517788422

However on the target the .py files are 0 seconds since epoch:

root@adesys-octalarm:/usr/bin# ls --full-time -ald /usr/lib/python3.5/json/encoder.py     
-rw-r--r-- 3 root root 15961 1970-01-01 01:00:00.000000000 +0100 /usr/lib/python3.5/json/encoder.py</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83222</commentid>
    <comment_count>13</comment_count>
    <who name="Leon Woestenberg">leon</who>
    <bug_when>2019-03-08 23:42:34 +0000</bug_when>
    <thetext>I found that this is probably due to my filesystem being an OSTree deployment; meta-updater / meta-ostree.

More info here:

https://github.com/advancedtelematic/meta-updater/issues/461</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84016</commentid>
    <comment_count>14</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2019-05-30 15:28:55 +0000</bug_when>
    <thetext>Robert, we think this has come down to needed some self-test for the consistency of the py and pyc file timestamaps. Richard can give you more guidance as needed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85496</commentid>
    <comment_count>15</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2019-11-07 16:19:59 +0000</bug_when>
    <thetext>Since https://www.python.org/dev/peps/pep-0552/ the cache files are invalidated based on file hashes not timestamps and the pyc files are hash based, so I believe this is resolved now.

Closing.  If anyone disagrees, please reopen.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>4434</attachid>
            <date>2019-02-19 08:23:09 +0000</date>
            <delta_ts>2019-02-19 08:23:09 +0000</delta_ts>
            <desc>Proposed patch for creation of data.tar</desc>
            <filename>tar_mtime_not_for_data.patch</filename>
            <type>application/octet-stream</type>
            <size>625</size>
            <attacher name="Tristan Ramseyer">t</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL29wa2ctYnVpbGQgYi9vcGtnLWJ1aWxkCmluZGV4IDliMjRiOWYuLjExOTFm
ZjcgMTAwNzU1Ci0tLSBhL29wa2ctYnVpbGQKKysrIGIvb3BrZy1idWlsZApAQCAtMjg5LDcgKzI4
OSw3IEBAIGVjaG8gJENPTlRST0wgPiAkdG1wX2Rpci90YXJYCiAKICMgSWdub3JlIGVycm9yIGNv
ZGUgMSwgY2F1c2VkIGJ5IG1vZGlmeWluZyB0aGUgbnVtYmVyIG9mIGhhcmQgbGlua3Mgd2hpbGUg
Y3JlYXRpbmcgdGhlIHRhciBmaWxlCiByYz0wCi0oIGNkICRwa2dfZGlyICYmIHRhciAkb2dhcmdz
ICR0c29ydGFyZ3MgLS1tdGltZT0iJGJ1aWxkX2RhdGUiIC1YICR0bXBfZGlyL3RhclggLWMgJHRh
cmZvcm1hdCAuIHwgJGNvbXByZXNzb3IgJGNvbXByZXNzb3JhcmdzID4gJHRtcF9kaXIvZGF0YS50
YXIuJGNleHQgKSB8fCByYz0kPworKCBjZCAkcGtnX2RpciAmJiB0YXIgJG9nYXJncyAkdHNvcnRh
cmdzIC1YICR0bXBfZGlyL3RhclggLWMgJHRhcmZvcm1hdCAuIHwgJGNvbXByZXNzb3IgJGNvbXBy
ZXNzb3JhcmdzID4gJHRtcF9kaXIvZGF0YS50YXIuJGNleHQgKSB8fCByYz0kPwogaWYgWyAkcmMg
LW5lIDEgXSAmJiBbICRyYyAtbmUgMCBdOyB0aGVuCiAgICAgICAgIGV4aXQgJHJjIAogZmkKCg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>4445</attachid>
            <date>2019-02-25 09:34:49 +0000</date>
            <delta_ts>2019-11-07 15:58:00 +0000</delta_ts>
            <desc>Test .pyc for stale</desc>
            <filename>python3_%.bbappend</filename>
            <type>text/plain</type>
            <size>2595</size>
            <attacher name="Tristan Ramseyer">t</attacher>
            
              <data encoding="base64">REVQRU5EUyArPSAiZHBrZy1uYXRpdmUiCmRvX3BhY2thZ2Vfd3JpdGVfaXBrW2RlcGVuZHNdICs9
ICJkcGtnLW5hdGl2ZTpkb19wb3B1bGF0ZV9zeXNyb290IgoKZG9fcGFja2FnZV93cml0ZV9pcGtf
YXBwZW5kICgpIHsKICAgIGltcG9ydCBvcwogICAgaW1wb3J0IHN1YnByb2Nlc3MKCiAgICAjIElm
IC5weWMgZmlsZXMgc2hhbGwgYmUgaW5jbHVkZWQgaW4gdGhlIHBhY2thZ2UsIGNoZWNrIHRoYXQg
dGhlIHBhY2thZ2luZyBwcm9jZXNzIGRpZCBub3QgbWFrZSB0aGVtIHN0YWxlLgogICAgIyBUaGlz
IGlzIGRvbmUgYnkgdmVyaWZ5aW5nIG9uZSAucHljIGZpbGUgaW4gdGhl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vcGVuKHB5Y19maWxlLCAncmInKSBhcyBmOgog
ICAgICAgICAgICBtYWdpY19zdHIgPSBmLnJlYWQoNCkKICAgICAgICAgICAgYml0ZmllbGRfc3Ry
ID0gZi5yZWFkKDQpCiAgICAgICAgICAgIG10aW1lX3N0ciA9IGYucmVhZCg0KQogICAgICAgICAg
ICBiaXRmaWVsZCA9IGdldF9sb25nKGJpdGZpZWxkX3N0cikKICAgICAgICAgICAgcHljX2ZpbGVf
bXRpbWUgPSBnZXRfbG9uZyhtdGltZV9zdHIpCiAgICAgICAgICAgIAogICAgICAgICMgUGVyZm9y
bSBjaGVjayBvbmx5IHdoZW4gY2FjaGVkIGJ5dGVjb2RlIGludmFsaWRhdGlvbiBpcyBiYXNlZCBv
biB0aW1lc3RhbXBzCiAgICAgICAgaWYgMCA9PSBiaXRmaWVsZDoKICAgICAgICAgICAgcHlfZmls
ZV9tdGltZSA9IGludChvcy5wYXRoLmdldG10aW1lKHB5X2ZpbGUpKQogICAgICAgICAgICBpZiBw
eWNfZmlsZV9tdGltZSAhPSBweV9maWxlX210aW1lOgogICAgICAgICAgICAgICAgYmIuZmF0YWwo
IlBhY2thZ2VkIC5weWMgZmlsZSBfX2Z1dHVyZV9fIGlzIHN0YWxlOiBIZWFkZXIgaW4gLnB5YyBp
bmRpY2F0ZXMgbXRpbWUgPSB7MH0gYnV0IC5weSBoYXMgbXRpbWUgPSB7MX0iLmZvcm1hdChweWNf
ZmlsZV9tdGltZSwgcHlfZmlsZV9tdGltZSkpCn0K
</data>

          </attachment>
      

    </bug>

</bugzilla>