Commit graph

26 commits

Author SHA1 Message Date
Rob Herring
23b56cb7e1 pylibfdt: Move setup.py to the top level
Using 'pip' and several setup.py sub-commands currently don't work with
pylibfdt. The primary reason is Python packaging has opinions on the
directory structure of repositories and one of those appears to be the
inability to reference source files outside of setup.py's subtree. This
means a sdist cannot be created with all necessary source components
(i.e. libfdt headers). Moving setup.py to the top-level solves these
problems.

With this change. the following commands now work:

Creating packages for pypi.org:
./setup.py sdist bdist_wheel

Using pip for installs:
pip install .
pip install git+http://github.com/robherring/dtc.git@pypi-v2

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20211111011135.2386773-5-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11 14:34:51 +11:00
Rob Herring
0b106a77db pylibfdt: Use setuptools_scm for the version
The DTC version in version_gen.h causes a warning with setuptools:

setuptools/dist.py:501: UserWarning: The version specified ('1.6.1-g5454474d') \
is an invalid version, this may not work as expected with newer versions of \
setuptools, pip, and PyPI. Please see PEP 440 for more details.

It also creates an unnecessary dependency on the rest of the build
system(s). Switch to use setuptools_scm instead to get the version for
pylibfdt.

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20211111011135.2386773-3-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11 14:30:33 +11:00
Marc-André Lureau
05874d0821 pylibfdt: allow build out of tree
With meson, we have to support out-of-tree build.

Introduce a --top-builddir option, which will default to the current
directory to lookup generated filed such as version_gen.h and output
directories.

Other source paths are derived from the location of the setup.py script
in the source tree.

--build-lib is changed to be relative to the current directory, instead
of relative to setup.py. This has less surprising results!

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20201012073405.1682782-2-marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-21 14:35:17 +11:00
Rob Herring
a5ac29baac pylibfdt: Replace dual GPLv2/BSD license boilerplate with SPDX tags
Replace pylibfdt GPLv2/BSD license boilerplate and add missing license
with SPDX tags.

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20190620211944.9378-4-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-06-21 21:06:10 +10:00
David Gibson
f9c0a425b6 Remove broken objdir / srcdir support
The dtc makefiles have support for building into a separate directory from
the sources... except that it's broken and probably always has been.

Remove the pretense.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23 21:58:42 +11:00
David Gibson
5182b5e6f2 pylibfdt: Use common PREFIX variable
For no particularly good reason, the install target for the Python library
uses a different PREFIX variable to give the installation destination
to the rest of dtc & libfdt.  Make it use the same one.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23 21:51:35 +11:00
David Gibson
99284c4db9 Refine pylibfdt_clean target
Move it to the subdir Makefile, generalize some of the patterns, remove
the 'build' directory made by setup.py and __pycache__ directory made by
Python3.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23 21:24:44 +11:00
Lumir Balhar
8113c00b99 pylibfdt: Allow switch to Python 3 via environment variable PYTHON
Python 2 is still the default but it can be changed by
setting environment variable PYTHON before build/test.

Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23 17:37:56 +11:00
David Gibson
1e4a0928f3 pylibfdt: Don't have setup.py depend on where it's invoked from
Currently setup.py depends on being invoked from the right directory
(specifically it needs to be run from the root of the project).  That's a
bit confusing.

This updates setup.py to no longer depend on the invoking directory by
instead having it change directory to the location of the script itself,
then using internal paths relative to that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:31:54 +10:00
David Gibson
ca399b1495 pylibfdt: Eliminate run_setup make function
This function no longer does anything useful, so get rid of it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:31:45 +10:00
David Gibson
98972f1b3e pylibfdt: Improved version extraction
Currently setup.py expects the library version in a VERSION environment
variable, or it exctracts the version from the Makefile.  The latter is
for the case where the script is run standalone, rather than from make.
But parsing the Makefile is ugly and fragile, and won't always get the
same version we put into the C code.

This changes to instead extracting the version from the trivial .h file we
already generate to put the version into C code.  It's still slightly ugly,
but it's simpler and since we can control the precise format of that .h,
not as fragile.

This lets us remove the remains of the makefile parsing code from setup.py.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:31:00 +10:00
David Gibson
7ba2be6cda pylibfdt: Don't silence setup.py when V=1
At the moment we unconditionally pass --quiet to setup.py.  Change that to
get more debugging output from it when V=1 is passed to make.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:30:52 +10:00
David Gibson
7691f9d393 pylibfdt: Make SETUP make variable
This points to the Python setup script, since we reference it in a couple
of places.  While we're there correct two small problems:

1) setup.py is part of the checked in sources and so lives in
   $(PYLIBFDT_srcdir) not $(PYLIBFDT_objdir) [this only worked because
   those are the same by default]

2) The module itself should depend on the setup script so it is rebuilt
   if the script is changed

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:30:28 +10:00
David Gibson
855b9963de pylibfdt: Simpler CFLAGS handling
At the moment we have some fiddly code to either pass in make's CPPFLAGS to
setup.py, or have setup.py extract them from the Makefile.  But really the
only thing we need from here is the include paths.  We already know what
include paths we need (libfdt/) so we can just set that directly in
setup.py.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:30:20 +10:00
David Gibson
47cafbeeb9 pylibfdt: Link extension module with libfdt rather than rebuilding
Currently we build the Python extension module from all the libfdt source
files as well as the swig wrapper file.  This is a bit silly, since we've
already compiled libfdt itself.

This changes the build to instead build the extension module from just the
swig wrapper, linking it against the libfdt.a we've already build.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:30:10 +10:00
David Gibson
dd695d6afb pylibfdt: Correctly set build output directory
Our Makefile currently passes PYLIBFDT_objdir into setup.py in an attempt
to set the correct place to put the Python extension module output.  But
that gets passed in the 'package_dir' map in distutils.

But that's basically not what package_dir controls.  What actually makes us
find the module in the right place is the --inplace passed to setup.py
(causing the module to go into the current directory), and the following
'mv' in the Makefile to move it into the right final location.

We can simplify setup.py by dropping the useless objdir stuff, and get the
module put in the right place straight way by instead using the --build-lib
setup.py option.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25 10:29:35 +10:00
Simon Glass
e56f2b07be pylibfdt: Use setup.py to build the swig file
Since we are using the standard .i extension for the swig file, we can use
setup.py to build the wrapper. Drop the existing build code since it is
not needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
Simon Glass
896f1c1332 pylibfdt: Use Makefile constructs to implement NO_PYTHON
The current mechanism uses a shell construct, but it seems better to use
a Makefile approach.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
Simon Glass
90db6d9989 pylibfdt: Allow setup.py to operate stand-alone
At present we require that setup.py is executed from the Makefile, which
sets up various important things like the list of files to build and the
version number.

However many installation systems expect to be able to change to the
directory containing setup.py and run it. This allows them to support (for
example) building/installing for multiple Python versions, varying
installation paths, particular C flags, etc.

The problem in implementing this is that we don't want to duplicate the
information in the Makefile. A common solution (so I am told) is to parse
the Makefile to obtain the required information.

Update the setup.py script to read a few Makefiles when it does not see
the required information in its environment. This allows installation
using:

   ./pylibfdt/setup.py install

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
Simon Glass
1c5170d3a4 pylibfdt: Rename libfdt.swig to libfdt.i
The .i extension allows Python distutils to automatically handle the swig
file. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:43:34 +10:00
Simon Glass
ab15256d8d pylibfdt: Use the call function to simplify the Makefile
This is in a separate patch since I not sure if GNU make features
are permitted in the Makefile.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
9f2e3a3a1f pylibfdt: Use the correct libfdt version in the module
Use the same version number in the module as with the rest of libfdt. This
can be examined with:

   import pkg_resources
   print pkg_resources.require('libfdt')[0].version

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
e91c652af2 pylibfdt: Enable installation of Python module
Adjust the setup script to support installation, and call it from the
Makefile if enabled. It will be disabled if we were unable to build the
module (e.g. due to swig being missing), or the NO_PYTHON environment
variable is set.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
14c4171f4f pylibfdt: Use package_dir to set the package directory
At present we manually move _libfdt.so into the correct place. Provide a
package directory so we can avoid needing to do this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:33:25 +11:00
Simon Glass
89a5062ab2 pylibfdt: Use environment to pass C flags and files
At present setup.py adjusts its command line when running, so that the
C flags and file list can be passed as arguments. Pass them in environment
variables instead, so we can avoid this messiness. It also allows us to
support the 'install' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:33:25 +11:00
Simon Glass
50f2507016 Add an initial Python library for libfdt
Add Python bindings for a bare-bones set of libfdt functions. These allow
navigating the tree and reading node names and properties.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00