patman: Move to absolute imports

At present patman sets the python path on startup so that it can access
the libraries it needs. If we convert to use absolute imports this is not
necessary.

Move patman to use absolute imports. This requires changes in tools which
use the patman libraries (which is most of them).

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-04-17 18:09:04 -06:00
parent 16287933a8
commit bf776679a7
58 changed files with 154 additions and 149 deletions

View File

@ -21,8 +21,8 @@ import struct
import sys import sys
from binman import elf from binman import elf
import command from patman import command
import tools from patman import tools
# Set to True to enable printing output while working # Set to True to enable printing output while working
DEBUG = False DEBUG = False

View File

@ -19,8 +19,8 @@ import unittest
from binman import cbfs_util from binman import cbfs_util
from binman.cbfs_util import CbfsWriter from binman.cbfs_util import CbfsWriter
from binman import elf from binman import elf
import test_util from patman import test_util
import tools from patman import tools
U_BOOT_DATA = b'1234' U_BOOT_DATA = b'1234'
U_BOOT_DTB_DATA = b'udtb' U_BOOT_DTB_DATA = b'udtb'

View File

@ -8,12 +8,12 @@
from collections import OrderedDict from collections import OrderedDict
import os import os
import sys import sys
import tools from patman import tools
from binman import cbfs_util from binman import cbfs_util
from binman import elf from binman import elf
import command from patman import command
import tout from patman import tout
# List of images we plan to create # List of images we plan to create
# Make this global so that it can be referenced from tests # Make this global so that it can be referenced from tests

View File

@ -13,9 +13,9 @@ import shutil
import struct import struct
import tempfile import tempfile
import command from patman import command
import tools from patman import tools
import tout from patman import tout
ELF_TOOLS = True ELF_TOOLS = True
try: try:

View File

@ -11,10 +11,10 @@ import tempfile
import unittest import unittest
from binman import elf from binman import elf
import command from patman import command
import test_util from patman import test_util
import tools from patman import tools
import tout from patman import tout
binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))

View File

@ -10,9 +10,9 @@ import os
import sys import sys
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
from patman.tools import ToHex, ToHexSize from patman.tools import ToHex, ToHexSize
import tout from patman import tout
modules = {} modules = {}

View File

@ -12,7 +12,7 @@ import unittest
from binman import entry from binman import entry
from dtoc import fdt from dtoc import fdt
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class TestEntry(unittest.TestCase): class TestEntry(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@ -9,7 +9,7 @@ from collections import OrderedDict
from binman.entry import Entry, EntryArg from binman.entry import Entry, EntryArg
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry__testing(Entry): class Entry__testing(Entry):

View File

@ -7,8 +7,8 @@
from binman.entry import Entry from binman.entry import Entry
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
import tout from patman import tout
class Entry_blob(Entry): class Entry_blob(Entry):
"""Entry containing an arbitrary binary blob """Entry containing an arbitrary binary blob

View File

@ -9,8 +9,8 @@ image.
""" """
from binman.entry import Entry from binman.entry import Entry
import tools from patman import tools
import tout from patman import tout
FDTMAP_MAGIC = b'_FDTMAP_' FDTMAP_MAGIC = b'_FDTMAP_'
FDTMAP_HDR_LEN = 16 FDTMAP_HDR_LEN = 16

View File

@ -11,7 +11,7 @@ import os
from binman.etype.section import Entry_section from binman.etype.section import Entry_section
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry_files(Entry_section): class Entry_files(Entry_section):

View File

@ -5,7 +5,7 @@
from binman.entry import Entry from binman.entry import Entry
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry_fill(Entry): class Entry_fill(Entry):
"""An entry which is filled to a particular byte value """An entry which is filled to a particular byte value

View File

@ -7,9 +7,9 @@
from binman.entry import Entry from binman.entry import Entry
from binman import fmap_util from binman import fmap_util
import tools from patman import tools
from patman.tools import ToHexSize from patman.tools import ToHexSize
import tout from patman import tout
class Entry_fmap(Entry): class Entry_fmap(Entry):

View File

@ -8,11 +8,11 @@
from collections import OrderedDict from collections import OrderedDict
import command from patman import command
from binman.entry import Entry, EntryArg from binman.entry import Entry, EntryArg
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
# Build GBB flags. # Build GBB flags.
# (src/platform/vboot_reference/firmware/include/gbb_header.h) # (src/platform/vboot_reference/firmware/include/gbb_header.h)

View File

@ -10,7 +10,7 @@ from collections import OrderedDict
from binman.entry import Entry from binman.entry import Entry
from binman.etype.blob import Entry_blob from binman.etype.blob import Entry_blob
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry_intel_ifwi(Entry_blob): class Entry_intel_ifwi(Entry_blob):
"""Entry containing an Intel Integrated Firmware Image (IFWI) file """Entry containing an Intel Integrated Firmware Image (IFWI) file

View File

@ -14,8 +14,8 @@ import sys
from binman.entry import Entry from binman.entry import Entry
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
import tout from patman import tout
class Entry_section(Entry): class Entry_section(Entry):

View File

@ -7,7 +7,7 @@ from collections import OrderedDict
from binman.entry import Entry, EntryArg from binman.entry import Entry, EntryArg
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry_text(Entry): class Entry_text(Entry):

View File

@ -7,7 +7,7 @@
from binman.entry import Entry from binman.entry import Entry
from binman.etype.blob_dtb import Entry_blob_dtb from binman.etype.blob_dtb import Entry_blob_dtb
import tools from patman import tools
class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb): class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
"""A U-Boot device tree file, with the microcode removed """A U-Boot device tree file, with the microcode removed

