snapcraft 给出 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

snapcraft gives 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

我尝试在 snap 包中编译 Qt 5.13,但在启动时出现以下错误:

'NoneType' object has no attribute 'decode'

我认为这与底层 python 代码中的一些国际化问题有关,因此尝试更改构建顺序,做了很多其他事情,但每次我们都返回上面的错误。

以下是snapcraft文件:

name: vcs
version: '2.0'
summary: VCS GUI
description: |
  Maritime Robotics Vehicle Control System GUI
confinement: devmode
base: core18
layout:
   /usr/lib/vcs-gui/plugins:
      bind: $SNAP/usr/lib/vcs-gui/plugins

parts:

  desktop-qt5:
    source: https://download.qt.io/archive/qt/5.13/5.13.2/single/qt-everywhere-src-5.13.2.tar.xz
    plugin: dump
    override-build: |
      snapcraftctl build
      ./configure -opensource -confirm-license -debug -nomake examples  -nomake tests
      make
      make install
    override-prime: |
      locale-gen "en_US.UTF-8"
      update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
      snapcraftctl prime
    build-packages:
      - python
      - locales

  protobuf:
    source: https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/protobuf-all-3.8.0.tar.gz
    plugin: autotools

  cmake:
    source: https://github.com/Kitware/CMake/releases/download/v3.15.0-rc1/cmake-3.15.0-rc1.tar.gz
    plugin: autotools

  libproj:
    source: http://download.osgeo.org/proj/proj-6.0.0.tar.gz
    plugin: autotools
    build-packages: 
      - libsqlite3-dev
      - sqlite3
      - libgl1-mesa-dev
      - libglu1-mesa-dev

  gdal:
    source: https://github.com/OSGeo/gdal/releases/download/v3.0.0/gdal-3.0.0.tar.gz
    plugin: autotools
    after: [libproj]

  ecc:
    source: https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.12.5-Source.tar.gz
    plugin: cmake
    configflags: [-DENABLE_FORTRAN=OFF]

  vcs:
    plugin: cmake
    configflags: [-DQt5Core_DIR=/usr/local/Qt-5.13.2/lib/cmake/Qt5Core,-DQt5_DIR=/usr/local/Qt-5.13.2/lib/cmake/Qt5,-DQT_QMAKE_EXECUTABLE=/usr/local/Qt-5.13.2/bin/qmake]
    source: https://github.com/fritzone/Qt-CMake-HelloWorld.git
    after: [protobuf,cmake,libproj,gdal,ecc,desktop-qt5]
    build-packages:
      - git
      - g++
      - make
      - libkml-dev
      - libarmadillo-dev
      - libgeographic-dev
      - libssl-dev
      - libconfig++-dev
      - libxml2-dev
      - libmodbus-dev
      - libev-dev
      - libudev-dev
      - libexiv2-dev
      - libv4l-dev
      - doxygen
      - graphviz
      - libgeotiff-dev
      - libgeos-dev 
      - libpng-dev
      - libbotan-2-dev
    stage-packages:
      - libbotan-2-4
      - libtspi1
      - libkmlconvenience1
      - libkmlbase1
      - libkmlengine1
      - libkmldom1
      - libssl1.0.0
      - libconfig++9v5
      - libxml2
      - libmodbus5
      - libev4
      - libaec0
      - libhdf4-0-alt
      - libsz2
      - libexiv2-14
      - libv4l-0
      - libgeotiff2
      - libsdl2-2.0-0
      - libxcb-xinerama0
      - libarmadillo8
      - libarpack2
      - libsuperlu5
      - libgeos-3.6.2
      - libgeos-c1v5

apps:
  vcs:
    command: bin/desktop-launch bin/vcs
    adapter: full
    command-chain: 
      - bin/desktop-launch
      - bin/vcs
    common-id: vcs-gui.desktop
    desktop: usr/share/applications/vcs-gui.desktop
    environment:
      "DISABLE_WAYLAND": "0"
    plugs: [x11, wayland, desktop, desktop-legacy, opengl, network, home]

这是我 运行 使用以下命令时得到的输出:

SNAPCRAFT_ENABLE_DEVELOPER_DEBUG=yes SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY=8G snapcraft --debug

