| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# @HEADER |
| 4 |
# ***************************************************************************** |
| 5 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 6 |
# |
| 7 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 8 |
# SPDX-License-Identifier: BSD-3-Clause |
| 9 |
# ***************************************************************************** |
| 10 |
# @HEADER |
| 11 |
|
| 12 |
from FindGeneralScriptSupport import * |
| 13 |
from TribitsPackageFilePathUtils import * |
| 14 |
|
| 15 |
|
| 16 |
# |
| 17 |
# Read in the commandline arguments |
| 18 |
# |
| 19 |
|
| 20 |
usageHelp = \ |
| 21 |
r"""get-tribits-packages-from-files-list.py --deps-xml-file=<DEPS_XML_FILE> \ |
| 22 |
--files-list-file=<FILES_LIST_FILE> [--project-dir=<projectDir>] |
| 23 |
|
| 24 |
This script returns a comma-seprated list of all of the project's TriBITS |
| 25 |
packages that must be directly tested for changes in the input list of files. |
| 26 |
This may also include the special package name 'ALL_PACKAGES' which means that |
| 27 |
at least one changed file (e.g. <projectDir>/CMakeLists.txt) should result in |
| 28 |
having to test all of the TriBITS packages in the project. The logic for |
| 29 |
which file changes should trigger testing all packages can be specialized for |
| 30 |
the project through the Python module: |
| 31 |
|
| 32 |
<projectDir>/cmake/ProjectCiFileChangeLogic.py |
| 33 |
|
| 34 |
(if that file exists). |
| 35 |
|
| 36 |
This script is used in continuous integration testing workflows involving |
| 37 |
TriBITS projects where only packages impacted by the changes are tested. For |
| 38 |
such a scenario, the list of changed files can come from: |
| 39 |
|
| 40 |
git diff --name-only <upstream>..<branch-tip> > changed-files.txt |
| 41 |
|
| 42 |
where <upstream> (e.g. origin/master) is the commit reference that the local |
| 43 |
branch was created from and <branch-tip> is the tip of the topic branch. |
| 44 |
""" |
| 45 |
|
| 46 |
from optparse import OptionParser |
| 47 |
|
| 48 |
clp = OptionParser(usage=usageHelp) |
| 49 |
|
| 50 |
clp.add_option( |
| 51 |
"--deps-xml-file", dest="depsXmlFile", type="string", |
| 52 |
help="File containing TriBITS-generated XML data-structure the listing of packages, dir names, dependencies, etc.") |
| 53 |
|
| 54 |
clp.add_option( |
| 55 |
"--files-list-file", dest="filesListFile", type="string", default=None, |
| 56 |
help="File containing the list of modified files relative to project base directory, one file per line." ) |
| 57 |
|
| 58 |
clp.add_option( |
| 59 |
"--project-dir", dest="projectDir", type="string", default="", |
| 60 |
help="Base project directory. Used to access more specialized logic beyond" \ |
| 61 |
+" what is known in the <DEPSXMLFILE>. If empty '', then it will be set" \ |
| 62 |
+" automatically if TriBITS is is the standard location w.r.t. the project" \ |
| 63 |
+" in relation to this script run from the TriBITS dir.") |
| 64 |
|
| 65 |
(options, args) = clp.parse_args() |
| 66 |
|
| 67 |
if not options.filesListFile: |
| 68 |
raise Exception("Error, the option --files-list-file=FILENAME must be set!") |
| 69 |
|
| 70 |
if not options.projectDir and os.path.isfile(defaultProjectDir+"/ProjectName.cmake"): |
| 71 |
options.projectDir = defaultProjectDir |
| 72 |
|
| 73 |
filesList = readStrFromFile(options.filesListFile).splitlines() |
| 74 |
|
| 75 |
trilinosDependencies = getProjectDependenciesFromXmlFile(options.depsXmlFile) |
| 76 |
|
| 77 |
projectCiFileChangeLogic = getProjectCiFileChangeLogic(options.projectDir) |
| 78 |
|
| 79 |
packagesList = getPackagesListFromFilePathsList(trilinosDependencies, filesList, True, |
| 80 |
projectCiFileChangeLogic) |
| 81 |
|
| 82 |
print(','.join(packagesList)) |