View File

@ -9,7 +9,7 @@ from binman.entry import Entry
from binman.etype.blob import Entry_blob from binman.etype.blob import Entry_blob
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry_u_boot_elf(Entry_blob): class Entry_u_boot_elf(Entry_blob):
"""U-Boot ELF image """U-Boot ELF image

View File

@ -9,9 +9,9 @@
from binman import elf from binman import elf
from binman.entry import Entry from binman.entry import Entry
import command from patman import command
from binman.etype.blob import Entry_blob from binman.etype.blob import Entry_blob
import tools from patman import tools
class Entry_u_boot_spl_bss_pad(Entry_blob): class Entry_u_boot_spl_bss_pad(Entry_blob):
"""U-Boot SPL binary padded with a BSS region """U-Boot SPL binary padded with a BSS region

View File

@ -7,11 +7,11 @@
import struct import struct
import command from patman import command
from binman.entry import Entry from binman.entry import Entry
from binman.etype.blob import Entry_blob from binman.etype.blob import Entry_blob
from binman.etype.u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr from binman.etype.u_boot_with_ucode_ptr import Entry_u_boot_with_ucode_ptr
import tools from patman import tools
class Entry_u_boot_tpl_with_ucode_ptr(Entry_u_boot_with_ucode_ptr): class Entry_u_boot_tpl_with_ucode_ptr(Entry_u_boot_with_ucode_ptr):
"""U-Boot TPL with embedded microcode pointer """U-Boot TPL with embedded microcode pointer

View File

@ -7,7 +7,7 @@
from binman.entry import Entry from binman.entry import Entry
from binman.etype.blob import Entry_blob from binman.etype.blob import Entry_blob
import tools from patman import tools
class Entry_u_boot_ucode(Entry_blob): class Entry_u_boot_ucode(Entry_blob):
"""U-Boot microcode block """U-Boot microcode block

View File

@ -11,8 +11,8 @@ from binman import elf
from binman.entry import Entry from binman.entry import Entry
from binman.etype.blob import Entry_blob from binman.etype.blob import Entry_blob
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
import command from patman import command
class Entry_u_boot_with_ucode_ptr(Entry_blob): class Entry_u_boot_with_ucode_ptr(Entry_blob):
"""U-Boot with embedded microcode pointer """U-Boot with embedded microcode pointer

View File

@ -12,7 +12,7 @@ import os
from binman.entry import Entry, EntryArg from binman.entry import Entry, EntryArg
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
class Entry_vblock(Entry): class Entry_vblock(Entry):
"""An entry which contains a Chromium OS verified boot block """An entry which contains a Chromium OS verified boot block

View File

@ -12,7 +12,7 @@ import unittest
from dtoc import fdt from dtoc import fdt
from dtoc import fdt_util from dtoc import fdt_util
from dtoc.fdt import FdtScan from dtoc.fdt import FdtScan
import tools from patman import tools
class TestFdt(unittest.TestCase): class TestFdt(unittest.TestCase):
@classmethod @classmethod

View File

@ -10,7 +10,7 @@ import collections
import struct import struct
import sys import sys
import tools from patman import tools
# constants imported from lib/fmap.h # constants imported from lib/fmap.h
FMAP_SIGNATURE = b'__FMAP__' FMAP_SIGNATURE = b'__FMAP__'

View File

