Skip to content

Commit

Permalink
pw_build: Git repo location fix
Browse files Browse the repository at this point in the history
Use the gn root as the default location of the git repo instead of the
current working directory.

Change-Id: Ie5a5ef66311030883473e2e2579a2996c841fbcd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/121912
Reviewed-by: Rob Mohr <[email protected]>
Commit-Queue: Anthony DiGirolamo <[email protected]>
  • Loading branch information
AnthonyDiGirolamo authored and CQ Bot Account committed Dec 1, 2022
1 parent 08c7b77 commit 54725fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 25 additions & 6 deletions pw_build/py/pw_build/create_python_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@

def _parse_args():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--repo-root',
type=Path,
help='Path to the root git repo.',
)
parser.add_argument(
'--tree-destination-dir', type=Path, help='Path to output directory.'
)
Expand Down Expand Up @@ -102,13 +107,25 @@ def _parse_args():


class UnknownGitSha(Exception):
"Exception thrown when the current git SHA cannot be found."
"""Exception thrown when the current git SHA cannot be found."""


def get_current_git_sha(repo_root: Optional[Path] = None) -> str:
if not repo_root:
repo_root = Path.cwd()
git_command = [
'git',
'-C',
str(repo_root),
'log',
'-1',
'--pretty=format:%h',
]

def get_current_git_sha() -> str:
git_command = 'git log -1 --pretty=format:%h'
process = subprocess.run(
git_command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT
git_command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
gitsha = process.stdout.decode()
if process.returncode != 0 or not gitsha:
Expand All @@ -126,7 +143,7 @@ def get_current_date() -> str:


class UnexpectedConfigSection(Exception):
"Exception thrown when the common configparser contains unexpected values."
"""Exception thrown when the common config contains unexpected values."""


def load_common_config(
Expand All @@ -135,6 +152,7 @@ def load_common_config(
package_version_override: Optional[str] = None,
append_git_sha: bool = False,
append_date: bool = False,
repo_root: Optional[Path] = None,
) -> configparser.ConfigParser:
"""Load an existing ConfigParser file and update metadata.version."""
config = configparser.ConfigParser()
Expand Down Expand Up @@ -164,7 +182,7 @@ def load_common_config(
if append_date:
build_metadata.append(get_current_date())
if append_git_sha:
build_metadata.append(get_current_git_sha())
build_metadata.append(get_current_git_sha(repo_root))
if build_metadata:
version_prefix = config['metadata']['version']
build_metadata_text = '.'.join(build_metadata)
Expand Down Expand Up @@ -385,6 +403,7 @@ def _main():
package_version_override=args.setupcfg_override_version,
append_git_sha=args.setupcfg_version_append_git_sha,
append_date=args.setupcfg_version_append_date,
repo_root=args.repo_root,
)

update_config_with_packages(config=config, python_packages=py_packages)
Expand Down
2 changes: 2 additions & 0 deletions pw_build/python_dist.gni
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ template("pw_python_distribution") {
_pw_internal_run_in_venv = false

args = [
"--repo-root",
rebase_path("//", root_build_dir),
"--tree-destination-dir",
rebase_path(_output_dir, root_build_dir),
"--input-list-files",
Expand Down

0 comments on commit 54725fa

Please sign in to comment.