Document _cargo_toml
This commit is contained in:
parent
b8c292f0aa
commit
9bcfa374ec
1 changed files with 23 additions and 6 deletions
|
@ -16,20 +16,37 @@ def _get_binaries(cargo_toml):
|
||||||
|
|
||||||
def _cargo_toml(source_path, path, exclude_vendor=True):
|
def _cargo_toml(source_path, path, exclude_vendor=True):
|
||||||
"""Find a Cargo.toml related with a binary."""
|
"""Find a Cargo.toml related with a binary."""
|
||||||
# If path is aready a Cargo.toml file, we are done
|
# Finding the Cargo.toml is a bit tricky, and the general idea is
|
||||||
if path.endswith('Cargo.toml'):
|
# like this:
|
||||||
|
#
|
||||||
|
# - `source_path`: is set but the dependecy generator call
|
||||||
|
# (cargo_bundled.attr) to point to `%{_builddir}`, so where
|
||||||
|
# the sources are (`.../rpmbuild/BUILD`)
|
||||||
|
#
|
||||||
|
# - `path`: can point to an executable when called by
|
||||||
|
# cargo_bundler.attr, that lives in `%{_buildroot}`, for
|
||||||
|
# example `.../rpmbuild/BUILDROOT/<PKGNAME>/usr/bin/<BINNAME>`
|
||||||
|
#
|
||||||
|
# - `path`: can also point to a Cargo.toml when called from
|
||||||
|
# command line
|
||||||
|
#
|
||||||
|
# - If `path` is a binary, we search the Cargo.toml from
|
||||||
|
# `source_path` that generates this specific binary
|
||||||
|
|
||||||
|
# If path is already a Cargo.toml file, we are done
|
||||||
|
binary_or_cargo_toml = os.path.basename(path)
|
||||||
|
if binary_or_cargo_toml == 'Cargo.toml':
|
||||||
return os.path.join(source_path, path)
|
return os.path.join(source_path, path)
|
||||||
|
|
||||||
binary = os.path.basename(path)
|
|
||||||
cargo_tomls = glob.glob(os.path.join(source_path, '**/Cargo.toml'),
|
cargo_tomls = glob.glob(os.path.join(source_path, '**/Cargo.toml'),
|
||||||
recursive=True)
|
recursive=True)
|
||||||
for cargo_toml in cargo_tomls:
|
for cargo_toml in cargo_tomls:
|
||||||
if exclude_vendor and 'vendor' in cargo_toml.split(os.sep):
|
if exclude_vendor and 'vendor' in cargo_toml.split(os.sep):
|
||||||
continue
|
continue
|
||||||
|
if binary_or_cargo_toml in _get_binaries(cargo_toml):
|
||||||
if binary in _get_binaries(cargo_toml):
|
|
||||||
return cargo_toml
|
return cargo_toml
|
||||||
raise Exception(f'Cargo.toml not found for binary {binary}')
|
|
||||||
|
raise Exception(f'Cargo.toml not found for binary {binary_or_cargo_toml}')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue