Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 18 additions & 34 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Script to automate creating builds of projects."""

import argparse
import io
import logging
import os
import platform
Expand Down Expand Up @@ -79,18 +78,15 @@ def _BuildProject(self, build_helper_object, source_helper_object, distribution)
log_filename = "_".join(
[source_helper_object.project_name, build_helper_object.LOG_FILENAME]
)

# Remove older logfiles if they exists otherwise the rename
# fails on Windows.
if os.path.exists(log_filename):
os.remove(log_filename)

os.rename(build_helper_object.LOG_FILENAME, log_filename)
logging.warning(
(
f"Build of: {source_helper_object.project_name:s} failed, for more "
f"information check {log_filename:s}"
)
f"Build of: {source_helper_object.project_name:s} failed, for more "
f"information check {log_filename:s}"
)

return False
Expand Down Expand Up @@ -252,14 +248,12 @@ def Download(self, project_definition):
download_helper_object = (
download_helper.DownloadHelperFactory.NewDownloadHelper(project_definition)
)

source_helper_object = source_helper.SourcePackageHelper(
project_definition.name,
project_definition,
self._downloads_directory,
download_helper_object,
)

source_helper_object.Clean()

# TODO: add a step to make sure build environment is sane
Expand All @@ -286,7 +280,7 @@ def ReadProjectDefinitions(self, path):
Args:
path (str): path of the project definitions file.
"""
with io.open(path, "r", encoding="utf-8") as file_object:
with open(path, encoding="utf-8") as file_object:
project_definition_reader = projects.ProjectDefinitionReader()
self.project_definitions = {
definition.name: definition
Expand All @@ -306,7 +300,7 @@ def ReadProjectsPreset(self, path, preset_name):
"""
preset_definitions = {}

with io.open(path, "r", encoding="utf-8") as file_object:
with open(path, encoding="utf-8") as file_object:
definition_reader = presets.PresetDefinitionReader()
preset_definitions = {
preset_definition.name: preset_definition
Expand All @@ -317,19 +311,17 @@ def ReadProjectsPreset(self, path, preset_name):


def Main():
"""The main program function.
"""Entry point of console script.

Returns:
bool: True if successful or False if not.
int: exit code that is provided to sys.exit().
"""
build_targets = frozenset(
["download", "dpkg", "dpkg-source", "rpm", "source", "srpm", "wheel"]
)

argument_parser = argparse.ArgumentParser(
description=("Downloads and builds the latest versions of projects.")
)

argument_parser.add_argument(
"build_target",
choices=sorted(build_targets),
Expand All @@ -338,7 +330,6 @@ def Main():
default=None,
help="The build target.",
)

default_builds_directory = os.path.join("..", "l2tbuilds")
argument_parser.add_argument(
"--build-directory",
Expand All @@ -352,7 +343,6 @@ def Main():
default=default_builds_directory,
help="The location of the build directory.",
)

argument_parser.add_argument(
"-c",
"--config",
Expand All @@ -365,7 +355,6 @@ def Main():
"files e.g. projects.ini."
),
)

argument_parser.add_argument(
"--distributions",
dest="distributions",
Expand All @@ -374,7 +363,6 @@ def Main():
default="",
help=("comma separated list of specific distribution names to build."),
)

argument_parser.add_argument(
"--download-directory",
"--downloads-directory",
Expand All @@ -387,7 +375,6 @@ def Main():
default=None,
help="The location of the downloads directory.",
)

argument_parser.add_argument(
"--preset",
dest="preset",
Expand All @@ -400,7 +387,6 @@ def Main():
"The presets are defined in the preset.ini configuration file."
),
)

argument_parser.add_argument(
"--projects",
dest="projects",
Expand All @@ -413,22 +399,21 @@ def Main():
"configuration file."
),
)

options = argument_parser.parse_args()

if not options.build_target:
print("Build target missing.")
print("")
argument_parser.print_help()
print("")
return False
return 1

if options.build_target not in build_targets:
print(f"Unsupported build target: {options.build_target:s}")
print("")
argument_parser.print_help()
print("")
return False
return 1

config_path = options.config_path
if not config_path:
Expand All @@ -439,27 +424,27 @@ def Main():
if not options.preset and not options.projects:
print("Please define a preset or projects to build.")
print("")
return False
return 1

presets_file = os.path.join(config_path, "presets.ini")
if options.preset and not os.path.exists(presets_file):
print(f"No such config file: {presets_file:s}")
print("")
return False
return 1

