Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only write the libraries hint file when using //maven #177

Merged
merged 1 commit into from
Mar 23, 2024
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
14 changes: 10 additions & 4 deletions maven/maven.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -e
print_usage() {
cat << EOF

Usage: maven.sh -a action(s) [-l path/to/library]
Usage: bazel run @pomgen//maven.sh -a action(s) -l path/to/library/root/dir

Required arguments:

Expand Down Expand Up @@ -179,6 +179,10 @@ _for_each_library() {
echo ""
while read library_path;
do
if [[ "$library_path" == \#* ]]; then
# the line starts with the comment character
continue
fi
echo "[INFO] Processing library: $library_path"
if [ "$action" == "install" ]; then
_for_each_pom "install_main_artifact" $repo_root_path $pom_base_filename $jar_artifact_classifier "/$library_path"
Expand Down Expand Up @@ -224,7 +228,7 @@ fi

if [ -z "$actions" ] ; then
echo "[ERROR] The action(s) to run must be specified using -a, for example:"
echo " $ bazel run @pomgen//maven -- -a install"
echo " $ bazel run @pomgen//maven -- -a pomgen,install"
echo " bazel run @pomgen//maven for usage information."
exit 1
fi
Expand Down Expand Up @@ -313,9 +317,11 @@ do
_for_each_pom "clean_source_tree" $repo_root_path $pom_base_filename $jar_artifact_classifier $library_path

elif [ "$action" == "pomgen" ]; then
extra_args=""
# this script uses the special libraries hint file, which contains
# the path to the upstream libraries
extra_args="--write_libraries_hint_file"
if [ "$debug" = true ]; then
extra_args="--verbose"
extra_args="${extra_args} --verbose"
fi
if [ "$force_pomgen" = true ]; then
extra_args="${extra_args} --force"
Expand Down
15 changes: 10 additions & 5 deletions pomgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def main(args):
output_dir = _get_output_dir(args)

lib_paths = bazel.query_all_libraries(repo_root, packages)
if len(lib_paths) == 1:
# a single lib as a starting point is the common case,
# so we do not bother with the other cases for now
if args.write_libraries_hint_file:
if not args.ignore_references:
# the libraries hint file contains the list of all upstream
# libs (including the current lib) - this only works when
# crawling is enabled (ignore_references disables crawling)
_write_all_libraries_hint_files(result, output_dir, lib_paths[0])
if len(lib_paths) == 1:
# a single lib as a starting point is the common case,
# so we do not bother with the other cases for now
path = lib_paths[0]
_write_all_libraries_hint_files(result, output_dir, path)

for pomgen in result.pomgens:
pom_dest_dir = os.path.join(output_dir, pomgen.bazel_package)
Expand Down Expand Up @@ -123,6 +125,8 @@ def _parse_arguments(args):
help="Verbose output")
parser.add_argument("--pom.description", type=str, required=False,
dest="pom_description", help="Written as the pom's <description/>")
parser.add_argument("--write_libraries_hint_file", required=False, action="store_true",
help="The libraries hint file is used by the wrapper script in //maven, it is not needed when running pomgen directly")

return parser.parse_args(args)

Expand Down Expand Up @@ -150,7 +154,8 @@ def _write_all_libraries_hint_files(crawler_result, output_dir, start_lib_path):
if not os.path.exists(hint_file_dir):
os.makedirs(hint_file_dir)
hint_file_path = os.path.join(hint_file_dir, "libraries.txt")
_write_file(hint_file_path, "\n".join(lib_paths))
_write_file(hint_file_path, "\n".join(
["# the root lib path, followed by the paths to its upstream dependencies"] + lib_paths))
logger.info("Wrote libraries hint file to [%s]" % hint_file_path)


Expand Down
Loading