82401dce2e89cf929b4178f7bbc97adee5a0b85a
3 # SPDX-FileCopyrightText: 2024 Kienan Stewart <kstewart@efficios.com>
4 # SPDX-License-Identifier: GPL-2.0-only
21 "BABELTRACE_PLUGIN_PATH",
33 parser
= argparse
.ArgumentParser(
34 description
="Fetch and create a stub environment from common job artifacts",
36 # Commands: fetch (implies activate), activate, deactivate
37 subparsers
= parser
.add_subparsers(required
=True, dest
="command")
39 "-v", "--verbose", action
="count", help="Increase the verbosity"
42 fetch_parser
= subparsers
.add_parser("fetch")
43 fetch_parser
.add_argument(
48 fetch_parser
.add_argument(
51 default
="https://ci.lttng.org",
52 help="The jenkins server to use",
54 fetch_parser
.add_argument(
57 help="The job name, eg. 'lttng-tools_master_root_slesbuild'",
61 fetch_parser
.add_argument(
63 "--job-configuration",
64 help="An optional job configuration, eg. 'babeltrace_version=stable-2.0,build=std,conf=agents,liburcu_version=master,node=sles15sp4-amd64-rootnode,platform=sles15sp4-amd64'",
67 fetch_parser
.add_argument(
68 "-b", "--build-id", help="The build ID, eg. '28'", default
=None, required
=True
70 fetch_parser
.add_argument(
73 help="Do not activate environment after fetching artifacts",
82 def fetch(destination
, server
, job
, build
, job_configuration
=None, download
=True):
83 if destination
.exists() and not destination
.is_dir():
84 raise Exception("'{}' exists but is not a directory".format(str(destination
)))
85 if not destination
.exists():
92 job_configuration
or "",
98 url_components
= [urllib
.parse
.quote_plus(x
) for x
in components
]
99 url
= "/".join([server
] + url_components
)
100 logging
.info("Fetching archive from '{}'".format(url
))
102 with tempfile
.NamedTemporaryFile() as archive
:
103 subprocess
.run(["wget", url
, "-O", archive
.name
])
104 subprocess
.run(["unzip", "-d", str(destination
), archive
.name
])
106 # The artifact archive doesn't include symlinks, so the the symlinks for
107 # the ".so" in libdir_arch must be rebuilt
109 lib_dir_arch
= lib_dir
111 pathlib
.Path("/etc/products.d/SLES.prod").exists()
112 or pathlib
.Path("/etc/redhat-release").exists()
113 or pathlib
.Path("/etc/yocto-release").exists()
114 ) and "64bit" in platform
.architecture
:
115 lib_dir_arch
= "{}64"
117 so_re
= re
.compile("^.*\.so\.\d+\.\d+\.\d+$")
118 for root
, dirs
, files
in os
.walk(
119 str(destination
/ "deps" / "build" / lib_dir_arch
)
130 os
.symlink(f
, os
.path
.join(root
, a
))
132 env
= create_activate(destination
)
133 create_deactivate(destination
, env
)
136 def create_activate(destination
):
138 lib_dir_arch
= lib_dir
140 pathlib
.Path("/etc/products.d/SLES.prod").exists()
141 or pathlib
.Path("/etc/redhat-release").exists()
142 or pathlib
.Path("/etc/yocto-release").exists()
143 ) and "64bit" in platform
.architecture
:
144 lib_dir_arch
= "{}64"
147 env
["_JENKINS_ENV"] = destination
.name
148 for var
in _ENV_VARS
:
149 original
= os
.getenv(var
)
150 env
["_JENKINS_{}".format(var
)] = original
if original
else ""
151 if var
== "BABELTRACE_PLUGIN_PATH":
152 env
["BABELTRACE_PLUGIN_PATH"] = "{}{}".format(
153 "{}:".format(original
) if original
else "",
166 elif var
== "CPPFLAGS":
167 env
["CPPFLAGS"] = "{}-I{}".format(
168 "{} ".format(original
) if original
else "",
170 (destination
/ "archive" / "deps" / "build" / "include").absolute()
173 elif var
== "LD_LIBRARY_PATH":
174 env
["LD_LIBRARY_PATH"] = "{}{}".format(
175 "{}:".format(original
) if original
else "",
178 destination
/ "archive" / "deps" / "build" / lib_dir_arch
182 elif var
== "LDFLAGS":
183 env
["LDFLAGS"] = "{}-L{}".format(
184 "{} ".format(original
) if original
else "",
187 destination
/ "archive" / "deps" / "build" / lib_dir_arch
192 env
["PATH"] = "{}:{}".format(
194 str((destination
/ "archive" / "deps" / "build" / "bin").absolute()),
196 elif var
== "PKG_CONFIG_PATH":
197 env
["PKG_CONFIG_PATH"] = "{}{}".format(
198 "{}:" if original
else "",
210 elif var
== "PYTHONPATH":
212 elif var
== "WORKSPACE":
213 env
["WORKSPACE"] = str((destination
/ "archive").absolute())
215 raise Exception("Unsupported environment variable '{}'".format(var
))
217 args
= ["{}={}".format(k
, shlex
.quote(v
)) for k
, v
in env
.items()]
218 with
open(str(destination
/ "activate"), "w") as fp
:
219 fp
.writelines("#!/usr/bin/bash\n")
221 fp
.writelines("export {}\n".format(arg
))
222 (destination
/ "activate").chmod(0o755)
226 def create_deactivate(destination
, env
):
227 with
open(str(destination
/ "deactivate"), "w") as fp
:
228 fp
.writelines("#!/usr/bin/bash\n")
229 for k
, v
in env
.items():
230 if k
.startswith("_JENKINS_"):
231 fp
.writelines("unset {}\n".format(k
))
233 original
= env
["_JENKINS_{}".format(k
)]
234 fp
.writelines("export {}={}\n".format(k
, original
))
235 (destination
/ "deactivate").chmod(0o755)
238 if __name__
== "__main__":
239 logger
= logging
.getLogger()
240 parser
= _get_argparser()
241 args
= parser
.parse_args()
242 logger
.setLevel(max(1, 30 - (args
.verbose
or 0) * 10))
243 logging
.debug("Initialized with log level: {}".format(logger
.getEffectiveLevel()))
245 if args
.command
== "fetch":
247 destination
=args
.directory
,
251 job_configuration
=args
.job_configuration
,
252 download
=args
.download
,
255 raise Exception("Command '{}' unsupported".format(args
.command
))
This page took 0.040894 seconds and 4 git commands to generate.