@ -29,10 +29,10 @@ from dtoc import fdt_util
from binman.etype import fdtmap from binman.etype import fdtmap
from binman.etype import image_header from binman.etype import image_header
from image import Image from image import Image
import command from patman import command
import test_util from patman import test_util
import tools from patman import tools
import tout from patman import tout
# Contents of test files, corresponding to different entry types # Contents of test files, corresponding to different entry types
U_BOOT_DATA = b'1234' U_BOOT_DATA = b'1234'

View File

@ -18,8 +18,8 @@ from binman.etype import image_header
from binman.etype import section from binman.etype import section
from dtoc import fdt from dtoc import fdt
from dtoc import fdt_util from dtoc import fdt_util
import tools from patman import tools
import tout from patman import tout
class Image(section.Entry_section): class Image(section.Entry_section):
"""A Image, representing an output from binman """A Image, representing an output from binman

View File

@ -36,7 +36,7 @@ sys.path.append(get_python_lib())
from binman import cmdline from binman import cmdline
from binman import control from binman import control
import test_util from patman import test_util
def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath): def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
"""Run the functional tests and any embedded doctests """Run the functional tests and any embedded doctests

View File

@ -10,8 +10,8 @@ import re
from dtoc import fdt from dtoc import fdt
import os import os
import tools from patman import tools
import tout from patman import tout
# Records the device-tree files known to binman, keyed by entry type (e.g. # Records the device-tree files known to binman, keyed by entry type (e.g.
# 'u-boot-spl-dtb'). These are the output FDT files, which can be updated by # 'u-boot-spl-dtb'). These are the output FDT files, which can be updated by

View File

@ -19,10 +19,10 @@ import time
from buildman import builderthread from buildman import builderthread
from buildman import toolchain from buildman import toolchain
import command from patman import command
import gitutil from patman import gitutil
import terminal from patman import terminal
from terminal import Print from patman.terminal import Print
""" """
Theory of Operation Theory of Operation

View File

@ -9,8 +9,8 @@ import shutil
import sys import sys
import threading import threading
import command from patman import command
import gitutil from patman import gitutil
RETURN_CODE_RETRY = -1 RETURN_CODE_RETRY = -1

View File

@ -12,11 +12,11 @@ from buildman import board
from buildman import bsettings from buildman import bsettings
from buildman import toolchain from buildman import toolchain
from buildman.builder import Builder from buildman.builder import Builder
import command from patman import command
import gitutil from patman import gitutil
import patchstream from patman import patchstream
import terminal from patman import terminal
from terminal import Print from patman.terminal import Print
def GetPlural(count): def GetPlural(count):
"""Returns a plural 's' if count is not 1""" """Returns a plural 's' if count is not 1"""

View File

@ -13,11 +13,10 @@ from buildman import bsettings
from buildman import cmdline from buildman import cmdline
from buildman import control from buildman import control
from buildman import toolchain from buildman import toolchain
import command from patman import command
import gitutil from patman import gitutil
import terminal from patman import terminal
import toolchain from patman import tools
import tools
settings_data = ''' settings_data = '''
# Buildman settings file # Buildman settings file

View File

@ -25,9 +25,9 @@ from buildman import builder
from buildman import cmdline from buildman import cmdline
from buildman import control from buildman import control
from buildman import toolchain from buildman import toolchain
import patchstream from patman import patchstream
import gitutil from patman import gitutil
import terminal from patman import terminal
def RunTests(skip_net_tests): def RunTests(skip_net_tests):
import func_test import func_test

View File

@ -18,11 +18,11 @@ from buildman import bsettings
from buildman import builder from buildman import builder
from buildman import control from buildman import control
from buildman import toolchain from buildman import toolchain
import commit from patman import commit
import command from patman import command
import terminal from patman import terminal
import test_util from patman import test_util
import tools from patman import tools
use_network = True use_network = True

View File

@ -11,9 +11,9 @@ import tempfile
import urllib.request, urllib.error, urllib.parse import urllib.request, urllib.error, urllib.parse
from buildman import bsettings from buildman import bsettings
import command from patman import command
import terminal from patman import terminal
import tools from patman import tools
(PRIORITY_FULL_PREFIX, PRIORITY_PREFIX_GCC, PRIORITY_PREFIX_GCC_PATH, (PRIORITY_FULL_PREFIX, PRIORITY_PREFIX_GCC, PRIORITY_PREFIX_GCC_PATH,
PRIORITY_CALC) = list(range(4)) PRIORITY_CALC) = list(range(4))

View File

