Skip to content

Commit f07d877

Browse files
committed
ypkg: Allow a custom build directory
Allow packager's to override the default build output directory. This in primarily intended for solbuild to invoke ypkg-build as root but continue to use the 'build' user directories.
1 parent c7074c2 commit f07d877

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

ypkg

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def main():
2929
"i.e. no prompt", action="store_true")
3030
parser.add_argument("-D", "--output-dir", type=str,
3131
help="Set the output directory for resulting files")
32+
parser.add_argument("-B", "--build-dir", type=str,
33+
help="Set the base directory for performing the build")
3234
# Main file
3335
parser.add_argument("filename", help="Path to the ypkg YAML file",
3436
nargs='?')

ypkg2/main.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def main():
6060
type=int, default=-1)
6161
parser.add_argument("-D", "--output-dir", type=str,
6262
help="Set the output directory for resulting files")
63+
parser.add_argument("-B", "--build-dir", type=str,
64+
help="Set the base directory for performing the build")
6365
# Main file
6466
parser.add_argument("filename", help="Path to the ypkg YAML file to build",
6567
nargs='?')
@@ -84,6 +86,11 @@ def main():
8486
outputDir = od
8587
outputDir = os.path.abspath(outputDir)
8688

89+
if args.build_dir:
90+
buildDir = os.path.abspath(args.build_dir)
91+
else:
92+
buildDir = None
93+
8794
# Grab filename
8895
if not args.filename:
8996
console_ui.emit_error("Error",
@@ -102,7 +109,7 @@ def main():
102109
"or as the root user (not recommended)")
103110
sys.exit(1)
104111

105-
build_package(args.filename, outputDir)
112+
build_package(args.filename, outputDir, buildDir)
106113

107114

108115
def clean_build_dirs(context):
@@ -184,7 +191,7 @@ def execute_step(context, step, step_n, work_dir):
184191
return True
185192

186193

187-
def build_package(filename, outputDir):
194+
def build_package(filename, outputDir, buildDir=None):
188195
""" Will in future be moved to a separate part of the module """
189196
spec = YpkgSpec()
190197
if not spec.load_from_path(filename):
@@ -225,6 +232,7 @@ def build_package(filename, outputDir):
225232

226233
spec.packager_name = packager_name
227234
spec.packager_email = packager_email
235+
spec.build_dir = buildDir
228236
# Try to load history
229237
dirn = os.path.dirname(filename)
230238
hist = os.path.join(dirn, "history.xml")

ypkg2/ypkgcontext.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,14 @@ def get_path(self):
304304

305305
def get_sources_directory(self):
306306
""" Get the configured source directory for fetching sources to """
307-
if self.is_root:
307+
if self.is_root and self.spec.build_dir is None:
308308
return self.global_archive_dir
309309
return os.path.join(self.get_build_prefix(), "sources")
310310

311311
def get_build_prefix(self):
312312
""" Get the build prefix used by ypkg """
313+
if self.spec.build_dir is not None:
314+
return self.spec.build_dir
313315
if self.is_root:
314316
return "/var/ypkg-root"
315317
return "{}/YPKG".format(os.path.expanduser("~"))

0 commit comments

Comments
 (0)