(是的,由于构建 Qt 时编译器崩溃,它需要大约 8GB 的​​内存)

.
. // everything is fine till this point
.
Priming desktop-qt5 
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
'NoneType' object has no attribute 'decode'
We would appreciate it if you anonymously reported this issue.
No other data than the traceback and the version of snapcraft in use will be sent.

这里是 python 脚本的堆栈跟踪,它试图构建包:

'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
We would appreciate it if you anonymously reported this issue.
No other data than the traceback and the version of snapcraft in use will be sent.
Would you like to send this error data? (Yes/No/Always/View) [no]: View
Traceback (most recent call last):
  File "/snap/snapcraft/3440/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==3.8', 'console_scripts', 'snapcraft')()
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 1114, in invoke
    return Command.invoke(self, ctx)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/cli/_runner.py", line 103, in run
    snap_command.invoke(ctx)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/cli/_command.py", line 87, in invoke
    return super().invoke(ctx)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 261, in snap
    _execute(steps.PRIME, parts=[], pack_project=True, output=output, **kwargs)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/cli/lifecycle.py", line 66, in _execute
    lifecycle.execute(step, project_config, parts)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 94, in execute
    executor.run(step, part_names)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 148, in run
    self._handle_step(part_names, part, step, current_step, cli_config)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 162, in _handle_step
    getattr(self, "_run_{}".format(current_step.name))(part)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 237, in _run_prime
    self._run_step(step=steps.PRIME, part=part, progress="Priming")
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/lifecycle/_runner.py", line 281, in _run_step
    getattr(part, step.name)()
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 795, in prime
    self._do_runner_step(steps.PRIME)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 242, in _do_runner_step
    return getattr(self._runner, "{}".format(step.name))()
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 91, in prime
    "override-prime", self._override_prime_scriptlet, self._primedir
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 137, in _run_scriptlet
    scriptlet_name, function_call.strip()
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/_runner.py", line 193, in _handle_builtin_function
    function(**function_args)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 807, in _do_prime
    dependency_paths = self._handle_elf(snap_files)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 814, in _handle_elf
    elf_files = elf.get_elf_files(self.primedir, snap_files)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/elf.py", line 576, in get_elf_files
    elf_file = ElfFile(path=path)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/elf.py", line 219, in __init__
    elf_data = self._extract(path)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/snapcraft/internal/elf.py", line 252, in _extract
    interp_section = elf.get_section_by_name(_INTERP)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/elftools/elf/elffile.py", line 94, in get_section_by_name
    for i, sec in enumerate(self.iter_sections()):
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/elftools/elf/elffile.py", line 103, in iter_sections
    yield self.get_section(i)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/elftools/elf/elffile.py", line 83, in get_section
    return self._make_section(section_header)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/elftools/elf/elffile.py", line 288, in _make_section
    name = self._get_section_name(section_header)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/elftools/elf/elffile.py", line 283, in _get_section_name
    return self._file_stringtable_section.get_string(name_offset)
  File "/snap/snapcraft/3440/lib/python3.5/site-packages/elftools/elf/sections.py", line 70, in get_string
    return s.decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
We would appreciate it if you anonymously reported this issue.

有没有人知道如何让它发挥作用?请注意,由于在 5.13 中修复了一些错误,使用默认基础 core18 (5.9) 附带的 Qt 对我们的应用程序不利,因此我们至少需要 5.13.

此尝试构建的应用程序只是一个 helloworld 应用程序,它与我们收到的错误无关,但 snapcraft 需要它才能到达错误阶段。

(如果您尝试针对此文件 运行 snapcraft 小心,Qt 在我的计算机上需要 4 - 5 个小时来编译)

在回溯中,get_string 函数引发了 UnicodeDecodeError,因为它无法从 ASCII 解码某些文本。

在 elftools 的 current source 中,此行已被替换为

return s.decode('UTF-8') is else ''

所以你可以尝试升级与 snap 捆绑的 pyelftools 版本

<the python interpreter bundled with snap> -m pip install --upgrade pyelftools 

(确保你可以回滚,以防这次升级让事情变得更糟)