Skip to content

Commit

Permalink
Improve build.py maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
maveonair committed Feb 26, 2023
1 parent d15edc4 commit f586dff
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
HELIX_SOURCE_CODE_URL = "https://github.com/helix-editor/helix/archive/refs/tags"


def prepare_target(target_directory) -> None:
rmtree(target_directory)
os.mkdir(target_directory)


def get_args() -> tuple[str, str, str]:
args = sys.argv[1:]

Expand All @@ -39,6 +34,11 @@ def get_args() -> tuple[str, str, str]:
return args[0], args[1], args[2]


def prepare_target(target_directory) -> None:
rmtree(target_directory)
os.mkdir(target_directory)


def get_helix_source_url(helix_version: str) -> str:
return f"{HELIX_SOURCE_CODE_URL}/{helix_version}.tar.gz"

Expand Down Expand Up @@ -114,39 +114,21 @@ def create_dependencies_archives(
)


def update_changelog(source_directory_path, ubuntu_codename, changelog_version) -> None:
with chdir(source_directory_path):
print("-> Create new changelog entry...")
subprocess.check_call(
[
"dch",
"--distribution",
ubuntu_codename,
"--package",
"helix",
"--newversion",
changelog_version,
f"No-change backport to {ubuntu_codename}",
]
)


def prepare_for_build(
target_directory: str,
source_directory_path: str,
helix_version: str,
) -> str:
prepare_target(target_directory)
prepare_target(TARGET_DIRECTORY)

release_file_path = download_helix_release(
target_directory_path=target_directory, helix_version=helix_version
target_directory_path=TARGET_DIRECTORY, helix_version=helix_version
)

unarchive_helix_release(
target_directory_path=target_directory, archive_file_path=release_file_path
target_directory_path=TARGET_DIRECTORY, archive_file_path=release_file_path
)

debian_files_directory = prepare_debian_files(target_directory)
debian_files_directory = prepare_debian_files(TARGET_DIRECTORY)

create_dependencies_archives(
source_directory_path=source_directory_path,
Expand All @@ -156,26 +138,52 @@ def prepare_for_build(
return release_file_path


def move_debian_files(source_directory_path: str, target_directory_path: str) -> None:
move(source_directory_path, target_directory_path)


def update_changelog(source_directory_path, ubuntu_codename, changelog_version) -> None:
with chdir(source_directory_path):
print("-> Create new changelog entry...")
subprocess.check_call(
[
"dch",
"--distribution",
ubuntu_codename,
"--package",
"helix",
"--newversion",
changelog_version,
f"No-change backport to {ubuntu_codename}",
]
)


def run_debuild(source_directory_path: str) -> None:
with chdir(source_directory_path):
print("-> Run debuild...")
subprocess.check_call(["debuild", "-S", "-sa"])


def run_build(
target_directory: str,
source_directory_path: str,
release_file_path: str,
ubuntu_codename: str,
changelog_version: str,
) -> None:
# We remove the extracted source directory because it contains
# many compiled files from the prepare-for-build step that we
# do not want in the final source archive.
prepare_target(source_directory_path)

unarchive_helix_release(
target_directory_path=target_directory, archive_file_path=release_file_path
target_directory_path=TARGET_DIRECTORY, archive_file_path=release_file_path
)

move(os.path.join(target_directory, "debian"), source_directory_path)
move_debian_files(
source_directory_path=os.path.join(TARGET_DIRECTORY, "debian"),
target_directory_path=source_directory_path,
)

update_changelog(
source_directory_path=source_directory_path,
Expand All @@ -191,13 +199,11 @@ def main():
source_directory_path = os.path.join(TARGET_DIRECTORY, f"helix-{helix_version}")

release_file_path = prepare_for_build(
target_directory=TARGET_DIRECTORY,
source_directory_path=source_directory_path,
helix_version=helix_version,
)

run_build(
target_directory=TARGET_DIRECTORY,
source_directory_path=source_directory_path,
release_file_path=release_file_path,
ubuntu_codename=ubuntu_codename,
Expand Down

0 comments on commit f586dff

Please sign in to comment.