projects_file = os.path.join(config_path, "projects.ini")
if not os.path.exists(projects_file):
print(f"No such config file: {projects_file:s}")
print("")
return False
return 1

if os.path.abspath(options.builds_directory).startswith(l2tdevtools_path):
print(
"Builds directory cannot be within l2tdevtools directory due to "
"usage of pbr"
)
print("")
return False
return 1

logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")

Expand All @@ -471,14 +456,13 @@ def Main():
project_builder = ProjectBuilder(
options.build_target, l2tdevtools_path, options.downloads_directory
)

project_names = []
if options.preset:
project_names = project_builder.ReadProjectsPreset(presets_file, options.preset)
if not project_names:
print(f"Undefined preset: {options.preset:s}")
print("")
return False
return 1

elif options.projects:
project_names = options.projects.split(",")
Expand Down Expand Up @@ -608,11 +592,11 @@ def Main():
for name in sorted(failed_builds):
print(f"\t{name:s}")

return not failed_downloads and not missing_build_dependencies and not failed_builds
if failed_downloads or missing_build_dependencies or failed_builds:
return 1

return 0


if __name__ == "__main__":
if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
43 changes: 15 additions & 28 deletions tools/dpkg-generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@


def Main():
"""The main program function.
"""Entry point of console script.

Returns:
bool: True if successful or False if not.
int: exit code that is provided to sys.exit().
"""
argument_parser = argparse.ArgumentParser(
description=("Generates dpkg packaging files for a project.")
)

argument_parser.add_argument(
"project_name",
action="store",
Expand All @@ -31,7 +30,6 @@ def Main():
"Project name for which the dpkg packaging files should be " "generated."
),
)

argument_parser.add_argument(
"-c",
"--config",
Expand All @@ -41,7 +39,6 @@ def Main():
default=None,
help="path of the build configuration file.",
)

argument_parser.add_argument(
"--source-directory",
"--source_directory",
Expand All @@ -52,7 +49,6 @@ def Main():
default=None,
help="The location of the the source directory.",
)

options = argument_parser.parse_args()

logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
Expand All @@ -65,10 +61,10 @@ def Main():
if not os.path.exists(options.config_file):
print(f"No such config file: {options.config_file:s}")
print("")
return False
return 1

project_definition_match = None
with open(options.config_file, "r", encoding="utf-8") as file_object:
with open(options.config_file, encoding="utf-8") as file_object:
project_definition_reader = projects.ProjectDefinitionReader()
for project_definition in project_definition_reader.Read(file_object):
if options.project_name == project_definition.name:
Expand All @@ -77,7 +73,7 @@ def Main():
if not project_definition_match:
print(f"No such package name: {options.project_name:s}")
print("")
return False
return 1

source_path = options.source_directory
if not source_path:
Expand All @@ -90,58 +86,49 @@ def Main():
if len(globbed_paths) != 1:
print("Unable to determine source directory.")
print("")
return False
return 1

source_path = globbed_paths[0]

if not os.path.exists(source_path):
print(f"No such source directory: {source_path:s}")
print("")
return False
return 1

source_path = os.path.abspath(source_path)
project_version = os.path.basename(source_path)
if not project_version.startswith(f"{options.project_name:s}-"):
print(
(
f"Unable to determine project version based on source "
f"directory: {source_path:s}"
)
f"Unable to determine project version based on source "
f"directory: {source_path:s}"
)
print("")
return False
return 1

_, _, project_version = project_version.partition("-")

dpkg_path = os.path.join(source_path, "dpkg")
if os.path.exists(dpkg_path):
print(f"Destination dpkg directory: {dpkg_path:s} already exists.")
print("")
return False
return 1

tools_path = os.path.dirname(__file__)
data_path = os.path.join(os.path.dirname(tools_path), "data")

build_files_generator = dpkg_files.DPKGBuildFilesGenerator(
options.project_name, project_version, project_definition_match, data_path
)

print(
(
f"Generating dpkg files for: {options.project_name:s} "
f"{project_version!s} in: {dpkg_path:s}"
)
f"Generating dpkg files for: {options.project_name:s} "
f"{project_version!s} in: {dpkg_path:s}"
)

build_files_generator.GenerateFiles(dpkg_path)

print("")

return True
return 0


if __name__ == "__main__":
if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
Loading
Loading