@ -15,9 +15,9 @@ import collections
import copy import copy
import sys import sys
import fdt from dtoc import fdt
import fdt_util from dtoc import fdt_util
import tools from patman import tools
# When we see these properties we ignore them - i.e. do not create a structure member # When we see these properties we ignore them - i.e. do not create a structure member
PROP_IGNORE_LIST = [ PROP_IGNORE_LIST = [

View File

@ -8,10 +8,10 @@
import struct import struct
import sys import sys
import fdt_util from dtoc import fdt_util
import libfdt import libfdt
from libfdt import QUIET_NOTFOUND from libfdt import QUIET_NOTFOUND
import tools from patman import tools
# This deals with a device tree, presenting it as an assortment of Node and # This deals with a device tree, presenting it as an assortment of Node and
# Prop objects, representing nodes and properties, respectively. This file # Prop objects, representing nodes and properties, respectively. This file

View File

@ -13,8 +13,8 @@ import struct
import sys import sys
import tempfile import tempfile
import command from patman import command
import tools from patman import tools
def fdt32_to_cpu(val): def fdt32_to_cpu(val):
"""Convert a device tree cell to an integer """Convert a device tree cell to an integer

View File

@ -33,14 +33,15 @@ import unittest
# Bring in the patman libraries # Bring in the patman libraries
our_path = os.path.dirname(os.path.realpath(__file__)) our_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(our_path, '../patman')) sys.path.append(os.path.join(our_path, '../patman'))
sys.path.append(os.path.join(our_path, '..'))
# Bring in the libfdt module # Bring in the libfdt module
sys.path.insert(0, 'scripts/dtc/pylibfdt') sys.path.insert(0, 'scripts/dtc/pylibfdt')
sys.path.insert(0, os.path.join(our_path, sys.path.insert(0, os.path.join(our_path,
'../../build-sandbox_spl/scripts/dtc/pylibfdt')) '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
import dtb_platdata from dtoc import dtb_platdata
import test_util from patman import test_util
def run_tests(args): def run_tests(args):
"""Run all the test we have for dtoc """Run all the test we have for dtoc

View File

@ -14,15 +14,15 @@ import os
import struct import struct
import unittest import unittest
import dtb_platdata from dtoc import dtb_platdata
from dtb_platdata import conv_name_to_c from dtb_platdata import conv_name_to_c
from dtb_platdata import get_compat_name from dtb_platdata import get_compat_name
from dtb_platdata import get_value from dtb_platdata import get_value
from dtb_platdata import tab_to from dtb_platdata import tab_to
import fdt from dtoc import fdt
import fdt_util from dtoc import fdt_util
import test_util from patman import test_util
import tools from patman import tools
our_path = os.path.dirname(os.path.realpath(__file__)) our_path = os.path.dirname(os.path.realpath(__file__))

View File

@ -17,14 +17,14 @@ our_path = os.path.dirname(os.path.realpath(__file__))
for dirname in ['../patman', '..']: for dirname in ['../patman', '..']:
sys.path.insert(0, os.path.join(our_path, dirname)) sys.path.insert(0, os.path.join(our_path, dirname))
import command from dtoc import fdt
import fdt from dtoc import fdt_util
from dtoc.fdt_util import fdt32_to_cpu
from fdt import TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, BytesToValue from fdt import TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, BytesToValue
import fdt_util
from fdt_util import fdt32_to_cpu
import libfdt import libfdt
import test_util from patman import command
import tools from patman import test_util
from patman import tools
def _GetPropertyValue(dtb, node, prop_name): def _GetPropertyValue(dtb, node, prop_name):
"""Low-level function to get the property value based on its offset """Low-level function to get the property value based on its offset

View File

@ -3,12 +3,14 @@
# #
import collections import collections
import command
import gitutil
import os import os
import re import re
import sys import sys
import terminal
from patman import command
from patman import gitutil
from patman import terminal
from patman import tools
def FindCheckPatch(): def FindCheckPatch():
top_level = gitutil.GetTopLevel() top_level = gitutil.GetTopLevel()

View File

@ -3,8 +3,9 @@
# #
import os import os
import cros_subprocess
import tools from patman import cros_subprocess
from patman import tools
"""Shell command ease-ups for Python.""" """Shell command ease-ups for Python."""

View File

@ -14,10 +14,10 @@ import unittest
from io import StringIO from io import StringIO
import gitutil from patman import gitutil
import patchstream from patman import patchstream
import settings from patman import settings
import tools from patman import tools
@contextlib.contextmanager @contextlib.contextmanager

View File

@ -2,10 +2,11 @@
# Copyright (c) 2012 The Chromium OS Authors. # Copyright (c) 2012 The Chromium OS Authors.
# #
import command
import gitutil
import os import os
from patman import command
from patman import gitutil
def FindGetMaintainer(): def FindGetMaintainer():
"""Look for the get_maintainer.pl script. """Look for the get_maintainer.pl script.

View File

@ -2,17 +2,17 @@
# Copyright (c) 2011 The Chromium OS Authors. # Copyright (c) 2011 The Chromium OS Authors.
# #
import command
import re import re
import os import os
import series
import subprocess import subprocess
import sys import sys
import terminal
import checkpatch from patman import checkpatch
import settings from patman import command
import tools from patman import series
from patman import settings
from patman import terminal
from patman import tools
# True to use --no-decorate - we check this in Setup() # True to use --no-decorate - we check this in Setup()
use_no_decorate = True use_no_decorate = True

View File

@ -18,14 +18,14 @@ if __name__ == "__main__":
sys.path.append(os.path.join(our_path, '..')) sys.path.append(os.path.join(our_path, '..'))
# Our modules # Our modules
import checkpatch from patman import checkpatch
import command from patman import command
import gitutil from patman import gitutil
import patchstream from patman import patchstream
import project from patman import project
import settings from patman import settings
import terminal from patman import terminal
import test from patman import test
parser = OptionParser() parser = OptionParser()
@ -86,7 +86,7 @@ if __name__ != "__main__":
# Run our meagre tests # Run our meagre tests
elif options.test: elif options.test:
import doctest import doctest
import func_test from patman import func_test
sys.argv = [sys.argv[0]] sys.argv = [sys.argv[0]]
result = unittest.TestResult() result = unittest.TestResult()

View File

@ -9,10 +9,10 @@ import re
import shutil import shutil
import tempfile import tempfile
import command from patman import command
import commit from patman import commit
import gitutil from patman import gitutil
from series import Series from patman.series import Series
# Tags that we detect and remove # Tags that we detect and remove
re_remove = re.compile('^BUG=|^TEST=|^BRANCH=|^Review URL:' re_remove = re.compile('^BUG=|^TEST=|^BRANCH=|^Review URL:'

View File

@ -4,7 +4,7 @@
import os.path import os.path
import gitutil from patman import gitutil
def DetectProject(): def DetectProject():
"""Autodetect the name of the current project. """Autodetect the name of the current project.

View File

@ -5,11 +5,11 @@
import itertools import itertools
import os import os
import get_maintainer from patman import get_maintainer
import gitutil from patman import gitutil
import settings from patman import settings
import terminal from patman import terminal
import tools from patman import tools
# Series-xxx tags that we understand # Series-xxx tags that we understand
valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name', valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name',

View File

@ -10,9 +10,9 @@ except:
import os import os
import re import re
import command from patman import command
import gitutil from patman import gitutil
import tools from patman import tools
"""Default settings per-project. """Default settings per-project.

View File

@ -8,11 +8,11 @@ import os
import tempfile import tempfile
import unittest import unittest
import checkpatch from patman import checkpatch
import gitutil from patman import gitutil
import patchstream from patman import patchstream
import series from patman import series
import commit from patman import commit
class TestPatch(unittest.TestCase): class TestPatch(unittest.TestCase):

View File

@ -10,7 +10,8 @@ import os
import sys import sys
import unittest import unittest
import command from patman import command
from patman import test_util
from io import StringIO from io import StringIO

View File

@ -3,7 +3,6 @@
# Copyright (c) 2016 Google, Inc # Copyright (c) 2016 Google, Inc
# #
import command
import glob import glob
import os import os
import shutil import shutil
@ -11,7 +10,8 @@ import struct
import sys import sys
import tempfile import tempfile
import tout from patman import command
from patman import tout
# Output directly (generally this is temporary) # Output directly (generally this is temporary)
outdir = None outdir = None

View File

@ -6,7 +6,7 @@
import sys import sys
import terminal from patman import terminal
# Output verbosity levels that we support # Output verbosity levels that we support
ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6) ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6)

View File

@ -32,7 +32,7 @@ import sys
our_path = os.path.dirname(os.path.realpath(__file__)) our_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(our_path, '../tools/patman')) sys.path.append(os.path.join(our_path, '../tools/patman'))
import command from patman import command
def rm_kconfig_include(path): def rm_kconfig_include(path):
"""Remove a path from Kconfig files """Remove a path from Kconfig files