From bb283e636d6a2b6956f1ea7fb61737fc6e310812 Mon Sep 17 00:00:00 2001 From: duarte Date: Thu, 19 Mar 2026 12:20:22 +0000 Subject: [PATCH 01/22] test: initial build statement testing --- test/build_defs/test.build_defs | 3 +- test/export/BUILD | 16 ++++++++++ test/export/repo/test/BUILD_FILE | 8 +++++ test/export/repo/test/file.txt | 1 + test/export/test_build_statement_content.sh | 33 +++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/export/repo/test/BUILD_FILE create mode 100644 test/export/repo/test/file.txt create mode 100755 test/export/test_build_statement_content.sh diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index 5830e3f62..33ab98369 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -10,6 +10,7 @@ def please_repo_e2e_test( expected_output: dict = {}, expect_output_contains: dict = {}, expect_output_doesnt_contain: dict = {}, + tool_content_checker = ["//test/build_defs:content_checker"], labels: list = [], ): plz_command = plz_command.replace("plz ", "$TOOLS_PLEASE ") @@ -37,7 +38,7 @@ def please_repo_e2e_test( data["BASE_CONFIG"] = ["//test/build_defs:base_config"] tools["PLEASE"] = ["//package:installed_files|please"] - tools["CONTENT_CHECKER"] = ["//test/build_defs:content_checker"] + tools["CONTENT_CHECKER"] = tool_content_checker return gentest( name = name, diff --git a/test/export/BUILD b/test/export/BUILD index c0f7ed5a0..9ac48b353 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -4,3 +4,19 @@ plz_e2e_test( name = "export_src_please_test", cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", ) + +sh_binary( + name = "build_statement_checker", + main = "test_build_statement_content.sh", +) + +# Export a target generated by a native genrule target. +please_repo_e2e_test( + name = "export_native_genrule_bstmt", + plz_command = "plz export --output plz-out/plzexport //test:native_genrule", + expected_output = { + "plz-out/plzexport/test/BUILD_FILE": "test/BUILD_FILE:native_genrule", + }, + tool_content_checker = [":build_statement_checker"], + repo = "repo", +) diff --git a/test/export/repo/test/BUILD_FILE b/test/export/repo/test/BUILD_FILE new file mode 100644 index 000000000..e57512d48 --- /dev/null +++ b/test/export/repo/test/BUILD_FILE @@ -0,0 +1,8 @@ +# Start BStmt native_genrule +genrule( + name = "native_genrule", + srcs = ["file.txt"], + outs = ["file.wordcount"], + cmd = "wc $SRCS > $OUT", +) +# End BStmt diff --git a/test/export/repo/test/file.txt b/test/export/repo/test/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/repo/test/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_build_statement_content.sh b/test/export/test_build_statement_content.sh new file mode 100755 index 000000000..939638cab --- /dev/null +++ b/test/export/test_build_statement_content.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + + +gen_file=$1 +if ! test -f "$gen_file"; then + echo "$gen_file" doesnt exist + exit 1 +fi + +# Statement identifier of type path/file:name +stmt_identifier=$2 +# string BEFORE the last colon +file_path="${stmt_identifier%:*}" +# string AFTER the last colon +statement_name="${stmt_identifier##*:}" + +if ! test -f "$file_path"; then + echo "$file_path" doesnt exist + exit 1 +fi + +# Extract the block into a variable +ORIG_CONTENT=$(sed -n "/# Start BStmt ${statement_name}/,/# End BStmt/{ /# /d; p; }" "$file_path") + +if ! grep -Fq "$ORIG_CONTENT" "$gen_file"; then + printf '%s\n%s\n%s\n%s\n%s\n' \ + "${gen_file} doesnt contain" \ + "${ORIG_CONTENT}" \ + "---- it contains ----" \ + "$(cat "$gen_file")" \ + "---- EOF ----" + exit 1 +fi From 8d876812dcb310f819267ad12dd4b828f4fb8fc5 Mon Sep 17 00:00:00 2001 From: duarte Date: Thu, 19 Mar 2026 17:11:51 +0000 Subject: [PATCH 02/22] test: move to export_e2e build rule --- test/build_defs/test.build_defs | 7 ++- test/export/BUILD | 48 +++++++++++++++------ test/export/repo/test/BUILD_FILE | 4 +- test/export/test_build_statement_content.sh | 20 ++++----- 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index 33ab98369..c7b5df9bb 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -5,12 +5,13 @@ def please_repo_e2e_test( repo: str, data: dict={}, deps: list=[], + defer_cmd=[], tools: dict={}, + tool_content_checker = ["//test/build_defs:content_checker"], expected_failure: bool = False, expected_output: dict = {}, expect_output_contains: dict = {}, expect_output_doesnt_contain: dict = {}, - tool_content_checker = ["//test/build_defs:content_checker"], labels: list = [], ): plz_command = plz_command.replace("plz ", "$TOOLS_PLEASE ") @@ -32,6 +33,10 @@ def please_repo_e2e_test( if expect_output_doesnt_contain: test_cmd += [f'_STR="$(cat {o})" _SUBSTR="{c}" && if [ -z "${_STR##*$_SUBSTR*}" ]; then echo "$_STR"; exit 1; fi' for o, c in expect_output_doesnt_contain.items()] + # defer commands should be added last + if defer_cmd: + test_cmd += [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in defer_cmd] + test_cmd = ' && '.join(test_cmd) data["REPO"] = [repo] diff --git a/test/export/BUILD b/test/export/BUILD index 9ac48b353..bf483516b 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -1,22 +1,46 @@ subinclude("//test/build_defs") -plz_e2e_test( - name = "export_src_please_test", - cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", -) - sh_binary( name = "build_statement_checker", main = "test_build_statement_content.sh", ) +# Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) +# within the same test to avoid the overhead of exporting multiple times. +def please_export_e2e_test( + name:str, + export_target:str, + repo:str): + + EXPORT_DIR = "plz-out/plzexport" + please_target = "//" + export_target + file_path, target_name = export_target.split(":") + build_file = file_path + "/BUILD_FILE" + + return please_repo_e2e_test( + name = name, + repo = repo, + plz_command = f"plz export --output {EXPORT_DIR} {please_target}", + defer_cmd = [ + # Tests the contents of the exported BUILD file + f'$TOOLS_BUILD_STATEMENT_CHECKER "{EXPORT_DIR}/{build_file}" "{build_file}" "{target_name}"', + # Tests building the exported target + f'plz build --repo_root=$(plz query reporoot)/plz-out/plzexport "{please_target}"', + ], + tools = { + "BUILD_STATEMENT_CHECKER": "//test/export:build_statement_checker" + }, + ) + +# Generic catch-all test on internal repo. +plz_e2e_test( + name = "export_src_please_test", + cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", +) + # Export a target generated by a native genrule target. -please_repo_e2e_test( - name = "export_native_genrule_bstmt", - plz_command = "plz export --output plz-out/plzexport //test:native_genrule", - expected_output = { - "plz-out/plzexport/test/BUILD_FILE": "test/BUILD_FILE:native_genrule", - }, - tool_content_checker = [":build_statement_checker"], +please_export_e2e_test( + name = "export_native_genrule", + export_target = "test:native_genrule", repo = "repo", ) diff --git a/test/export/repo/test/BUILD_FILE b/test/export/repo/test/BUILD_FILE index e57512d48..e198e11f9 100644 --- a/test/export/repo/test/BUILD_FILE +++ b/test/export/repo/test/BUILD_FILE @@ -1,8 +1,8 @@ -# Start BStmt native_genrule +# Start BUILDStmt native_genrule genrule( name = "native_genrule", srcs = ["file.txt"], outs = ["file.wordcount"], cmd = "wc $SRCS > $OUT", ) -# End BStmt +# End BUILDStmt diff --git a/test/export/test_build_statement_content.sh b/test/export/test_build_statement_content.sh index 939638cab..92d4a054b 100755 --- a/test/export/test_build_statement_content.sh +++ b/test/export/test_build_statement_content.sh @@ -1,29 +1,25 @@ #!/usr/bin/env bash - gen_file=$1 +orig_file=$2 +stmt_identifier=$3 + if ! test -f "$gen_file"; then echo "$gen_file" doesnt exist exit 1 fi -# Statement identifier of type path/file:name -stmt_identifier=$2 -# string BEFORE the last colon -file_path="${stmt_identifier%:*}" -# string AFTER the last colon -statement_name="${stmt_identifier##*:}" - -if ! test -f "$file_path"; then - echo "$file_path" doesnt exist +if ! test -f "$orig_file"; then + echo "$orig_file" doesnt exist exit 1 fi # Extract the block into a variable -ORIG_CONTENT=$(sed -n "/# Start BStmt ${statement_name}/,/# End BStmt/{ /# /d; p; }" "$file_path") +ORIG_CONTENT=$(sed -n "/# Start BStmt ${stmt_identifier}/,/# End BStmt/{ /# /d; p; }" "$orig_file") if ! grep -Fq "$ORIG_CONTENT" "$gen_file"; then - printf '%s\n%s\n%s\n%s\n%s\n' \ + printf '%s\n%s\n%s\n%s\n%s\n%s\n' \ + "BUILD statements mismatch" \ "${gen_file} doesnt contain" \ "${ORIG_CONTENT}" \ "---- it contains ----" \ From 4a4144979aa3f7212136e75166c130579f94e61e Mon Sep 17 00:00:00 2001 From: duarte Date: Fri, 20 Mar 2026 15:50:27 +0000 Subject: [PATCH 03/22] test: add test for custom build def and rework build stmt checked build stmt checker now uses awk, supports more than one stmt associated with with a target and has a strict matching mode --- test/export/BUILD | 27 ++-- test/export/build_statement_checker.sh | 119 ++++++++++++++++++ test/export/repo/.plzconfig | 0 test/export/repo/test/BUILD_FILE | 8 -- test/export/repo/test_builtins/BUILD_FILE | 17 +++ .../repo/{test => test_builtins}/file.txt | 0 test/export/repo/test_custom_defs/BUILD_FILE | 11 ++ .../test_custom_defs/build_defs/BUILD_FILE | 5 + .../build_defs/custom.build_defs | 10 ++ test/export/repo/test_custom_defs/file.txt | 1 + test/export/test_build_statement_content.sh | 29 ----- 11 files changed, 183 insertions(+), 44 deletions(-) create mode 100755 test/export/build_statement_checker.sh create mode 100644 test/export/repo/.plzconfig delete mode 100644 test/export/repo/test/BUILD_FILE create mode 100644 test/export/repo/test_builtins/BUILD_FILE rename test/export/repo/{test => test_builtins}/file.txt (100%) create mode 100644 test/export/repo/test_custom_defs/BUILD_FILE create mode 100644 test/export/repo/test_custom_defs/build_defs/BUILD_FILE create mode 100644 test/export/repo/test_custom_defs/build_defs/custom.build_defs create mode 100644 test/export/repo/test_custom_defs/file.txt delete mode 100755 test/export/test_build_statement_content.sh diff --git a/test/export/BUILD b/test/export/BUILD index bf483516b..b47719a48 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -2,7 +2,7 @@ subinclude("//test/build_defs") sh_binary( name = "build_statement_checker", - main = "test_build_statement_content.sh", + main = "build_statement_checker.sh", ) # Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) @@ -10,22 +10,27 @@ sh_binary( def please_export_e2e_test( name:str, export_target:str, - repo:str): + repo:str, + strict_check_build_stmt:bool = False, + ): EXPORT_DIR = "plz-out/plzexport" + please_target = "//" + export_target file_path, target_name = export_target.split(":") build_file = file_path + "/BUILD_FILE" + strict_opt = "--strict" if strict_check_build_stmt else "" + return please_repo_e2e_test( name = name, repo = repo, plz_command = f"plz export --output {EXPORT_DIR} {please_target}", defer_cmd = [ # Tests the contents of the exported BUILD file - f'$TOOLS_BUILD_STATEMENT_CHECKER "{EXPORT_DIR}/{build_file}" "{build_file}" "{target_name}"', - # Tests building the exported target - f'plz build --repo_root=$(plz query reporoot)/plz-out/plzexport "{please_target}"', + f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"', + # Tests building the exported target which in turn ensures the sources are included + f'plz build --repo_root=$(plz query reporoot)/{EXPORT_DIR} "{please_target}"', ], tools = { "BUILD_STATEMENT_CHECKER": "//test/export:build_statement_checker" @@ -38,9 +43,17 @@ plz_e2e_test( cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", ) -# Export a target generated by a native genrule target. +# Export a target generated by a native genrule target and trim unused build statements. please_export_e2e_test( name = "export_native_genrule", - export_target = "test:native_genrule", + export_target = "test_builtins:native_genrule", + repo = "repo", + strict_check_build_stmt = True, +) + +# Export a target generated by a custom build def. +please_export_e2e_test( + name = "export_custom_target", + export_target = "test_custom_defs:custom_target", repo = "repo", ) diff --git a/test/export/build_statement_checker.sh b/test/export/build_statement_checker.sh new file mode 100755 index 000000000..f8bcb9c91 --- /dev/null +++ b/test/export/build_statement_checker.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +set -euo pipefail + +strict_match=false +exported_file="" +original_file="" +target_name="" + +while [[ "$#" -gt 0 ]]; do + case $1 in + --strict) + strict_match=true + shift + ;; + --exported) + exported_file=$2 + shift 2 + ;; + --original) + original_file=$2 + shift 2 + ;; + --target) + target_name=$2 + shift 2 + ;; + -*) + echo "Unknown option: $1" >&2 + exit 1 + ;; + *) + echo "Unknown argument: $1" >&2 + exit 1 + ;; + esac +done + +if [[ -z "$exported_file" ]] || [[ -z "$original_file" ]] || [[ -z "$target_name" ]]; then + echo "Usage: $0 [--strict] --exported --original --target " >&2 + exit 1 +fi + +if [[ ! -f "$exported_file" ]]; then + echo "$exported_file doesnt exist" >&2 + exit 1 +fi + +if [[ ! -f "$original_file" ]]; then + echo "$original_file doesnt exist" >&2 + exit 1 +fi + +readonly START_DELIM="# BUILD_STMT_START" +readonly END_DELIM="# BUILD_STMT_END" + +# Using awk to extract statement blocks directly into an array. +blocks=() +while IFS= read -r -d '' block; do + blocks+=("$block") +done < <(awk -v id="$target_name" -v start_delim="$START_DELIM" -v end_delim="$END_DELIM" ' + BEGIN { in_block = 0; block = "" } + $0 == start_delim " " id { + in_block = 1; + block = ""; + next; + } + $0 == end_delim { + if (in_block) { + in_block = 0; + printf "%s\0", block; + } + next; + } + in_block { + block = block ? block "\n" $0 : $0 + } +' "$original_file") + +if [[ ${#blocks[@]} -eq 0 ]]; then + echo "Failed to pull original content for $target_name" >&2 + exit 1 +fi + +# Ensure that ALL required blocks are present in the generated file +for block_content in "${blocks[@]}"; do + if ! grep -Fq "$block_content" "$exported_file"; then + printf '%s\n%s\n%s\n%s\n%s\n%s\n' \ + "BUILD statements mismatch" \ + "${exported_file} doesnt contain" \ + "${block_content}" \ + "---- it contains ----" \ + "$(cat "$exported_file")" \ + "---- EOF ----" >&2 + exit 1 + fi +done + +# If --strict is enabled, ensure ONLY these blocks are present +# (ignoring all whitespace, newlines and comments). +if [[ "$strict_match" == true ]]; then + concatenated_blocks="" + for block_content in "${blocks[@]}"; do + concatenated_blocks="${concatenated_blocks}${block_content}" + done + + stripped_blocks=$(echo -n "$concatenated_blocks" | sed 's/#.*//' | tr -d ' \t\n\r') + stripped_exported_file=$(sed 's/#.*//' "$exported_file" | tr -d ' \t\n\r') + + if [[ "$stripped_blocks" != "$stripped_exported_file" ]]; then + printf '%s\n' "Strict match failed: exported file contains extra or out-of-order content." >&2 + printf '%s\n' "---- Expected (stripped) ----" >&2 + printf '%s\n' "$stripped_blocks" >&2 + printf '%s\n' "---- Got (stripped) ----" >&2 + printf '%s\n' "$stripped_exported_file" >&2 + exit 1 + fi +fi + +exit 0 diff --git a/test/export/repo/.plzconfig b/test/export/repo/.plzconfig new file mode 100644 index 000000000..e69de29bb diff --git a/test/export/repo/test/BUILD_FILE b/test/export/repo/test/BUILD_FILE deleted file mode 100644 index e198e11f9..000000000 --- a/test/export/repo/test/BUILD_FILE +++ /dev/null @@ -1,8 +0,0 @@ -# Start BUILDStmt native_genrule -genrule( - name = "native_genrule", - srcs = ["file.txt"], - outs = ["file.wordcount"], - cmd = "wc $SRCS > $OUT", -) -# End BUILDStmt diff --git a/test/export/repo/test_builtins/BUILD_FILE b/test/export/repo/test_builtins/BUILD_FILE new file mode 100644 index 000000000..c533d280d --- /dev/null +++ b/test/export/repo/test_builtins/BUILD_FILE @@ -0,0 +1,17 @@ +# BUILD_STMT_START native_genrule +genrule( + name = "native_genrule", + srcs = ["file.txt"], + outs = ["file.wordcount"], + cmd = "wc $SRCS > $OUT", +) +# BUILD_STMT_END + + +# Du mmy target to be trimmed +genrule( + name = "dummy", + srcs = ["file.txt"], + outs = ["dummy"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/repo/test/file.txt b/test/export/repo/test_builtins/file.txt similarity index 100% rename from test/export/repo/test/file.txt rename to test/export/repo/test_builtins/file.txt diff --git a/test/export/repo/test_custom_defs/BUILD_FILE b/test/export/repo/test_custom_defs/BUILD_FILE new file mode 100644 index 000000000..df8819489 --- /dev/null +++ b/test/export/repo/test_custom_defs/BUILD_FILE @@ -0,0 +1,11 @@ +# BUILD_STMT_START custom_target +subinclude("//test_custom_defs/build_defs") +# BUILD_STMT_END + +# BUILD_STMT_START custom_target +simple_custom_target( + name = "custom_target", + srcs = ["file.txt"], + outs = ["file.out"], +) +# BUILD_STMT_END diff --git a/test/export/repo/test_custom_defs/build_defs/BUILD_FILE b/test/export/repo/test_custom_defs/build_defs/BUILD_FILE new file mode 100644 index 000000000..cf7d4a898 --- /dev/null +++ b/test/export/repo/test_custom_defs/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "build_defs", + srcs = ["custom.build_defs"], + visibility = ["//test_custom_defs/..."], +) diff --git a/test/export/repo/test_custom_defs/build_defs/custom.build_defs b/test/export/repo/test_custom_defs/build_defs/custom.build_defs new file mode 100644 index 000000000..8fe3a6021 --- /dev/null +++ b/test/export/repo/test_custom_defs/build_defs/custom.build_defs @@ -0,0 +1,10 @@ +def simple_custom_target( + name:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "cat $SRCS > $OUT", + ) diff --git a/test/export/repo/test_custom_defs/file.txt b/test/export/repo/test_custom_defs/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/repo/test_custom_defs/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_build_statement_content.sh b/test/export/test_build_statement_content.sh deleted file mode 100755 index 92d4a054b..000000000 --- a/test/export/test_build_statement_content.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -gen_file=$1 -orig_file=$2 -stmt_identifier=$3 - -if ! test -f "$gen_file"; then - echo "$gen_file" doesnt exist - exit 1 -fi - -if ! test -f "$orig_file"; then - echo "$orig_file" doesnt exist - exit 1 -fi - -# Extract the block into a variable -ORIG_CONTENT=$(sed -n "/# Start BStmt ${stmt_identifier}/,/# End BStmt/{ /# /d; p; }" "$orig_file") - -if ! grep -Fq "$ORIG_CONTENT" "$gen_file"; then - printf '%s\n%s\n%s\n%s\n%s\n%s\n' \ - "BUILD statements mismatch" \ - "${gen_file} doesnt contain" \ - "${ORIG_CONTENT}" \ - "---- it contains ----" \ - "$(cat "$gen_file")" \ - "---- EOF ----" - exit 1 -fi From 15ea8ce00505f033dfe58379a2e8862df0badc23 Mon Sep 17 00:00:00 2001 From: duarte Date: Mon, 23 Mar 2026 11:56:07 +0000 Subject: [PATCH 04/22] test: targets with deps, multiple targets, export outputs and notrim --- test/export/BUILD | 92 +++++++++++++++------ test/export/repo/test_deps/BUILD_FILE | 21 +++++ test/export/repo/test_deps/file1.txt | 1 + test/export/repo/test_deps/file2.txt | 1 + test/export/repo/test_deps_other/BUILD_FILE | 8 ++ test/export/repo/test_multiple/BUILD_FILE | 17 ++++ test/export/repo/test_multiple/file1.txt | 1 + test/export/repo/test_multiple/file2.txt | 1 + test/export/repo/test_notrim/BUILD_FILE | 17 ++++ test/export/repo/test_notrim/file1.txt | 1 + test/export/repo/test_notrim/file2.txt | 1 + test/export/repo/test_outputs/BUILD_FILE | 5 ++ 12 files changed, 143 insertions(+), 23 deletions(-) create mode 100644 test/export/repo/test_deps/BUILD_FILE create mode 100644 test/export/repo/test_deps/file1.txt create mode 100644 test/export/repo/test_deps/file2.txt create mode 100644 test/export/repo/test_deps_other/BUILD_FILE create mode 100644 test/export/repo/test_multiple/BUILD_FILE create mode 100644 test/export/repo/test_multiple/file1.txt create mode 100644 test/export/repo/test_multiple/file2.txt create mode 100644 test/export/repo/test_notrim/BUILD_FILE create mode 100644 test/export/repo/test_notrim/file1.txt create mode 100644 test/export/repo/test_notrim/file2.txt create mode 100644 test/export/repo/test_outputs/BUILD_FILE diff --git a/test/export/BUILD b/test/export/BUILD index b47719a48..5e5a01d14 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -9,44 +9,44 @@ sh_binary( # within the same test to avoid the overhead of exporting multiple times. def please_export_e2e_test( name:str, - export_target:str, + export_targets:list, repo:str, - strict_check_build_stmt:bool = False, - ): - + strict_check_build_stmt:bool=False): EXPORT_DIR = "plz-out/plzexport" - please_target = "//" + export_target - file_path, target_name = export_target.split(":") - build_file = file_path + "/BUILD_FILE" + please_targets = ["//" + t for t in export_targets] + defer_cmd = [] strict_opt = "--strict" if strict_check_build_stmt else "" + for export_target in export_targets: + file_path, target_name = export_target.split(":") + build_file = file_path + "/BUILD_FILE" + + # Tests the contents of the exported BUILD file + defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] + + build_targets_str = " ".join([f'"{t}"' for t in please_targets]) + + # Tests building the exported target which in turn ensures the sources are included + defer_cmd += [f"plz build --repo_root=$(plz query reporoot)/{EXPORT_DIR} {build_targets_str}"] + + plz_command_targets = " ".join(please_targets) + return please_repo_e2e_test( name = name, + defer_cmd = defer_cmd, + plz_command = f"plz export --output {EXPORT_DIR} {plz_command_targets}", repo = repo, - plz_command = f"plz export --output {EXPORT_DIR} {please_target}", - defer_cmd = [ - # Tests the contents of the exported BUILD file - f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"', - # Tests building the exported target which in turn ensures the sources are included - f'plz build --repo_root=$(plz query reporoot)/{EXPORT_DIR} "{please_target}"', - ], tools = { - "BUILD_STATEMENT_CHECKER": "//test/export:build_statement_checker" + "BUILD_STATEMENT_CHECKER": "//test/export:build_statement_checker", }, ) -# Generic catch-all test on internal repo. -plz_e2e_test( - name = "export_src_please_test", - cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", -) - # Export a target generated by a native genrule target and trim unused build statements. please_export_e2e_test( name = "export_native_genrule", - export_target = "test_builtins:native_genrule", + export_targets = ["test_builtins:native_genrule"], repo = "repo", strict_check_build_stmt = True, ) @@ -54,6 +54,52 @@ please_export_e2e_test( # Export a target generated by a custom build def. please_export_e2e_test( name = "export_custom_target", - export_target = "test_custom_defs:custom_target", + export_targets = ["test_custom_defs:custom_target"], + repo = "repo", +) + +# Export a target that depends on another target. +please_export_e2e_test( + name = "export_deps", + export_targets = ["test_deps:dep2"], + repo = "repo", +) + +# Test multiple targets. +please_export_e2e_test( + name = "export_multiple", + export_targets = [ + "test_multiple:target1", + "test_multiple:target2", + ], + repo = "repo", +) + +# Generic catch-all test on internal repo. +plz_e2e_test( + name = "export_src_please_test", + cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", +) + +# Test outputs export. +please_repo_e2e_test( + name = "export_outputs", + defer_cmd = [ + 'test -f "plz-out/plzexport/some_output.txt"', + 'test ! -f "plz-out/plzexport/BUILD_FILE"', + ], + plz_command = "plz export outputs --output plz-out/plzexport //test_outputs:out_target", + repo = "repo", +) + +# Test --notrim flag. +please_repo_e2e_test( + name = "export_notrim", + defer_cmd = [ + 'test -f "plz-out/plzexport/test_notrim/file2.txt"', + 'test -f "plz-out/plzexport/test_notrim/BUILD_FILE"', + 'grep -q \'name = "unrelated"\' "plz-out/plzexport/test_notrim/BUILD_FILE"', + ], + plz_command = "plz export --notrim --output plz-out/plzexport //test_notrim:target1", repo = "repo", ) diff --git a/test/export/repo/test_deps/BUILD_FILE b/test/export/repo/test_deps/BUILD_FILE new file mode 100644 index 000000000..a6578830a --- /dev/null +++ b/test/export/repo/test_deps/BUILD_FILE @@ -0,0 +1,21 @@ +# BUILD_STMT_START dep1 +genrule( + name = "dep1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) +# BUILD_STMT_END + +# BUILD_STMT_START dep2 +genrule( + name = "dep2", + srcs = [ + "file2.txt", + ":dep1", + "//test_deps_other:other_target", + ], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) +# BUILD_STMT_END \ No newline at end of file diff --git a/test/export/repo/test_deps/file1.txt b/test/export/repo/test_deps/file1.txt new file mode 100644 index 000000000..e2129701f --- /dev/null +++ b/test/export/repo/test_deps/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/test/export/repo/test_deps/file2.txt b/test/export/repo/test_deps/file2.txt new file mode 100644 index 000000000..30d67d467 --- /dev/null +++ b/test/export/repo/test_deps/file2.txt @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/test/export/repo/test_deps_other/BUILD_FILE b/test/export/repo/test_deps_other/BUILD_FILE new file mode 100644 index 000000000..1bf3ee556 --- /dev/null +++ b/test/export/repo/test_deps_other/BUILD_FILE @@ -0,0 +1,8 @@ +# BUILD_STMT_START other_target +genrule( + name = "other_target", + outs = ["other.txt"], + cmd = "echo 'other' > $OUT", + visibility = ["PUBLIC"], +) +# BUILD_STMT_END \ No newline at end of file diff --git a/test/export/repo/test_multiple/BUILD_FILE b/test/export/repo/test_multiple/BUILD_FILE new file mode 100644 index 000000000..29a248447 --- /dev/null +++ b/test/export/repo/test_multiple/BUILD_FILE @@ -0,0 +1,17 @@ +# BUILD_STMT_START target1 +genrule( + name = "target1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) +# BUILD_STMT_END + +# BUILD_STMT_START target2 +genrule( + name = "target2", + srcs = ["file2.txt"], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) +# BUILD_STMT_END \ No newline at end of file diff --git a/test/export/repo/test_multiple/file1.txt b/test/export/repo/test_multiple/file1.txt new file mode 100644 index 000000000..08219db9b --- /dev/null +++ b/test/export/repo/test_multiple/file1.txt @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/test/export/repo/test_multiple/file2.txt b/test/export/repo/test_multiple/file2.txt new file mode 100644 index 000000000..30d67d467 --- /dev/null +++ b/test/export/repo/test_multiple/file2.txt @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/test/export/repo/test_notrim/BUILD_FILE b/test/export/repo/test_notrim/BUILD_FILE new file mode 100644 index 000000000..e6fd02e36 --- /dev/null +++ b/test/export/repo/test_notrim/BUILD_FILE @@ -0,0 +1,17 @@ +# BUILD_STMT_START target1 +genrule( + name = "target1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) +# BUILD_STMT_END + +# BUILD_STMT_START unrelated +genrule( + name = "unrelated", + srcs = ["file2.txt"], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) +# BUILD_STMT_END \ No newline at end of file diff --git a/test/export/repo/test_notrim/file1.txt b/test/export/repo/test_notrim/file1.txt new file mode 100644 index 000000000..08219db9b --- /dev/null +++ b/test/export/repo/test_notrim/file1.txt @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/test/export/repo/test_notrim/file2.txt b/test/export/repo/test_notrim/file2.txt new file mode 100644 index 000000000..30d67d467 --- /dev/null +++ b/test/export/repo/test_notrim/file2.txt @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/test/export/repo/test_outputs/BUILD_FILE b/test/export/repo/test_outputs/BUILD_FILE new file mode 100644 index 000000000..9aeaaff12 --- /dev/null +++ b/test/export/repo/test_outputs/BUILD_FILE @@ -0,0 +1,5 @@ +genrule( + name = "out_target", + outs = ["some_output.txt"], + cmd = "echo 'hello world' > $OUT", +) \ No newline at end of file From 53629cab3a7423e4764ed9f3945f77b2629a4242 Mon Sep 17 00:00:00 2001 From: duarte Date: Tue, 24 Mar 2026 11:46:52 +0000 Subject: [PATCH 05/22] test: export go binary including rework of build_def for multiple plz commands --- test/build_defs/test.build_defs | 18 +++--- test/export/BUILD | 55 +++++++++++++------ test/export/repo_go/.plzconfig | 6 ++ test/export/repo_go/plugins/BUILD_FILE | 5 ++ test/export/repo_go/test_go_bin/BUILD_FILE | 10 ++++ test/export/repo_go/test_go_bin/main.go | 7 +++ test/export/repo_go/third_party/go/BUILD_FILE | 5 ++ 7 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 test/export/repo_go/.plzconfig create mode 100644 test/export/repo_go/plugins/BUILD_FILE create mode 100644 test/export/repo_go/test_go_bin/BUILD_FILE create mode 100644 test/export/repo_go/test_go_bin/main.go create mode 100644 test/export/repo_go/third_party/go/BUILD_FILE diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index c7b5df9bb..959c5cc4f 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -1,7 +1,7 @@ # Runs e2e tests against please in a specified repo def please_repo_e2e_test( name: str, - plz_command: str, + plz_command: str|list, repo: str, data: dict={}, deps: list=[], @@ -14,16 +14,20 @@ def please_repo_e2e_test( expect_output_doesnt_contain: dict = {}, labels: list = [], ): - plz_command = plz_command.replace("plz ", "$TOOLS_PLEASE ") - if expected_failure: - plz_command += "; [ ! $? -eq 0 ]" - test_cmd = [ "cp $DATA_BASE_CONFIG $DATA_REPO", "cd $DATA_REPO", - plz_command, ] + if isinstance(plz_command, str): + plz_command = [plz_command] + + for cmd in plz_command: + cmd.replace("plz ", "$TOOLS_PLEASE ") + if expected_failure: + cmd += "; [ ! $? -eq 0 ]" + test_cmd += [cmd] + if expected_output: test_cmd += [f"$TOOLS_CONTENT_CHECKER '{o}' '{c}'" for o, c in expected_output.items()] @@ -35,7 +39,7 @@ def please_repo_e2e_test( # defer commands should be added last if defer_cmd: - test_cmd += [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in defer_cmd] + test_cmd += defer_cmd test_cmd = ' && '.join(test_cmd) diff --git a/test/export/BUILD b/test/export/BUILD index 5e5a01d14..764081114 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -8,39 +8,49 @@ sh_binary( # Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) # within the same test to avoid the overhead of exporting multiple times. def please_export_e2e_test( - name:str, - export_targets:list, - repo:str, - strict_check_build_stmt:bool=False): - EXPORT_DIR = "plz-out/plzexport" + name: str, + export_targets: list, + repo: str, + include_go: bool = False, + strict_check_build_stmt: bool = False, # requires match for all BUILD statements in exported file + EXPORT_DIR = "plz-out/plzexport", + BUILD_FILE = "BUILD_FILE" + ): please_targets = ["//" + t for t in export_targets] - - defer_cmd = [] + plz_command_targets = " ".join(please_targets) + tools = {} + config_override = [] strict_opt = "--strict" if strict_check_build_stmt else "" + if include_go: + config_override += ["-o plugin.go.gotool:$TOOLS_GO"] + tools["GO"] = [CONFIG.GO.GO_TOOL] + config_override = " ".join(config_override) + + plz_command = [ + # Export command + f"plz {config_override} export --output {EXPORT_DIR} {plz_command_targets}", + # Tests building the exported target which in turn ensures the sources are included + f"plz {config_override} build --repo_root=$(plz query reporoot)/{EXPORT_DIR} {plz_command_targets}" + ] + + defer_cmd = [] for export_target in export_targets: file_path, target_name = export_target.split(":") - build_file = file_path + "/BUILD_FILE" + build_file = f"{file_path}/{BUILD_FILE}" # Tests the contents of the exported BUILD file defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] + tools["BUILD_STATEMENT_CHECKER"] = "//test/export:build_statement_checker" - build_targets_str = " ".join([f'"{t}"' for t in please_targets]) - - # Tests building the exported target which in turn ensures the sources are included - defer_cmd += [f"plz build --repo_root=$(plz query reporoot)/{EXPORT_DIR} {build_targets_str}"] - - plz_command_targets = " ".join(please_targets) return please_repo_e2e_test( name = name, defer_cmd = defer_cmd, - plz_command = f"plz export --output {EXPORT_DIR} {plz_command_targets}", + plz_command = plz_command, repo = repo, - tools = { - "BUILD_STATEMENT_CHECKER": "//test/export:build_statement_checker", - }, + tools = tools, ) # Export a target generated by a native genrule target and trim unused build statements. @@ -75,6 +85,15 @@ please_export_e2e_test( repo = "repo", ) +# Test go binary target. +please_export_e2e_test( + name = "export_go_binary", + export_targets = ["test_go_bin:dummy"], + repo = "repo_go", + include_go = True, + strict_check_build_stmt = True, +) + # Generic catch-all test on internal repo. plz_e2e_test( name = "export_src_please_test", diff --git a/test/export/repo_go/.plzconfig b/test/export/repo_go/.plzconfig new file mode 100644 index 000000000..51a718f2f --- /dev/null +++ b/test/export/repo_go/.plzconfig @@ -0,0 +1,6 @@ +[Parse] +BuildFileName = BUILD # We override this in the e2e test profile and the subrepo has BUILD files not BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/repo_go/plugins/BUILD_FILE b/test/export/repo_go/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/repo_go/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/repo_go/test_go_bin/BUILD_FILE b/test/export/repo_go/test_go_bin/BUILD_FILE new file mode 100644 index 000000000..3260bf080 --- /dev/null +++ b/test/export/repo_go/test_go_bin/BUILD_FILE @@ -0,0 +1,10 @@ +# BUILD_STMT_START dummy +subinclude("///go//build_defs:go") +# BUILD_STMT_END + +# BUILD_STMT_START dummy +go_binary( + name = "dummy", + srcs = ["main.go"], +) +# BUILD_STMT_END diff --git a/test/export/repo_go/test_go_bin/main.go b/test/export/repo_go/test_go_bin/main.go new file mode 100644 index 000000000..155420a26 --- /dev/null +++ b/test/export/repo_go/test_go_bin/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Print("Woop Woop") +} diff --git a/test/export/repo_go/third_party/go/BUILD_FILE b/test/export/repo_go/third_party/go/BUILD_FILE new file mode 100644 index 000000000..7e2be50ca --- /dev/null +++ b/test/export/repo_go/third_party/go/BUILD_FILE @@ -0,0 +1,5 @@ +subinclude("///go//build_defs:go") + +go_stdlib( + name = "std", +) From d60973d39e7b9fab8e0a46ce394c2adafb5f7345 Mon Sep 17 00:00:00 2001 From: duarte Date: Tue, 24 Mar 2026 13:38:54 +0000 Subject: [PATCH 06/22] test: genrule with go subrepo and go binary with go dependency --- test/export/BUILD | 20 ++++++++++++++++- test/export/repo_go/test_go_dep/BUILD_FILE | 22 +++++++++++++++++++ test/export/repo_go/test_go_dep/main.go | 11 ++++++++++ test/export/repo_go/third_party/go/BUILD_FILE | 7 ++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/export/repo_go/test_go_dep/BUILD_FILE create mode 100644 test/export/repo_go/test_go_dep/main.go diff --git a/test/export/BUILD b/test/export/BUILD index 764081114..15a9fed2f 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -44,7 +44,6 @@ def please_export_e2e_test( defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] tools["BUILD_STATEMENT_CHECKER"] = "//test/export:build_statement_checker" - return please_repo_e2e_test( name = name, defer_cmd = defer_cmd, @@ -94,6 +93,25 @@ please_export_e2e_test( strict_check_build_stmt = True, ) +# Test native target with go third_party dependency. +please_export_e2e_test( + name = "export_native_target_with_go_dep", + export_targets = ["test_go_dep:genrule_go_dep"], + repo = "repo_go", + include_go = True, + # TODO Enable strict check after after support for trimming subincludes #3496 + # strict_check_build_stmt = True, +) + +# Test go target with go third_party dependency. +please_export_e2e_test( + name = "export_go_target_with_go_dep", + export_targets = ["test_go_dep:bin_go_dep"], + repo = "repo_go", + include_go = True, + strict_check_build_stmt = True, +) + # Generic catch-all test on internal repo. plz_e2e_test( name = "export_src_please_test", diff --git a/test/export/repo_go/test_go_dep/BUILD_FILE b/test/export/repo_go/test_go_dep/BUILD_FILE new file mode 100644 index 000000000..6ecfacc22 --- /dev/null +++ b/test/export/repo_go/test_go_dep/BUILD_FILE @@ -0,0 +1,22 @@ +# BUILD_STMT_START genrule_go_dep +genrule( + name = "genrule_go_dep", + srcs = ["///third_party/go/github.com_google_go-cmp//cmp"], + outs = ["out.txt"], + cmd = "ls $SRCS > $OUT", +) +# BUILD_STMT_END + +# BUILD_STMT_START bin_go_dep +subinclude("///go//build_defs:go") +# BUILD_STMT_END + +# BUILD_STMT_START bin_go_dep +go_binary( + name = "bin_go_dep", + srcs = ["main.go"], + deps = [ + "///third_party/go/github.com_google_go-cmp//cmp", + ], +) +# BUILD_STMT_END diff --git a/test/export/repo_go/test_go_dep/main.go b/test/export/repo_go/test_go_dep/main.go new file mode 100644 index 000000000..0853120a2 --- /dev/null +++ b/test/export/repo_go/test_go_dep/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/google/go-cmp/cmp" +) + +func main() { + fmt.Print(cmp.Equal(1, 1)) +} diff --git a/test/export/repo_go/third_party/go/BUILD_FILE b/test/export/repo_go/third_party/go/BUILD_FILE index 7e2be50ca..0af523288 100644 --- a/test/export/repo_go/third_party/go/BUILD_FILE +++ b/test/export/repo_go/third_party/go/BUILD_FILE @@ -1,5 +1,12 @@ subinclude("///go//build_defs:go") +package(default_visibility = ["PUBLIC"]) + go_stdlib( name = "std", ) + +go_repo( + module = "github.com/google/go-cmp", + version = "v0.5.6", +) From c7bf7129733b3f05f13e886c05ac4e1f2ce4d3cb Mon Sep 17 00:00:00 2001 From: duarte Date: Tue, 24 Mar 2026 14:41:07 +0000 Subject: [PATCH 07/22] test: build def with children targets --- test/export/BUILD | 24 +++++++++++++++---- test/export/repo/test_custom_defs/BUILD_FILE | 24 +++++++++++++++---- .../test_custom_defs/build_defs/BUILD_FILE | 10 ++++++-- .../{custom.build_defs => simple.build_defs} | 0 .../build_defs/standard_children.build_defs | 17 +++++++++++++ 5 files changed, 64 insertions(+), 11 deletions(-) rename test/export/repo/test_custom_defs/build_defs/{custom.build_defs => simple.build_defs} (100%) create mode 100644 test/export/repo/test_custom_defs/build_defs/standard_children.build_defs diff --git a/test/export/BUILD b/test/export/BUILD index 15a9fed2f..97813cef3 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -11,6 +11,7 @@ def please_export_e2e_test( name: str, export_targets: list, repo: str, + cmd_on_export: list = [], include_go: bool = False, strict_check_build_stmt: bool = False, # requires match for all BUILD statements in exported file EXPORT_DIR = "plz-out/plzexport", @@ -32,8 +33,8 @@ def please_export_e2e_test( # Export command f"plz {config_override} export --output {EXPORT_DIR} {plz_command_targets}", # Tests building the exported target which in turn ensures the sources are included - f"plz {config_override} build --repo_root=$(plz query reporoot)/{EXPORT_DIR} {plz_command_targets}" - ] + f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} build {plz_command_targets}" + ] + [ f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} {cmd}" for cmd in cmd_on_export] defer_cmd = [] for export_target in export_targets: @@ -62,9 +63,24 @@ please_export_e2e_test( # Export a target generated by a custom build def. please_export_e2e_test( - name = "export_custom_target", - export_targets = ["test_custom_defs:custom_target"], + name = "export_simple_custom_target", + export_targets = ["test_custom_defs:simple_custom_target"], repo = "repo", + # TODO Enable strict check after after support for trimming subincludes #3496 + # strict_check_build_stmt = True, +) + +# Export a target generated by a custom build def. +please_export_e2e_test( + name = "export_standard_children_custom_target", + export_targets = ["test_custom_defs:standard_children_custom_target"], + repo = "repo", + cmd_on_export = [ + # Child of build def + "build //test_custom_defs:standard_children_custom_target#child", + ], + # TODO Enable strict check after after support for trimming subincludes #3496 + # strict_check_build_stmt = True, ) # Export a target that depends on another target. diff --git a/test/export/repo/test_custom_defs/BUILD_FILE b/test/export/repo/test_custom_defs/BUILD_FILE index df8819489..241b18d6b 100644 --- a/test/export/repo/test_custom_defs/BUILD_FILE +++ b/test/export/repo/test_custom_defs/BUILD_FILE @@ -1,11 +1,25 @@ -# BUILD_STMT_START custom_target -subinclude("//test_custom_defs/build_defs") +# BUILD_STMT_START simple_custom_target +subinclude("//test_custom_defs/build_defs:simple_build_def") # BUILD_STMT_END -# BUILD_STMT_START custom_target +# BUILD_STMT_START simple_custom_target simple_custom_target( - name = "custom_target", + name = "simple_custom_target", srcs = ["file.txt"], - outs = ["file.out"], + outs = ["file_simple.out"], +) +# BUILD_STMT_END + + +# BUILD_STMT_START standard_children_custom_target +subinclude("//test_custom_defs/build_defs:standard_children_build_def") +# BUILD_STMT_END + +# BUILD_STMT_START standard_children_custom_target +standard_children_custom_target( + name = "standard_children_custom_target", + srcs = ["file.txt"], + outs = ["file_standard.out"], + outs_child = ["file_child.out"], ) # BUILD_STMT_END diff --git a/test/export/repo/test_custom_defs/build_defs/BUILD_FILE b/test/export/repo/test_custom_defs/build_defs/BUILD_FILE index cf7d4a898..db512e3a8 100644 --- a/test/export/repo/test_custom_defs/build_defs/BUILD_FILE +++ b/test/export/repo/test_custom_defs/build_defs/BUILD_FILE @@ -1,5 +1,11 @@ filegroup( - name = "build_defs", - srcs = ["custom.build_defs"], + name = "simple_build_def", + srcs = ["simple.build_defs"], + visibility = ["//test_custom_defs/..."], +) + +filegroup( + name = "standard_children_build_def", + srcs = ["standard_children.build_defs"], visibility = ["//test_custom_defs/..."], ) diff --git a/test/export/repo/test_custom_defs/build_defs/custom.build_defs b/test/export/repo/test_custom_defs/build_defs/simple.build_defs similarity index 100% rename from test/export/repo/test_custom_defs/build_defs/custom.build_defs rename to test/export/repo/test_custom_defs/build_defs/simple.build_defs diff --git a/test/export/repo/test_custom_defs/build_defs/standard_children.build_defs b/test/export/repo/test_custom_defs/build_defs/standard_children.build_defs new file mode 100644 index 000000000..081154550 --- /dev/null +++ b/test/export/repo/test_custom_defs/build_defs/standard_children.build_defs @@ -0,0 +1,17 @@ +def standard_children_custom_target( + name:str, + srcs:list=[], + outs:list=[], + outs_child:list=[]): + genrule( + name = f"{name}#child", + srcs = srcs, + outs = outs_child, + cmd = "echo 'child' > $OUT && cat $SRCS >> $OUT ", + ) + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "echo 'main' > $OUT && cat $SRCS >> $OUT ", + ) From a164a9012e485215339fd06fad59d1b3293068e7 Mon Sep 17 00:00:00 2001 From: duarte Date: Tue, 24 Mar 2026 15:30:09 +0000 Subject: [PATCH 08/22] test: preload build def --- test/export/BUILD | 30 +++++++++++++++++++ test/export/repo_preload/.plzconfig | 2 ++ .../export/repo_preload/build_defs/BUILD_FILE | 5 ++++ .../build_defs/preloaded.build_defs | 11 +++++++ test/export/repo_preload/test/BUILD_FILE | 16 ++++++++++ test/export/repo_preload/test/file.txt | 1 + 6 files changed, 65 insertions(+) create mode 100644 test/export/repo_preload/.plzconfig create mode 100644 test/export/repo_preload/build_defs/BUILD_FILE create mode 100644 test/export/repo_preload/build_defs/preloaded.build_defs create mode 100644 test/export/repo_preload/test/BUILD_FILE create mode 100644 test/export/repo_preload/test/file.txt diff --git a/test/export/BUILD b/test/export/BUILD index 97813cef3..870712f3c 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -12,6 +12,7 @@ def please_export_e2e_test( export_targets: list, repo: str, cmd_on_export: list = [], + expect_output_contains: dict = {}, include_go: bool = False, strict_check_build_stmt: bool = False, # requires match for all BUILD statements in exported file EXPORT_DIR = "plz-out/plzexport", @@ -45,12 +46,19 @@ def please_export_e2e_test( defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] tools["BUILD_STATEMENT_CHECKER"] = "//test/export:build_statement_checker" + if expect_output_contains: + updated_expect_output = {} + for key, val in expect_output_contains.items(): + updated_expect_output[f"{EXPORT_DIR}/{key}"] = val + expect_output_contains = updated_expect_output + return please_repo_e2e_test( name = name, defer_cmd = defer_cmd, plz_command = plz_command, repo = repo, tools = tools, + expect_output_contains = expect_output_contains, ) # Export a target generated by a native genrule target and trim unused build statements. @@ -100,6 +108,28 @@ please_export_e2e_test( repo = "repo", ) +# Export a target from a repo that preloads a build def. +# This test purposely doesn't use the custom def but checks that the source files are still included. +please_export_e2e_test( + name = "export_preload_genrule", + export_targets = ["test:native_not_including_preloaded"], + repo = "repo_preload", + strict_check_build_stmt = True, + expect_output_contains = { + # validating that export includes preloaded build def files + "build_defs/preloaded.build_defs": "preloaded_target", + "build_defs/BUILD_FILE": "preloaded_build_def", + } +) + +# Export a custom target from a repo that preloads the build def used. +please_export_e2e_test( + name = "export_preload_use_preloaded_def", + export_targets = ["test:use_preloaded_def"], + repo = "repo_preload", + strict_check_build_stmt = True, +) + # Test go binary target. please_export_e2e_test( name = "export_go_binary", diff --git a/test/export/repo_preload/.plzconfig b/test/export/repo_preload/.plzconfig new file mode 100644 index 000000000..c77f93d75 --- /dev/null +++ b/test/export/repo_preload/.plzconfig @@ -0,0 +1,2 @@ +[parse] +preloadsubincludes = //build_defs:preloaded_build_def diff --git a/test/export/repo_preload/build_defs/BUILD_FILE b/test/export/repo_preload/build_defs/BUILD_FILE new file mode 100644 index 000000000..b3d36cb71 --- /dev/null +++ b/test/export/repo_preload/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "preloaded_build_def", + srcs = ["preloaded.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/repo_preload/build_defs/preloaded.build_defs b/test/export/repo_preload/build_defs/preloaded.build_defs new file mode 100644 index 000000000..1666afbd0 --- /dev/null +++ b/test/export/repo_preload/build_defs/preloaded.build_defs @@ -0,0 +1,11 @@ +def preloaded_target( + name:str, + cmd:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = f"{cmd} $SRCS > $OUT", + ) diff --git a/test/export/repo_preload/test/BUILD_FILE b/test/export/repo_preload/test/BUILD_FILE new file mode 100644 index 000000000..1b821ed99 --- /dev/null +++ b/test/export/repo_preload/test/BUILD_FILE @@ -0,0 +1,16 @@ +# BUILD_STMT_START native_not_including_preloaded +genrule( + name = "native_not_including_preloaded", + outs = ["file_no_preload.out"], + cmd = "echo 'woosh' > $OUT", +) +# BUILD_STMT_END + +# BUILD_STMT_START use_preloaded_def +preloaded_target( + name = "use_preloaded_def", + srcs = ["file.txt"], + outs = ["file_w_preload.out"], + cmd = "cat", +) +# BUILD_STMT_END diff --git a/test/export/repo_preload/test/file.txt b/test/export/repo_preload/test/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/repo_preload/test/file.txt @@ -0,0 +1 @@ +Test source file From 5038929672c85d6b9970fd6c42701d534053f3ef Mon Sep 17 00:00:00 2001 From: duarte Date: Tue, 24 Mar 2026 15:43:41 +0000 Subject: [PATCH 09/22] lint: run plz format --- test/export/BUILD | 44 ++++++++++---------- test/export/repo/test_builtins/BUILD_FILE | 1 - test/export/repo/test_custom_defs/BUILD_FILE | 1 - test/export/repo/test_deps/BUILD_FILE | 2 +- test/export/repo/test_deps/file2.txt | 2 +- test/export/repo/test_deps_other/BUILD_FILE | 2 +- test/export/repo/test_multiple/BUILD_FILE | 2 +- test/export/repo/test_multiple/file1.txt | 2 +- test/export/repo/test_multiple/file2.txt | 2 +- test/export/repo/test_notrim/BUILD_FILE | 2 +- test/export/repo/test_notrim/file1.txt | 2 +- test/export/repo/test_notrim/file2.txt | 2 +- test/export/repo/test_outputs/BUILD_FILE | 2 +- 13 files changed, 31 insertions(+), 35 deletions(-) diff --git a/test/export/BUILD b/test/export/BUILD index 870712f3c..51cd69b65 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -8,17 +8,15 @@ sh_binary( # Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) # within the same test to avoid the overhead of exporting multiple times. def please_export_e2e_test( - name: str, - export_targets: list, - repo: str, - cmd_on_export: list = [], - expect_output_contains: dict = {}, - include_go: bool = False, - strict_check_build_stmt: bool = False, # requires match for all BUILD statements in exported file - EXPORT_DIR = "plz-out/plzexport", - BUILD_FILE = "BUILD_FILE" - ): - + name:str, + export_targets:list, + repo:str, + cmd_on_export:list=[], + expect_output_contains:dict={}, + include_go:bool=False, + strict_check_build_stmt:bool=False, # requires match for all BUILD statements in exported file + EXPORT_DIR="plz-out/plzexport", + BUILD_FILE="BUILD_FILE"): please_targets = ["//" + t for t in export_targets] plz_command_targets = " ".join(please_targets) tools = {} @@ -34,8 +32,8 @@ def please_export_e2e_test( # Export command f"plz {config_override} export --output {EXPORT_DIR} {plz_command_targets}", # Tests building the exported target which in turn ensures the sources are included - f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} build {plz_command_targets}" - ] + [ f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} {cmd}" for cmd in cmd_on_export] + f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} build {plz_command_targets}", + ] + [f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} {cmd}" for cmd in cmd_on_export] defer_cmd = [] for export_target in export_targets: @@ -55,10 +53,10 @@ def please_export_e2e_test( return please_repo_e2e_test( name = name, defer_cmd = defer_cmd, + expect_output_contains = expect_output_contains, plz_command = plz_command, repo = repo, tools = tools, - expect_output_contains = expect_output_contains, ) # Export a target generated by a native genrule target and trim unused build statements. @@ -81,12 +79,12 @@ please_export_e2e_test( # Export a target generated by a custom build def. please_export_e2e_test( name = "export_standard_children_custom_target", - export_targets = ["test_custom_defs:standard_children_custom_target"], - repo = "repo", cmd_on_export = [ # Child of build def "build //test_custom_defs:standard_children_custom_target#child", ], + export_targets = ["test_custom_defs:standard_children_custom_target"], + repo = "repo", # TODO Enable strict check after after support for trimming subincludes #3496 # strict_check_build_stmt = True, ) @@ -112,14 +110,14 @@ please_export_e2e_test( # This test purposely doesn't use the custom def but checks that the source files are still included. please_export_e2e_test( name = "export_preload_genrule", - export_targets = ["test:native_not_including_preloaded"], - repo = "repo_preload", - strict_check_build_stmt = True, expect_output_contains = { # validating that export includes preloaded build def files "build_defs/preloaded.build_defs": "preloaded_target", "build_defs/BUILD_FILE": "preloaded_build_def", - } + }, + export_targets = ["test:native_not_including_preloaded"], + repo = "repo_preload", + strict_check_build_stmt = True, ) # Export a custom target from a repo that preloads the build def used. @@ -134,8 +132,8 @@ please_export_e2e_test( please_export_e2e_test( name = "export_go_binary", export_targets = ["test_go_bin:dummy"], - repo = "repo_go", include_go = True, + repo = "repo_go", strict_check_build_stmt = True, ) @@ -143,8 +141,8 @@ please_export_e2e_test( please_export_e2e_test( name = "export_native_target_with_go_dep", export_targets = ["test_go_dep:genrule_go_dep"], - repo = "repo_go", include_go = True, + repo = "repo_go", # TODO Enable strict check after after support for trimming subincludes #3496 # strict_check_build_stmt = True, ) @@ -153,8 +151,8 @@ please_export_e2e_test( please_export_e2e_test( name = "export_go_target_with_go_dep", export_targets = ["test_go_dep:bin_go_dep"], - repo = "repo_go", include_go = True, + repo = "repo_go", strict_check_build_stmt = True, ) diff --git a/test/export/repo/test_builtins/BUILD_FILE b/test/export/repo/test_builtins/BUILD_FILE index c533d280d..d652c9bd1 100644 --- a/test/export/repo/test_builtins/BUILD_FILE +++ b/test/export/repo/test_builtins/BUILD_FILE @@ -7,7 +7,6 @@ genrule( ) # BUILD_STMT_END - # Du mmy target to be trimmed genrule( name = "dummy", diff --git a/test/export/repo/test_custom_defs/BUILD_FILE b/test/export/repo/test_custom_defs/BUILD_FILE index 241b18d6b..aa6330182 100644 --- a/test/export/repo/test_custom_defs/BUILD_FILE +++ b/test/export/repo/test_custom_defs/BUILD_FILE @@ -10,7 +10,6 @@ simple_custom_target( ) # BUILD_STMT_END - # BUILD_STMT_START standard_children_custom_target subinclude("//test_custom_defs/build_defs:standard_children_build_def") # BUILD_STMT_END diff --git a/test/export/repo/test_deps/BUILD_FILE b/test/export/repo/test_deps/BUILD_FILE index a6578830a..2240c467d 100644 --- a/test/export/repo/test_deps/BUILD_FILE +++ b/test/export/repo/test_deps/BUILD_FILE @@ -18,4 +18,4 @@ genrule( outs = ["out2.txt"], cmd = "cat $SRCS > $OUT", ) -# BUILD_STMT_END \ No newline at end of file +# BUILD_STMT_END diff --git a/test/export/repo/test_deps/file2.txt b/test/export/repo/test_deps/file2.txt index 30d67d467..6c493ff74 100644 --- a/test/export/repo/test_deps/file2.txt +++ b/test/export/repo/test_deps/file2.txt @@ -1 +1 @@ -file2 \ No newline at end of file +file2 diff --git a/test/export/repo/test_deps_other/BUILD_FILE b/test/export/repo/test_deps_other/BUILD_FILE index 1bf3ee556..1c5fbb713 100644 --- a/test/export/repo/test_deps_other/BUILD_FILE +++ b/test/export/repo/test_deps_other/BUILD_FILE @@ -5,4 +5,4 @@ genrule( cmd = "echo 'other' > $OUT", visibility = ["PUBLIC"], ) -# BUILD_STMT_END \ No newline at end of file +# BUILD_STMT_END diff --git a/test/export/repo/test_multiple/BUILD_FILE b/test/export/repo/test_multiple/BUILD_FILE index 29a248447..3fd958da5 100644 --- a/test/export/repo/test_multiple/BUILD_FILE +++ b/test/export/repo/test_multiple/BUILD_FILE @@ -14,4 +14,4 @@ genrule( outs = ["out2.txt"], cmd = "cat $SRCS > $OUT", ) -# BUILD_STMT_END \ No newline at end of file +# BUILD_STMT_END diff --git a/test/export/repo/test_multiple/file1.txt b/test/export/repo/test_multiple/file1.txt index 08219db9b..e2129701f 100644 --- a/test/export/repo/test_multiple/file1.txt +++ b/test/export/repo/test_multiple/file1.txt @@ -1 +1 @@ -file1 \ No newline at end of file +file1 diff --git a/test/export/repo/test_multiple/file2.txt b/test/export/repo/test_multiple/file2.txt index 30d67d467..6c493ff74 100644 --- a/test/export/repo/test_multiple/file2.txt +++ b/test/export/repo/test_multiple/file2.txt @@ -1 +1 @@ -file2 \ No newline at end of file +file2 diff --git a/test/export/repo/test_notrim/BUILD_FILE b/test/export/repo/test_notrim/BUILD_FILE index e6fd02e36..830f381b7 100644 --- a/test/export/repo/test_notrim/BUILD_FILE +++ b/test/export/repo/test_notrim/BUILD_FILE @@ -14,4 +14,4 @@ genrule( outs = ["out2.txt"], cmd = "cat $SRCS > $OUT", ) -# BUILD_STMT_END \ No newline at end of file +# BUILD_STMT_END diff --git a/test/export/repo/test_notrim/file1.txt b/test/export/repo/test_notrim/file1.txt index 08219db9b..e2129701f 100644 --- a/test/export/repo/test_notrim/file1.txt +++ b/test/export/repo/test_notrim/file1.txt @@ -1 +1 @@ -file1 \ No newline at end of file +file1 diff --git a/test/export/repo/test_notrim/file2.txt b/test/export/repo/test_notrim/file2.txt index 30d67d467..6c493ff74 100644 --- a/test/export/repo/test_notrim/file2.txt +++ b/test/export/repo/test_notrim/file2.txt @@ -1 +1 @@ -file2 \ No newline at end of file +file2 diff --git a/test/export/repo/test_outputs/BUILD_FILE b/test/export/repo/test_outputs/BUILD_FILE index 9aeaaff12..f10a47d81 100644 --- a/test/export/repo/test_outputs/BUILD_FILE +++ b/test/export/repo/test_outputs/BUILD_FILE @@ -2,4 +2,4 @@ genrule( name = "out_target", outs = ["some_output.txt"], cmd = "echo 'hello world' > $OUT", -) \ No newline at end of file +) From 6c5ce6da7d4dc93696f9804f8963af54fed9c4ee Mon Sep 17 00:00:00 2001 From: duarte Date: Tue, 24 Mar 2026 16:56:56 +0000 Subject: [PATCH 10/22] fix: plz command replacement for tests cmd --- test/build_defs/test.build_defs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index 959c5cc4f..11efeaa8f 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -23,7 +23,7 @@ def please_repo_e2e_test( plz_command = [plz_command] for cmd in plz_command: - cmd.replace("plz ", "$TOOLS_PLEASE ") + cmd = cmd.replace("plz ", "$TOOLS_PLEASE ") if expected_failure: cmd += "; [ ! $? -eq 0 ]" test_cmd += [cmd] From 78a9ff01cb593a97211d49051ab76fd0ffaae651 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 11:29:15 +0000 Subject: [PATCH 11/22] nit comments --- test/build_defs/test.build_defs | 4 ++-- test/export/repo/test_builtins/BUILD_FILE | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index 11efeaa8f..906e10dbf 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -7,7 +7,7 @@ def please_repo_e2e_test( deps: list=[], defer_cmd=[], tools: dict={}, - tool_content_checker = ["//test/build_defs:content_checker"], + content_checker_tool = ["//test/build_defs:content_checker"], expected_failure: bool = False, expected_output: dict = {}, expect_output_contains: dict = {}, @@ -47,7 +47,7 @@ def please_repo_e2e_test( data["BASE_CONFIG"] = ["//test/build_defs:base_config"] tools["PLEASE"] = ["//package:installed_files|please"] - tools["CONTENT_CHECKER"] = tool_content_checker + tools["CONTENT_CHECKER"] = content_checker_tool return gentest( name = name, diff --git a/test/export/repo/test_builtins/BUILD_FILE b/test/export/repo/test_builtins/BUILD_FILE index d652c9bd1..bfe0f4ab2 100644 --- a/test/export/repo/test_builtins/BUILD_FILE +++ b/test/export/repo/test_builtins/BUILD_FILE @@ -7,7 +7,7 @@ genrule( ) # BUILD_STMT_END -# Du mmy target to be trimmed +# Dummy target to be trimmed genrule( name = "dummy", srcs = ["file.txt"], From 2ac149c773f55cc87ebf49aca5032ec0213106d1 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 11:40:31 +0000 Subject: [PATCH 12/22] test export build def --- test/build_defs/BUILD | 6 +++ test/build_defs/test_export.build_defs | 55 ++++++++++++++++++++++++++ test/export/BUILD | 55 +------------------------- 3 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 test/build_defs/test_export.build_defs diff --git a/test/build_defs/BUILD b/test/build_defs/BUILD index 46e36c791..7e7cf3f5d 100644 --- a/test/build_defs/BUILD +++ b/test/build_defs/BUILD @@ -17,6 +17,12 @@ filegroup( ], ) +filegroup( + name = "test_export", + srcs = ["test_export.build_defs"], + visibility = ["//test/..."], +) + filegroup( name = "base_config", srcs = [ diff --git a/test/build_defs/test_export.build_defs b/test/build_defs/test_export.build_defs new file mode 100644 index 000000000..a56d428e1 --- /dev/null +++ b/test/build_defs/test_export.build_defs @@ -0,0 +1,55 @@ +subinclude("//test/build_defs:build_defs") + +# Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) +# within the same test to avoid the overhead of exporting multiple times. +def please_export_e2e_test( + name:str, + export_targets:list, + repo:str, + cmd_on_export:list=[], + expect_output_contains:dict={}, + include_go:bool=False, + strict_check_build_stmt:bool=False, # requires match for all BUILD statements in exported file + EXPORT_DIR="plz-out/plzexport", + BUILD_FILE="BUILD_FILE"): + please_targets = ["//" + t for t in export_targets] + plz_command_targets = " ".join(please_targets) + tools = {} + config_override = [] + strict_opt = "--strict" if strict_check_build_stmt else "" + + if include_go: + config_override += ["-o plugin.go.gotool:$TOOLS_GO"] + tools["GO"] = [CONFIG.GO.GO_TOOL] + config_override = " ".join(config_override) + + plz_command = [ + # Export command + f"plz {config_override} export --output {EXPORT_DIR} {plz_command_targets}", + # Tests building the exported target which in turn ensures the sources are included + f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} build {plz_command_targets}", + ] + [f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} {cmd}" for cmd in cmd_on_export] + + defer_cmd = [] + for export_target in export_targets: + file_path, target_name = export_target.split(":") + build_file = f"{file_path}/{BUILD_FILE}" + + # Tests the contents of the exported BUILD file + defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] + tools["BUILD_STATEMENT_CHECKER"] = "//test/export:build_statement_checker" + + if expect_output_contains: + updated_expect_output = {} + for key, val in expect_output_contains.items(): + updated_expect_output[f"{EXPORT_DIR}/{key}"] = val + expect_output_contains = updated_expect_output + + return please_repo_e2e_test( + name = name, + defer_cmd = defer_cmd, + expect_output_contains = expect_output_contains, + plz_command = plz_command, + repo = repo, + tools = tools, + ) diff --git a/test/export/BUILD b/test/export/BUILD index 51cd69b65..ee4116a2e 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -1,63 +1,10 @@ -subinclude("//test/build_defs") +subinclude("//test/build_defs:test_export") sh_binary( name = "build_statement_checker", main = "build_statement_checker.sh", ) -# Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) -# within the same test to avoid the overhead of exporting multiple times. -def please_export_e2e_test( - name:str, - export_targets:list, - repo:str, - cmd_on_export:list=[], - expect_output_contains:dict={}, - include_go:bool=False, - strict_check_build_stmt:bool=False, # requires match for all BUILD statements in exported file - EXPORT_DIR="plz-out/plzexport", - BUILD_FILE="BUILD_FILE"): - please_targets = ["//" + t for t in export_targets] - plz_command_targets = " ".join(please_targets) - tools = {} - config_override = [] - strict_opt = "--strict" if strict_check_build_stmt else "" - - if include_go: - config_override += ["-o plugin.go.gotool:$TOOLS_GO"] - tools["GO"] = [CONFIG.GO.GO_TOOL] - config_override = " ".join(config_override) - - plz_command = [ - # Export command - f"plz {config_override} export --output {EXPORT_DIR} {plz_command_targets}", - # Tests building the exported target which in turn ensures the sources are included - f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} build {plz_command_targets}", - ] + [f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} {cmd}" for cmd in cmd_on_export] - - defer_cmd = [] - for export_target in export_targets: - file_path, target_name = export_target.split(":") - build_file = f"{file_path}/{BUILD_FILE}" - - # Tests the contents of the exported BUILD file - defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] - tools["BUILD_STATEMENT_CHECKER"] = "//test/export:build_statement_checker" - - if expect_output_contains: - updated_expect_output = {} - for key, val in expect_output_contains.items(): - updated_expect_output[f"{EXPORT_DIR}/{key}"] = val - expect_output_contains = updated_expect_output - - return please_repo_e2e_test( - name = name, - defer_cmd = defer_cmd, - expect_output_contains = expect_output_contains, - plz_command = plz_command, - repo = repo, - tools = tools, - ) # Export a target generated by a native genrule target and trim unused build statements. please_export_e2e_test( From 439b7218d2b1829d8d8680ea3153353685739515 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 15:37:54 +0000 Subject: [PATCH 13/22] first golden-master test and moved export_e2e to generic test Reverted changes to main test build def --- test/build_defs/BUILD | 6 - test/build_defs/test.build_defs | 24 +- test/build_defs/test_export.build_defs | 55 ----- test/export/BUILD | 226 +++++++++--------- test/export/build_statement_checker.sh | 119 --------- test/export/please_export_e2e_test.build_defs | 51 ++++ .../test_builtins/expected_repo/.plzconfig | 2 + .../test_builtins/expected_repo/BUILD_FILE | 6 + .../test_builtins/expected_repo/file.txt | 1 + .../export/test_builtins/test_repo/.plzconfig | 2 + .../export/test_builtins/test_repo/BUILD_FILE | 13 + test/export/test_builtins/test_repo/file.txt | 1 + 12 files changed, 195 insertions(+), 311 deletions(-) delete mode 100644 test/build_defs/test_export.build_defs delete mode 100755 test/export/build_statement_checker.sh create mode 100644 test/export/please_export_e2e_test.build_defs create mode 100644 test/export/test_builtins/expected_repo/.plzconfig create mode 100644 test/export/test_builtins/expected_repo/BUILD_FILE create mode 100644 test/export/test_builtins/expected_repo/file.txt create mode 100644 test/export/test_builtins/test_repo/.plzconfig create mode 100644 test/export/test_builtins/test_repo/BUILD_FILE create mode 100644 test/export/test_builtins/test_repo/file.txt diff --git a/test/build_defs/BUILD b/test/build_defs/BUILD index 7e7cf3f5d..46e36c791 100644 --- a/test/build_defs/BUILD +++ b/test/build_defs/BUILD @@ -17,12 +17,6 @@ filegroup( ], ) -filegroup( - name = "test_export", - srcs = ["test_export.build_defs"], - visibility = ["//test/..."], -) - filegroup( name = "base_config", srcs = [ diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index 906e10dbf..5830e3f62 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -1,33 +1,27 @@ # Runs e2e tests against please in a specified repo def please_repo_e2e_test( name: str, - plz_command: str|list, + plz_command: str, repo: str, data: dict={}, deps: list=[], - defer_cmd=[], tools: dict={}, - content_checker_tool = ["//test/build_defs:content_checker"], expected_failure: bool = False, expected_output: dict = {}, expect_output_contains: dict = {}, expect_output_doesnt_contain: dict = {}, labels: list = [], ): + plz_command = plz_command.replace("plz ", "$TOOLS_PLEASE ") + if expected_failure: + plz_command += "; [ ! $? -eq 0 ]" + test_cmd = [ "cp $DATA_BASE_CONFIG $DATA_REPO", "cd $DATA_REPO", + plz_command, ] - if isinstance(plz_command, str): - plz_command = [plz_command] - - for cmd in plz_command: - cmd = cmd.replace("plz ", "$TOOLS_PLEASE ") - if expected_failure: - cmd += "; [ ! $? -eq 0 ]" - test_cmd += [cmd] - if expected_output: test_cmd += [f"$TOOLS_CONTENT_CHECKER '{o}' '{c}'" for o, c in expected_output.items()] @@ -37,17 +31,13 @@ def please_repo_e2e_test( if expect_output_doesnt_contain: test_cmd += [f'_STR="$(cat {o})" _SUBSTR="{c}" && if [ -z "${_STR##*$_SUBSTR*}" ]; then echo "$_STR"; exit 1; fi' for o, c in expect_output_doesnt_contain.items()] - # defer commands should be added last - if defer_cmd: - test_cmd += defer_cmd - test_cmd = ' && '.join(test_cmd) data["REPO"] = [repo] data["BASE_CONFIG"] = ["//test/build_defs:base_config"] tools["PLEASE"] = ["//package:installed_files|please"] - tools["CONTENT_CHECKER"] = content_checker_tool + tools["CONTENT_CHECKER"] = ["//test/build_defs:content_checker"] return gentest( name = name, diff --git a/test/build_defs/test_export.build_defs b/test/build_defs/test_export.build_defs deleted file mode 100644 index a56d428e1..000000000 --- a/test/build_defs/test_export.build_defs +++ /dev/null @@ -1,55 +0,0 @@ -subinclude("//test/build_defs:build_defs") - -# Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) -# within the same test to avoid the overhead of exporting multiple times. -def please_export_e2e_test( - name:str, - export_targets:list, - repo:str, - cmd_on_export:list=[], - expect_output_contains:dict={}, - include_go:bool=False, - strict_check_build_stmt:bool=False, # requires match for all BUILD statements in exported file - EXPORT_DIR="plz-out/plzexport", - BUILD_FILE="BUILD_FILE"): - please_targets = ["//" + t for t in export_targets] - plz_command_targets = " ".join(please_targets) - tools = {} - config_override = [] - strict_opt = "--strict" if strict_check_build_stmt else "" - - if include_go: - config_override += ["-o plugin.go.gotool:$TOOLS_GO"] - tools["GO"] = [CONFIG.GO.GO_TOOL] - config_override = " ".join(config_override) - - plz_command = [ - # Export command - f"plz {config_override} export --output {EXPORT_DIR} {plz_command_targets}", - # Tests building the exported target which in turn ensures the sources are included - f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} build {plz_command_targets}", - ] + [f"plz {config_override} --repo_root=$(plz query reporoot)/{EXPORT_DIR} {cmd}" for cmd in cmd_on_export] - - defer_cmd = [] - for export_target in export_targets: - file_path, target_name = export_target.split(":") - build_file = f"{file_path}/{BUILD_FILE}" - - # Tests the contents of the exported BUILD file - defer_cmd += [f'$TOOLS_BUILD_STATEMENT_CHECKER {strict_opt} --exported "{EXPORT_DIR}/{build_file}" --original "{build_file}" --target "{target_name}"'] - tools["BUILD_STATEMENT_CHECKER"] = "//test/export:build_statement_checker" - - if expect_output_contains: - updated_expect_output = {} - for key, val in expect_output_contains.items(): - updated_expect_output[f"{EXPORT_DIR}/{key}"] = val - expect_output_contains = updated_expect_output - - return please_repo_e2e_test( - name = name, - defer_cmd = defer_cmd, - expect_output_contains = expect_output_contains, - plz_command = plz_command, - repo = repo, - tools = tools, - ) diff --git a/test/export/BUILD b/test/export/BUILD index ee4116a2e..8ea510097 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -1,133 +1,131 @@ -subinclude("//test/build_defs:test_export") - -sh_binary( - name = "build_statement_checker", - main = "build_statement_checker.sh", +filegroup( + name = "export_e2e_test_build_def", + srcs = ["please_export_e2e_test.build_defs"], ) +subinclude(":export_e2e_test_build_def") # Export a target generated by a native genrule target and trim unused build statements. please_export_e2e_test( name = "export_native_genrule", - export_targets = ["test_builtins:native_genrule"], - repo = "repo", - strict_check_build_stmt = True, + dir = "test_builtins", + export_targets = [":native_genrule"], ) -# Export a target generated by a custom build def. -please_export_e2e_test( - name = "export_simple_custom_target", - export_targets = ["test_custom_defs:simple_custom_target"], - repo = "repo", - # TODO Enable strict check after after support for trimming subincludes #3496 - # strict_check_build_stmt = True, -) +# # Export a target generated by a custom build def. +# please_export_e2e_test( +# name = "export_simple_custom_target", +# export_targets = ["test_custom_defs:simple_custom_target"], +# repo = "repo", +# # TODO Enable strict check after after support for trimming subincludes #3496 +# # strict_check_build_stmt = True, +# ) -# Export a target generated by a custom build def. -please_export_e2e_test( - name = "export_standard_children_custom_target", - cmd_on_export = [ - # Child of build def - "build //test_custom_defs:standard_children_custom_target#child", - ], - export_targets = ["test_custom_defs:standard_children_custom_target"], - repo = "repo", - # TODO Enable strict check after after support for trimming subincludes #3496 - # strict_check_build_stmt = True, -) +# # Export a target generated by a custom build def. +# please_export_e2e_test( +# name = "export_standard_children_custom_target", +# cmd_on_export = [ +# # Child of build def +# "build //test_custom_defs:standard_children_custom_target#child", +# ], +# export_targets = ["test_custom_defs:standard_children_custom_target"], +# repo = "repo", +# # TODO Enable strict check after after support for trimming subincludes #3496 +# # strict_check_build_stmt = True, +# ) -# Export a target that depends on another target. -please_export_e2e_test( - name = "export_deps", - export_targets = ["test_deps:dep2"], - repo = "repo", -) +# # Export a target that depends on another target. +# please_export_e2e_test( +# name = "export_deps", +# export_targets = ["test_deps:dep2"], +# repo = "repo", +# ) -# Test multiple targets. -please_export_e2e_test( - name = "export_multiple", - export_targets = [ - "test_multiple:target1", - "test_multiple:target2", - ], - repo = "repo", -) +# # Test multiple targets. +# please_export_e2e_test( +# name = "export_multiple", +# export_targets = [ +# "test_multiple:target1", +# "test_multiple:target2", +# ], +# repo = "repo", +# ) -# Export a target from a repo that preloads a build def. -# This test purposely doesn't use the custom def but checks that the source files are still included. -please_export_e2e_test( - name = "export_preload_genrule", - expect_output_contains = { - # validating that export includes preloaded build def files - "build_defs/preloaded.build_defs": "preloaded_target", - "build_defs/BUILD_FILE": "preloaded_build_def", - }, - export_targets = ["test:native_not_including_preloaded"], - repo = "repo_preload", - strict_check_build_stmt = True, -) +# # Export a target from a repo that preloads a build def. +# # This test purposely doesn't use the custom def but checks that the source files are still included. +# please_export_e2e_test( +# name = "export_preload_genrule", +# expect_output_contains = { +# # validating that export includes preloaded build def files +# "build_defs/preloaded.build_defs": "preloaded_target", +# "build_defs/BUILD_FILE": "preloaded_build_def", +# }, +# export_targets = ["test:native_not_including_preloaded"], +# repo = "repo_preload", +# strict_check_build_stmt = True, +# ) -# Export a custom target from a repo that preloads the build def used. -please_export_e2e_test( - name = "export_preload_use_preloaded_def", - export_targets = ["test:use_preloaded_def"], - repo = "repo_preload", - strict_check_build_stmt = True, -) +# # Export a custom target from a repo that preloads the build def used. +# please_export_e2e_test( +# name = "export_preload_use_preloaded_def", +# export_targets = ["test:use_preloaded_def"], +# repo = "repo_preload", +# strict_check_build_stmt = True, +# ) -# Test go binary target. -please_export_e2e_test( - name = "export_go_binary", - export_targets = ["test_go_bin:dummy"], - include_go = True, - repo = "repo_go", - strict_check_build_stmt = True, -) +# # Test go binary target. +# please_export_e2e_test( +# name = "export_go_binary", +# export_targets = ["test_go_bin:dummy"], +# include_go = True, +# repo = "repo_go", +# strict_check_build_stmt = True, +# ) -# Test native target with go third_party dependency. -please_export_e2e_test( - name = "export_native_target_with_go_dep", - export_targets = ["test_go_dep:genrule_go_dep"], - include_go = True, - repo = "repo_go", - # TODO Enable strict check after after support for trimming subincludes #3496 - # strict_check_build_stmt = True, -) +# # Test native target with go third_party dependency. +# please_export_e2e_test( +# name = "export_native_target_with_go_dep", +# export_targets = ["test_go_dep:genrule_go_dep"], +# include_go = True, +# repo = "repo_go", +# # TODO Enable strict check after after support for trimming subincludes #3496 +# # strict_check_build_stmt = True, +# ) -# Test go target with go third_party dependency. -please_export_e2e_test( - name = "export_go_target_with_go_dep", - export_targets = ["test_go_dep:bin_go_dep"], - include_go = True, - repo = "repo_go", - strict_check_build_stmt = True, -) +# # Test go target with go third_party dependency. +# please_export_e2e_test( +# name = "export_go_target_with_go_dep", +# export_targets = ["test_go_dep:bin_go_dep"], +# include_go = True, +# repo = "repo_go", +# strict_check_build_stmt = True, +# ) -# Generic catch-all test on internal repo. -plz_e2e_test( - name = "export_src_please_test", - cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", -) +# # Generic catch-all test on internal repo. +# plz_e2e_test( +# name = "export_src_please_test", +# cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", +# ) -# Test outputs export. -please_repo_e2e_test( - name = "export_outputs", - defer_cmd = [ - 'test -f "plz-out/plzexport/some_output.txt"', - 'test ! -f "plz-out/plzexport/BUILD_FILE"', - ], - plz_command = "plz export outputs --output plz-out/plzexport //test_outputs:out_target", - repo = "repo", -) +# # Test outputs export. +# please_repo_e2e_test( +# name = "export_outputs", +# defer_cmd = [ +# 'test -f "plz-out/plzexport/some_output.txt"', +# 'test ! -f "plz-out/plzexport/BUILD_FILE"', +# ], +# plz_command = "plz export outputs --output plz-out/plzexport //test_outputs:out_target", +# repo = "repo", +# ) -# Test --notrim flag. -please_repo_e2e_test( - name = "export_notrim", - defer_cmd = [ - 'test -f "plz-out/plzexport/test_notrim/file2.txt"', - 'test -f "plz-out/plzexport/test_notrim/BUILD_FILE"', - 'grep -q \'name = "unrelated"\' "plz-out/plzexport/test_notrim/BUILD_FILE"', - ], - plz_command = "plz export --notrim --output plz-out/plzexport //test_notrim:target1", - repo = "repo", -) +# # Test --notrim flag. +# please_repo_e2e_test( +# name = "export_notrim", +# defer_cmd = [ +# 'test -f "plz-out/plzexport/test_notrim/file2.txt"', +# 'test -f "plz-out/plzexport/test_notrim/BUILD_FILE"', +# 'grep -q \'name = "unrelated"\' "plz-out/plzexport/test_notrim/BUILD_FILE"', +# ], +# plz_command = "plz export --notrim --output plz-out/plzexport //test_notrim:target1", +# repo = "repo", +# ) diff --git a/test/export/build_statement_checker.sh b/test/export/build_statement_checker.sh deleted file mode 100755 index f8bcb9c91..000000000 --- a/test/export/build_statement_checker.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -strict_match=false -exported_file="" -original_file="" -target_name="" - -while [[ "$#" -gt 0 ]]; do - case $1 in - --strict) - strict_match=true - shift - ;; - --exported) - exported_file=$2 - shift 2 - ;; - --original) - original_file=$2 - shift 2 - ;; - --target) - target_name=$2 - shift 2 - ;; - -*) - echo "Unknown option: $1" >&2 - exit 1 - ;; - *) - echo "Unknown argument: $1" >&2 - exit 1 - ;; - esac -done - -if [[ -z "$exported_file" ]] || [[ -z "$original_file" ]] || [[ -z "$target_name" ]]; then - echo "Usage: $0 [--strict] --exported --original --target " >&2 - exit 1 -fi - -if [[ ! -f "$exported_file" ]]; then - echo "$exported_file doesnt exist" >&2 - exit 1 -fi - -if [[ ! -f "$original_file" ]]; then - echo "$original_file doesnt exist" >&2 - exit 1 -fi - -readonly START_DELIM="# BUILD_STMT_START" -readonly END_DELIM="# BUILD_STMT_END" - -# Using awk to extract statement blocks directly into an array. -blocks=() -while IFS= read -r -d '' block; do - blocks+=("$block") -done < <(awk -v id="$target_name" -v start_delim="$START_DELIM" -v end_delim="$END_DELIM" ' - BEGIN { in_block = 0; block = "" } - $0 == start_delim " " id { - in_block = 1; - block = ""; - next; - } - $0 == end_delim { - if (in_block) { - in_block = 0; - printf "%s\0", block; - } - next; - } - in_block { - block = block ? block "\n" $0 : $0 - } -' "$original_file") - -if [[ ${#blocks[@]} -eq 0 ]]; then - echo "Failed to pull original content for $target_name" >&2 - exit 1 -fi - -# Ensure that ALL required blocks are present in the generated file -for block_content in "${blocks[@]}"; do - if ! grep -Fq "$block_content" "$exported_file"; then - printf '%s\n%s\n%s\n%s\n%s\n%s\n' \ - "BUILD statements mismatch" \ - "${exported_file} doesnt contain" \ - "${block_content}" \ - "---- it contains ----" \ - "$(cat "$exported_file")" \ - "---- EOF ----" >&2 - exit 1 - fi -done - -# If --strict is enabled, ensure ONLY these blocks are present -# (ignoring all whitespace, newlines and comments). -if [[ "$strict_match" == true ]]; then - concatenated_blocks="" - for block_content in "${blocks[@]}"; do - concatenated_blocks="${concatenated_blocks}${block_content}" - done - - stripped_blocks=$(echo -n "$concatenated_blocks" | sed 's/#.*//' | tr -d ' \t\n\r') - stripped_exported_file=$(sed 's/#.*//' "$exported_file" | tr -d ' \t\n\r') - - if [[ "$stripped_blocks" != "$stripped_exported_file" ]]; then - printf '%s\n' "Strict match failed: exported file contains extra or out-of-order content." >&2 - printf '%s\n' "---- Expected (stripped) ----" >&2 - printf '%s\n' "$stripped_blocks" >&2 - printf '%s\n' "---- Got (stripped) ----" >&2 - printf '%s\n' "$stripped_exported_file" >&2 - exit 1 - fi -fi - -exit 0 diff --git a/test/export/please_export_e2e_test.build_defs b/test/export/please_export_e2e_test.build_defs new file mode 100644 index 000000000..5e93f4ad3 --- /dev/null +++ b/test/export/please_export_e2e_test.build_defs @@ -0,0 +1,51 @@ +subinclude("//test/build_defs:build_defs") + +# Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) +# within the same test to avoid the overhead of exporting multiple times. +def please_export_e2e_test( + name:str, + export_targets:list, + dir:str, + cmd_on_export:list=[], + include_go:bool=False): + EXPORT_DIR="plz-out/plzexport" + test_repo = f"{dir}/test_repo" + expected_repo = f"{dir}/expected_repo" + exported_repo = f"$DATA_TEST_REPO/{EXPORT_DIR}" + + please_targets = ["//" + t for t in export_targets] + plz_command_targets = " ".join(please_targets) + + config_override = "" + if include_go: + config_override += "-o plugin.go.gotool:$TOOLS_GO" + tools["GO"] = [CONFIG.GO.GO_TOOL] + + test_cmd = [ + # Export + f'plz {config_override} --repo_root="$DATA_TEST_REPO" export --output "{EXPORT_DIR}" {plz_command_targets}', + # Golden-Master validation with expected repo. Done before any building to avoid plz-out + f'diff -r "{exported_repo}" "$DATA_EXPECTED_REPO"', + # Tests building the exported target which in turn ensures the sources are included + f'plz {config_override} --repo_root="{exported_repo}" build {plz_command_targets}', + ] + [f'plz {config_override} --repo_root="{exported_repo}" {cmd}' for cmd in cmd_on_export] + + test_cmd = [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in test_cmd] + test_cmd = ' && '.join(test_cmd) + + data = {} + data["TEST_REPO"] = [test_repo] + data["EXPECTED_REPO"] = [expected_repo] + + tools = {} + tools["PLEASE"] = ["//package:installed_files|please"] + + return gentest( + name = name, + test_cmd = test_cmd, + test_tools = tools, + data = data, + no_test_output = True, + labels = ["plz_e2e_test", "e2e"], + sandbox = False, + ) diff --git a/test/export/test_builtins/expected_repo/.plzconfig b/test/export/test_builtins/expected_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_builtins/expected_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_builtins/expected_repo/BUILD_FILE b/test/export/test_builtins/expected_repo/BUILD_FILE new file mode 100644 index 000000000..a62a98a8d --- /dev/null +++ b/test/export/test_builtins/expected_repo/BUILD_FILE @@ -0,0 +1,6 @@ +genrule( + name = "native_genrule", + srcs = ["file.txt"], + outs = ["file.wordcount"], + cmd = "wc $SRCS > $OUT", +) diff --git a/test/export/test_builtins/expected_repo/file.txt b/test/export/test_builtins/expected_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_builtins/expected_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_builtins/test_repo/.plzconfig b/test/export/test_builtins/test_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_builtins/test_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_builtins/test_repo/BUILD_FILE b/test/export/test_builtins/test_repo/BUILD_FILE new file mode 100644 index 000000000..566d3ab5f --- /dev/null +++ b/test/export/test_builtins/test_repo/BUILD_FILE @@ -0,0 +1,13 @@ +genrule( + name = "native_genrule", + srcs = ["file.txt"], + outs = ["file.wordcount"], + cmd = "wc $SRCS > $OUT", +) + +genrule( + name = "dummy_target_to_be_trimmed", + srcs = ["file.txt"], + outs = ["dummy"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/test_builtins/test_repo/file.txt b/test/export/test_builtins/test_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_builtins/test_repo/file.txt @@ -0,0 +1 @@ +Test source file From 5579a830527f0aeeb5f20abfb3a36635c74eed4c Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 16:12:29 +0000 Subject: [PATCH 14/22] update test simple custom build def to use repo diff --- test/export/BUILD | 16 +++++++--------- test/export/please_export_e2e_test.build_defs | 7 +++---- .../test_custom_def/expected_repo/.plzconfig | 2 ++ .../test_custom_def/expected_repo/BUILD_FILE | 7 +++++++ .../expected_repo/build_defs/BUILD_FILE | 5 +++++ .../expected_repo/build_defs/simple.build_defs | 10 ++++++++++ .../test_custom_def/expected_repo/file.txt | 1 + test/export/test_custom_def/test_repo/.plzconfig | 2 ++ test/export/test_custom_def/test_repo/BUILD_FILE | 7 +++++++ .../test_repo/build_defs/BUILD_FILE | 5 +++++ .../test_repo/build_defs/simple.build_defs | 10 ++++++++++ test/export/test_custom_def/test_repo/file.txt | 1 + 12 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 test/export/test_custom_def/expected_repo/.plzconfig create mode 100644 test/export/test_custom_def/expected_repo/BUILD_FILE create mode 100644 test/export/test_custom_def/expected_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_custom_def/expected_repo/build_defs/simple.build_defs create mode 100644 test/export/test_custom_def/expected_repo/file.txt create mode 100644 test/export/test_custom_def/test_repo/.plzconfig create mode 100644 test/export/test_custom_def/test_repo/BUILD_FILE create mode 100644 test/export/test_custom_def/test_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_custom_def/test_repo/build_defs/simple.build_defs create mode 100644 test/export/test_custom_def/test_repo/file.txt diff --git a/test/export/BUILD b/test/export/BUILD index 8ea510097..f481e013d 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -9,17 +9,15 @@ subinclude(":export_e2e_test_build_def") please_export_e2e_test( name = "export_native_genrule", dir = "test_builtins", - export_targets = [":native_genrule"], + export_targets = ["//:native_genrule"], ) -# # Export a target generated by a custom build def. -# please_export_e2e_test( -# name = "export_simple_custom_target", -# export_targets = ["test_custom_defs:simple_custom_target"], -# repo = "repo", -# # TODO Enable strict check after after support for trimming subincludes #3496 -# # strict_check_build_stmt = True, -# ) +# Export a target generated by a custom build def. +please_export_e2e_test( + name = "export_simple_custom_target", + export_targets = ["//:simple_custom_target"], + dir = "test_custom_def", +) # # Export a target generated by a custom build def. # please_export_e2e_test( diff --git a/test/export/please_export_e2e_test.build_defs b/test/export/please_export_e2e_test.build_defs index 5e93f4ad3..47d64ad3f 100644 --- a/test/export/please_export_e2e_test.build_defs +++ b/test/export/please_export_e2e_test.build_defs @@ -13,8 +13,7 @@ def please_export_e2e_test( expected_repo = f"{dir}/expected_repo" exported_repo = f"$DATA_TEST_REPO/{EXPORT_DIR}" - please_targets = ["//" + t for t in export_targets] - plz_command_targets = " ".join(please_targets) + targets = " ".join(export_targets) config_override = "" if include_go: @@ -23,11 +22,11 @@ def please_export_e2e_test( test_cmd = [ # Export - f'plz {config_override} --repo_root="$DATA_TEST_REPO" export --output "{EXPORT_DIR}" {plz_command_targets}', + f'plz {config_override} --repo_root="$DATA_TEST_REPO" export --output "{EXPORT_DIR}" {targets}', # Golden-Master validation with expected repo. Done before any building to avoid plz-out f'diff -r "{exported_repo}" "$DATA_EXPECTED_REPO"', # Tests building the exported target which in turn ensures the sources are included - f'plz {config_override} --repo_root="{exported_repo}" build {plz_command_targets}', + f'plz {config_override} --repo_root="{exported_repo}" build {targets}', ] + [f'plz {config_override} --repo_root="{exported_repo}" {cmd}' for cmd in cmd_on_export] test_cmd = [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in test_cmd] diff --git a/test/export/test_custom_def/expected_repo/.plzconfig b/test/export/test_custom_def/expected_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_custom_def/expected_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def/expected_repo/BUILD_FILE b/test/export/test_custom_def/expected_repo/BUILD_FILE new file mode 100644 index 000000000..261729adc --- /dev/null +++ b/test/export/test_custom_def/expected_repo/BUILD_FILE @@ -0,0 +1,7 @@ +subinclude("//build_defs:simple_build_def") + +simple_custom_target( + name = "simple_custom_target", + srcs = ["file.txt"], + outs = ["file_simple.out"], +) diff --git a/test/export/test_custom_def/expected_repo/build_defs/BUILD_FILE b/test/export/test_custom_def/expected_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..a556ce6d4 --- /dev/null +++ b/test/export/test_custom_def/expected_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "simple_build_def", + srcs = ["simple.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_custom_def/expected_repo/build_defs/simple.build_defs b/test/export/test_custom_def/expected_repo/build_defs/simple.build_defs new file mode 100644 index 000000000..8fe3a6021 --- /dev/null +++ b/test/export/test_custom_def/expected_repo/build_defs/simple.build_defs @@ -0,0 +1,10 @@ +def simple_custom_target( + name:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "cat $SRCS > $OUT", + ) diff --git a/test/export/test_custom_def/expected_repo/file.txt b/test/export/test_custom_def/expected_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_custom_def/expected_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_custom_def/test_repo/.plzconfig b/test/export/test_custom_def/test_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_custom_def/test_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def/test_repo/BUILD_FILE b/test/export/test_custom_def/test_repo/BUILD_FILE new file mode 100644 index 000000000..261729adc --- /dev/null +++ b/test/export/test_custom_def/test_repo/BUILD_FILE @@ -0,0 +1,7 @@ +subinclude("//build_defs:simple_build_def") + +simple_custom_target( + name = "simple_custom_target", + srcs = ["file.txt"], + outs = ["file_simple.out"], +) diff --git a/test/export/test_custom_def/test_repo/build_defs/BUILD_FILE b/test/export/test_custom_def/test_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..a556ce6d4 --- /dev/null +++ b/test/export/test_custom_def/test_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "simple_build_def", + srcs = ["simple.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_custom_def/test_repo/build_defs/simple.build_defs b/test/export/test_custom_def/test_repo/build_defs/simple.build_defs new file mode 100644 index 000000000..8fe3a6021 --- /dev/null +++ b/test/export/test_custom_def/test_repo/build_defs/simple.build_defs @@ -0,0 +1,10 @@ +def simple_custom_target( + name:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "cat $SRCS > $OUT", + ) diff --git a/test/export/test_custom_def/test_repo/file.txt b/test/export/test_custom_def/test_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_custom_def/test_repo/file.txt @@ -0,0 +1 @@ +Test source file From a375e24a76ed1cc7eca86c07b14b0244d3e4aa2e Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 17:05:41 +0000 Subject: [PATCH 15/22] update test build defs for in file and extra child --- test/export/BUILD | 33 +++++++++++-------- .../export/test_builtins/test_repo/BUILD_FILE | 2 +- test/export/test_builtins/test_repo/dummy.txt | 0 .../test_repo/build_defs/dummy.build_defs | 10 ++++++ .../expected_repo/.plzconfig | 2 ++ .../expected_repo/BUILD_FILE | 8 +++++ .../expected_repo/build_defs/BUILD_FILE | 5 +++ .../build_defs/standard_children.build_defs | 17 ++++++++++ .../expected_repo/file.txt | 1 + .../test_repo/.plzconfig | 2 ++ .../test_repo/BUILD_FILE | 8 +++++ .../test_repo/build_defs/BUILD_FILE | 5 +++ .../build_defs/standard_children.build_defs | 17 ++++++++++ .../test_repo/file.txt | 1 + .../expected_repo/.plzconfig | 2 ++ .../expected_repo/BUILD_FILE | 13 ++++++++ .../expected_repo/file.txt | 1 + .../expected_repo/simple.build_defs | 10 ++++++ .../test_repo/.plzconfig | 2 ++ .../test_repo/BUILD_FILE | 13 ++++++++ .../test_repo/file.txt | 1 + .../test_repo/simple.build_defs | 10 ++++++ 22 files changed, 149 insertions(+), 14 deletions(-) create mode 100644 test/export/test_builtins/test_repo/dummy.txt create mode 100644 test/export/test_custom_def/test_repo/build_defs/dummy.build_defs create mode 100644 test/export/test_custom_def_children/expected_repo/.plzconfig create mode 100644 test/export/test_custom_def_children/expected_repo/BUILD_FILE create mode 100644 test/export/test_custom_def_children/expected_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_custom_def_children/expected_repo/build_defs/standard_children.build_defs create mode 100644 test/export/test_custom_def_children/expected_repo/file.txt create mode 100644 test/export/test_custom_def_children/test_repo/.plzconfig create mode 100644 test/export/test_custom_def_children/test_repo/BUILD_FILE create mode 100644 test/export/test_custom_def_children/test_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_custom_def_children/test_repo/build_defs/standard_children.build_defs create mode 100644 test/export/test_custom_def_children/test_repo/file.txt create mode 100644 test/export/test_custom_in_file_def/expected_repo/.plzconfig create mode 100644 test/export/test_custom_in_file_def/expected_repo/BUILD_FILE create mode 100644 test/export/test_custom_in_file_def/expected_repo/file.txt create mode 100644 test/export/test_custom_in_file_def/expected_repo/simple.build_defs create mode 100644 test/export/test_custom_in_file_def/test_repo/.plzconfig create mode 100644 test/export/test_custom_in_file_def/test_repo/BUILD_FILE create mode 100644 test/export/test_custom_in_file_def/test_repo/file.txt create mode 100644 test/export/test_custom_in_file_def/test_repo/simple.build_defs diff --git a/test/export/BUILD b/test/export/BUILD index f481e013d..79febe34e 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -5,7 +5,8 @@ filegroup( subinclude(":export_e2e_test_build_def") -# Export a target generated by a native genrule target and trim unused build statements. +# Export a target generated by a native genrule target and trim unused +# build statements. please_export_e2e_test( name = "export_native_genrule", dir = "test_builtins", @@ -19,18 +20,24 @@ please_export_e2e_test( dir = "test_custom_def", ) -# # Export a target generated by a custom build def. -# please_export_e2e_test( -# name = "export_standard_children_custom_target", -# cmd_on_export = [ -# # Child of build def -# "build //test_custom_defs:standard_children_custom_target#child", -# ], -# export_targets = ["test_custom_defs:standard_children_custom_target"], -# repo = "repo", -# # TODO Enable strict check after after support for trimming subincludes #3496 -# # strict_check_build_stmt = True, -# ) +# Export a target generated by a custom build def defined in the same +# BUILD file. +please_export_e2e_test( + name = "export_custom_target_in_file", + export_targets = ["//:simple_custom_target"], + dir = "test_custom_in_file_def", +) + +# Export a target generated by a custom build def. +please_export_e2e_test( + name = "export_standard_children_custom_target", + cmd_on_export = [ + # Child of build def + "build //:standard_children_custom_target#child", + ], + export_targets = ["//:standard_children_custom_target"], + dir = "test_custom_def_children", +) # # Export a target that depends on another target. # please_export_e2e_test( diff --git a/test/export/test_builtins/test_repo/BUILD_FILE b/test/export/test_builtins/test_repo/BUILD_FILE index 566d3ab5f..db7732c48 100644 --- a/test/export/test_builtins/test_repo/BUILD_FILE +++ b/test/export/test_builtins/test_repo/BUILD_FILE @@ -7,7 +7,7 @@ genrule( genrule( name = "dummy_target_to_be_trimmed", - srcs = ["file.txt"], + srcs = ["dummy.txt"], outs = ["dummy"], cmd = "cat $SRCS > $OUT", ) diff --git a/test/export/test_builtins/test_repo/dummy.txt b/test/export/test_builtins/test_repo/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/export/test_custom_def/test_repo/build_defs/dummy.build_defs b/test/export/test_custom_def/test_repo/build_defs/dummy.build_defs new file mode 100644 index 000000000..2e9198492 --- /dev/null +++ b/test/export/test_custom_def/test_repo/build_defs/dummy.build_defs @@ -0,0 +1,10 @@ +def dummy_target( + name:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "echo dummy > $OUT", + ) diff --git a/test/export/test_custom_def_children/expected_repo/.plzconfig b/test/export/test_custom_def_children/expected_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_custom_def_children/expected_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def_children/expected_repo/BUILD_FILE b/test/export/test_custom_def_children/expected_repo/BUILD_FILE new file mode 100644 index 000000000..6c99c406d --- /dev/null +++ b/test/export/test_custom_def_children/expected_repo/BUILD_FILE @@ -0,0 +1,8 @@ +subinclude("//build_defs:standard_children_build_def") + +standard_children_custom_target( + name = "standard_children_custom_target", + srcs = ["file.txt"], + outs = ["file_standard.out"], + outs_child = ["file_child.out"], +) diff --git a/test/export/test_custom_def_children/expected_repo/build_defs/BUILD_FILE b/test/export/test_custom_def_children/expected_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..00eed0f0b --- /dev/null +++ b/test/export/test_custom_def_children/expected_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "standard_children_build_def", + srcs = ["standard_children.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_custom_def_children/expected_repo/build_defs/standard_children.build_defs b/test/export/test_custom_def_children/expected_repo/build_defs/standard_children.build_defs new file mode 100644 index 000000000..081154550 --- /dev/null +++ b/test/export/test_custom_def_children/expected_repo/build_defs/standard_children.build_defs @@ -0,0 +1,17 @@ +def standard_children_custom_target( + name:str, + srcs:list=[], + outs:list=[], + outs_child:list=[]): + genrule( + name = f"{name}#child", + srcs = srcs, + outs = outs_child, + cmd = "echo 'child' > $OUT && cat $SRCS >> $OUT ", + ) + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "echo 'main' > $OUT && cat $SRCS >> $OUT ", + ) diff --git a/test/export/test_custom_def_children/expected_repo/file.txt b/test/export/test_custom_def_children/expected_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_custom_def_children/expected_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_custom_def_children/test_repo/.plzconfig b/test/export/test_custom_def_children/test_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_custom_def_children/test_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def_children/test_repo/BUILD_FILE b/test/export/test_custom_def_children/test_repo/BUILD_FILE new file mode 100644 index 000000000..6c99c406d --- /dev/null +++ b/test/export/test_custom_def_children/test_repo/BUILD_FILE @@ -0,0 +1,8 @@ +subinclude("//build_defs:standard_children_build_def") + +standard_children_custom_target( + name = "standard_children_custom_target", + srcs = ["file.txt"], + outs = ["file_standard.out"], + outs_child = ["file_child.out"], +) diff --git a/test/export/test_custom_def_children/test_repo/build_defs/BUILD_FILE b/test/export/test_custom_def_children/test_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..00eed0f0b --- /dev/null +++ b/test/export/test_custom_def_children/test_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "standard_children_build_def", + srcs = ["standard_children.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_custom_def_children/test_repo/build_defs/standard_children.build_defs b/test/export/test_custom_def_children/test_repo/build_defs/standard_children.build_defs new file mode 100644 index 000000000..081154550 --- /dev/null +++ b/test/export/test_custom_def_children/test_repo/build_defs/standard_children.build_defs @@ -0,0 +1,17 @@ +def standard_children_custom_target( + name:str, + srcs:list=[], + outs:list=[], + outs_child:list=[]): + genrule( + name = f"{name}#child", + srcs = srcs, + outs = outs_child, + cmd = "echo 'child' > $OUT && cat $SRCS >> $OUT ", + ) + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "echo 'main' > $OUT && cat $SRCS >> $OUT ", + ) diff --git a/test/export/test_custom_def_children/test_repo/file.txt b/test/export/test_custom_def_children/test_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_custom_def_children/test_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_custom_in_file_def/expected_repo/.plzconfig b/test/export/test_custom_in_file_def/expected_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_custom_in_file_def/expected_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_in_file_def/expected_repo/BUILD_FILE b/test/export/test_custom_in_file_def/expected_repo/BUILD_FILE new file mode 100644 index 000000000..699b589aa --- /dev/null +++ b/test/export/test_custom_in_file_def/expected_repo/BUILD_FILE @@ -0,0 +1,13 @@ +filegroup( + name = "simple_build_def", + srcs = ["simple.build_defs"], + visibility = ["//test_custom_defs/..."], +) + +subinclude(":simple_build_def") + +simple_custom_target( + name = "simple_custom_target", + srcs = ["file.txt"], + outs = ["file_simple.out"], +) diff --git a/test/export/test_custom_in_file_def/expected_repo/file.txt b/test/export/test_custom_in_file_def/expected_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_custom_in_file_def/expected_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_custom_in_file_def/expected_repo/simple.build_defs b/test/export/test_custom_in_file_def/expected_repo/simple.build_defs new file mode 100644 index 000000000..8fe3a6021 --- /dev/null +++ b/test/export/test_custom_in_file_def/expected_repo/simple.build_defs @@ -0,0 +1,10 @@ +def simple_custom_target( + name:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "cat $SRCS > $OUT", + ) diff --git a/test/export/test_custom_in_file_def/test_repo/.plzconfig b/test/export/test_custom_in_file_def/test_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_custom_in_file_def/test_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_in_file_def/test_repo/BUILD_FILE b/test/export/test_custom_in_file_def/test_repo/BUILD_FILE new file mode 100644 index 000000000..699b589aa --- /dev/null +++ b/test/export/test_custom_in_file_def/test_repo/BUILD_FILE @@ -0,0 +1,13 @@ +filegroup( + name = "simple_build_def", + srcs = ["simple.build_defs"], + visibility = ["//test_custom_defs/..."], +) + +subinclude(":simple_build_def") + +simple_custom_target( + name = "simple_custom_target", + srcs = ["file.txt"], + outs = ["file_simple.out"], +) diff --git a/test/export/test_custom_in_file_def/test_repo/file.txt b/test/export/test_custom_in_file_def/test_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_custom_in_file_def/test_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_custom_in_file_def/test_repo/simple.build_defs b/test/export/test_custom_in_file_def/test_repo/simple.build_defs new file mode 100644 index 000000000..8fe3a6021 --- /dev/null +++ b/test/export/test_custom_in_file_def/test_repo/simple.build_defs @@ -0,0 +1,10 @@ +def simple_custom_target( + name:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "cat $SRCS > $OUT", + ) From 10a244159fc6feebc9803ea7df5ea9b0543fcbf1 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 17:11:23 +0000 Subject: [PATCH 16/22] update deps test --- test/export/BUILD | 12 ++++++------ test/export/test_deps/expected_repo/.plzconfig | 2 ++ test/export/test_deps/expected_repo/BUILD_FILE | 17 +++++++++++++++++ test/export/test_deps/expected_repo/file1.txt | 1 + test/export/test_deps/expected_repo/file2.txt | 1 + .../expected_repo/other_deps/BUILD_FILE | 6 ++++++ test/export/test_deps/test_repo/.plzconfig | 2 ++ test/export/test_deps/test_repo/BUILD_FILE | 17 +++++++++++++++++ test/export/test_deps/test_repo/file1.txt | 1 + test/export/test_deps/test_repo/file2.txt | 1 + .../test_deps/test_repo/other_deps/BUILD_FILE | 6 ++++++ 11 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 test/export/test_deps/expected_repo/.plzconfig create mode 100644 test/export/test_deps/expected_repo/BUILD_FILE create mode 100644 test/export/test_deps/expected_repo/file1.txt create mode 100644 test/export/test_deps/expected_repo/file2.txt create mode 100644 test/export/test_deps/expected_repo/other_deps/BUILD_FILE create mode 100644 test/export/test_deps/test_repo/.plzconfig create mode 100644 test/export/test_deps/test_repo/BUILD_FILE create mode 100644 test/export/test_deps/test_repo/file1.txt create mode 100644 test/export/test_deps/test_repo/file2.txt create mode 100644 test/export/test_deps/test_repo/other_deps/BUILD_FILE diff --git a/test/export/BUILD b/test/export/BUILD index 79febe34e..7ceb50194 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -39,12 +39,12 @@ please_export_e2e_test( dir = "test_custom_def_children", ) -# # Export a target that depends on another target. -# please_export_e2e_test( -# name = "export_deps", -# export_targets = ["test_deps:dep2"], -# repo = "repo", -# ) +# Export a target that depends on another target. +please_export_e2e_test( + name = "export_deps", + export_targets = ["//:dep2"], + dir = "test_deps", +) # # Test multiple targets. # please_export_e2e_test( diff --git a/test/export/test_deps/expected_repo/.plzconfig b/test/export/test_deps/expected_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_deps/expected_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_deps/expected_repo/BUILD_FILE b/test/export/test_deps/expected_repo/BUILD_FILE new file mode 100644 index 000000000..453e9ba00 --- /dev/null +++ b/test/export/test_deps/expected_repo/BUILD_FILE @@ -0,0 +1,17 @@ +genrule( + name = "dep1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) + +genrule( + name = "dep2", + srcs = [ + "file2.txt", + ":dep1", + "//other_deps:other_target", + ], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/test_deps/expected_repo/file1.txt b/test/export/test_deps/expected_repo/file1.txt new file mode 100644 index 000000000..e2129701f --- /dev/null +++ b/test/export/test_deps/expected_repo/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/test/export/test_deps/expected_repo/file2.txt b/test/export/test_deps/expected_repo/file2.txt new file mode 100644 index 000000000..6c493ff74 --- /dev/null +++ b/test/export/test_deps/expected_repo/file2.txt @@ -0,0 +1 @@ +file2 diff --git a/test/export/test_deps/expected_repo/other_deps/BUILD_FILE b/test/export/test_deps/expected_repo/other_deps/BUILD_FILE new file mode 100644 index 000000000..72a20cf25 --- /dev/null +++ b/test/export/test_deps/expected_repo/other_deps/BUILD_FILE @@ -0,0 +1,6 @@ +genrule( + name = "other_target", + outs = ["other.txt"], + cmd = "echo 'other' > $OUT", + visibility = ["PUBLIC"], +) diff --git a/test/export/test_deps/test_repo/.plzconfig b/test/export/test_deps/test_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_deps/test_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_deps/test_repo/BUILD_FILE b/test/export/test_deps/test_repo/BUILD_FILE new file mode 100644 index 000000000..453e9ba00 --- /dev/null +++ b/test/export/test_deps/test_repo/BUILD_FILE @@ -0,0 +1,17 @@ +genrule( + name = "dep1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) + +genrule( + name = "dep2", + srcs = [ + "file2.txt", + ":dep1", + "//other_deps:other_target", + ], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/test_deps/test_repo/file1.txt b/test/export/test_deps/test_repo/file1.txt new file mode 100644 index 000000000..e2129701f --- /dev/null +++ b/test/export/test_deps/test_repo/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/test/export/test_deps/test_repo/file2.txt b/test/export/test_deps/test_repo/file2.txt new file mode 100644 index 000000000..6c493ff74 --- /dev/null +++ b/test/export/test_deps/test_repo/file2.txt @@ -0,0 +1 @@ +file2 diff --git a/test/export/test_deps/test_repo/other_deps/BUILD_FILE b/test/export/test_deps/test_repo/other_deps/BUILD_FILE new file mode 100644 index 000000000..72a20cf25 --- /dev/null +++ b/test/export/test_deps/test_repo/other_deps/BUILD_FILE @@ -0,0 +1,6 @@ +genrule( + name = "other_target", + outs = ["other.txt"], + cmd = "echo 'other' > $OUT", + visibility = ["PUBLIC"], +) From c90e3ba67b3a01ee1b57842aa163be2f99524096 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 17:22:42 +0000 Subject: [PATCH 17/22] update multiple targets and preload tests --- test/export/BUILD | 51 ++++++++----------- .../expected_repo/.plzconfig | 2 + .../expected_repo/BUILD_FILE | 13 +++++ .../expected_repo/file1.txt | 1 + .../expected_repo/file2.txt | 1 + .../test_repo/.plzconfig | 2 + .../test_repo/BUILD_FILE | 13 +++++ .../test_multiple_targets/test_repo/file1.txt | 1 + .../test_multiple_targets/test_repo/file2.txt | 1 + .../expected_repo}/.plzconfig | 1 + .../test_preload/expected_repo/BUILD_FILE | 5 ++ .../expected_repo}/build_defs/BUILD_FILE | 0 .../build_defs/preloaded.build_defs | 0 test/export/test_preload/test_repo/.plzconfig | 3 ++ .../test_repo}/BUILD_FILE | 6 +-- .../test_repo/build_defs/BUILD_FILE | 5 ++ .../test_repo/build_defs/preloaded.build_defs | 11 ++++ .../test => test_preload/test_repo}/file.txt | 0 .../expected_repo/.plzconfig | 3 ++ .../expected_repo/BUILD_FILE | 6 +++ .../expected_repo/build_defs/BUILD_FILE | 5 ++ .../build_defs/preloaded.build_defs | 11 ++++ .../test_use_preloaded/expected_repo/file.txt | 1 + .../test_use_preloaded/test_repo/.plzconfig | 3 ++ .../test_use_preloaded/test_repo/BUILD_FILE | 12 +++++ .../test_repo/build_defs/BUILD_FILE | 5 ++ .../test_repo/build_defs/preloaded.build_defs | 11 ++++ .../test_use_preloaded/test_repo/file.txt | 1 + 28 files changed, 140 insertions(+), 34 deletions(-) create mode 100644 test/export/test_multiple_targets/expected_repo/.plzconfig create mode 100644 test/export/test_multiple_targets/expected_repo/BUILD_FILE create mode 100644 test/export/test_multiple_targets/expected_repo/file1.txt create mode 100644 test/export/test_multiple_targets/expected_repo/file2.txt create mode 100644 test/export/test_multiple_targets/test_repo/.plzconfig create mode 100644 test/export/test_multiple_targets/test_repo/BUILD_FILE create mode 100644 test/export/test_multiple_targets/test_repo/file1.txt create mode 100644 test/export/test_multiple_targets/test_repo/file2.txt rename test/export/{repo_preload => test_preload/expected_repo}/.plzconfig (69%) create mode 100644 test/export/test_preload/expected_repo/BUILD_FILE rename test/export/{repo_preload => test_preload/expected_repo}/build_defs/BUILD_FILE (100%) rename test/export/{repo_preload => test_preload/expected_repo}/build_defs/preloaded.build_defs (100%) create mode 100644 test/export/test_preload/test_repo/.plzconfig rename test/export/{repo_preload/test => test_preload/test_repo}/BUILD_FILE (55%) create mode 100644 test/export/test_preload/test_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_preload/test_repo/build_defs/preloaded.build_defs rename test/export/{repo_preload/test => test_preload/test_repo}/file.txt (100%) create mode 100644 test/export/test_use_preloaded/expected_repo/.plzconfig create mode 100644 test/export/test_use_preloaded/expected_repo/BUILD_FILE create mode 100644 test/export/test_use_preloaded/expected_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_use_preloaded/expected_repo/build_defs/preloaded.build_defs create mode 100644 test/export/test_use_preloaded/expected_repo/file.txt create mode 100644 test/export/test_use_preloaded/test_repo/.plzconfig create mode 100644 test/export/test_use_preloaded/test_repo/BUILD_FILE create mode 100644 test/export/test_use_preloaded/test_repo/build_defs/BUILD_FILE create mode 100644 test/export/test_use_preloaded/test_repo/build_defs/preloaded.build_defs create mode 100644 test/export/test_use_preloaded/test_repo/file.txt diff --git a/test/export/BUILD b/test/export/BUILD index 7ceb50194..e56b0df69 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -46,37 +46,30 @@ please_export_e2e_test( dir = "test_deps", ) -# # Test multiple targets. -# please_export_e2e_test( -# name = "export_multiple", -# export_targets = [ -# "test_multiple:target1", -# "test_multiple:target2", -# ], -# repo = "repo", -# ) +# Test multiple targets. +please_export_e2e_test( + name = "export_multiple_targets", + export_targets = [ + "//:target1", + "//:target2", + ], + dir = "test_multiple_targets", +) -# # Export a target from a repo that preloads a build def. -# # This test purposely doesn't use the custom def but checks that the source files are still included. -# please_export_e2e_test( -# name = "export_preload_genrule", -# expect_output_contains = { -# # validating that export includes preloaded build def files -# "build_defs/preloaded.build_defs": "preloaded_target", -# "build_defs/BUILD_FILE": "preloaded_build_def", -# }, -# export_targets = ["test:native_not_including_preloaded"], -# repo = "repo_preload", -# strict_check_build_stmt = True, -# ) +# Export a target from a repo that preloads a build def. +# This test purposely doesn't use the custom def but checks that the source files are still included. +please_export_e2e_test( + name = "export_preload_genrule", + export_targets = ["//:native_target"], + dir = "test_preload", +) -# # Export a custom target from a repo that preloads the build def used. -# please_export_e2e_test( -# name = "export_preload_use_preloaded_def", -# export_targets = ["test:use_preloaded_def"], -# repo = "repo_preload", -# strict_check_build_stmt = True, -# ) +# Export a custom target from a repo that preloads the build def used. +please_export_e2e_test( + name = "export_preload_use_preloaded_def", + export_targets = ["//:use_preloaded_def"], + dir = "test_use_preloaded", +) # # Test go binary target. # please_export_e2e_test( diff --git a/test/export/test_multiple_targets/expected_repo/.plzconfig b/test/export/test_multiple_targets/expected_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_multiple_targets/expected_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_multiple_targets/expected_repo/BUILD_FILE b/test/export/test_multiple_targets/expected_repo/BUILD_FILE new file mode 100644 index 000000000..e8bbf0d78 --- /dev/null +++ b/test/export/test_multiple_targets/expected_repo/BUILD_FILE @@ -0,0 +1,13 @@ +genrule( + name = "target1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) + +genrule( + name = "target2", + srcs = ["file2.txt"], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/test_multiple_targets/expected_repo/file1.txt b/test/export/test_multiple_targets/expected_repo/file1.txt new file mode 100644 index 000000000..e2129701f --- /dev/null +++ b/test/export/test_multiple_targets/expected_repo/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/test/export/test_multiple_targets/expected_repo/file2.txt b/test/export/test_multiple_targets/expected_repo/file2.txt new file mode 100644 index 000000000..6c493ff74 --- /dev/null +++ b/test/export/test_multiple_targets/expected_repo/file2.txt @@ -0,0 +1 @@ +file2 diff --git a/test/export/test_multiple_targets/test_repo/.plzconfig b/test/export/test_multiple_targets/test_repo/.plzconfig new file mode 100644 index 000000000..f8ba31854 --- /dev/null +++ b/test/export/test_multiple_targets/test_repo/.plzconfig @@ -0,0 +1,2 @@ +[Parse] +BuildFileName = BUILD_FILE diff --git a/test/export/test_multiple_targets/test_repo/BUILD_FILE b/test/export/test_multiple_targets/test_repo/BUILD_FILE new file mode 100644 index 000000000..e8bbf0d78 --- /dev/null +++ b/test/export/test_multiple_targets/test_repo/BUILD_FILE @@ -0,0 +1,13 @@ +genrule( + name = "target1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) + +genrule( + name = "target2", + srcs = ["file2.txt"], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/test_multiple_targets/test_repo/file1.txt b/test/export/test_multiple_targets/test_repo/file1.txt new file mode 100644 index 000000000..e2129701f --- /dev/null +++ b/test/export/test_multiple_targets/test_repo/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/test/export/test_multiple_targets/test_repo/file2.txt b/test/export/test_multiple_targets/test_repo/file2.txt new file mode 100644 index 000000000..6c493ff74 --- /dev/null +++ b/test/export/test_multiple_targets/test_repo/file2.txt @@ -0,0 +1 @@ +file2 diff --git a/test/export/repo_preload/.plzconfig b/test/export/test_preload/expected_repo/.plzconfig similarity index 69% rename from test/export/repo_preload/.plzconfig rename to test/export/test_preload/expected_repo/.plzconfig index c77f93d75..0b1b781c2 100644 --- a/test/export/repo_preload/.plzconfig +++ b/test/export/test_preload/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [parse] +BuildFileName = BUILD_FILE preloadsubincludes = //build_defs:preloaded_build_def diff --git a/test/export/test_preload/expected_repo/BUILD_FILE b/test/export/test_preload/expected_repo/BUILD_FILE new file mode 100644 index 000000000..cd9cc2b39 --- /dev/null +++ b/test/export/test_preload/expected_repo/BUILD_FILE @@ -0,0 +1,5 @@ +genrule( + name = "native_target", + outs = ["file_no_preload.out"], + cmd = "echo 'woosh' > $OUT", +) diff --git a/test/export/repo_preload/build_defs/BUILD_FILE b/test/export/test_preload/expected_repo/build_defs/BUILD_FILE similarity index 100% rename from test/export/repo_preload/build_defs/BUILD_FILE rename to test/export/test_preload/expected_repo/build_defs/BUILD_FILE diff --git a/test/export/repo_preload/build_defs/preloaded.build_defs b/test/export/test_preload/expected_repo/build_defs/preloaded.build_defs similarity index 100% rename from test/export/repo_preload/build_defs/preloaded.build_defs rename to test/export/test_preload/expected_repo/build_defs/preloaded.build_defs diff --git a/test/export/test_preload/test_repo/.plzconfig b/test/export/test_preload/test_repo/.plzconfig new file mode 100644 index 000000000..0b1b781c2 --- /dev/null +++ b/test/export/test_preload/test_repo/.plzconfig @@ -0,0 +1,3 @@ +[parse] +BuildFileName = BUILD_FILE +preloadsubincludes = //build_defs:preloaded_build_def diff --git a/test/export/repo_preload/test/BUILD_FILE b/test/export/test_preload/test_repo/BUILD_FILE similarity index 55% rename from test/export/repo_preload/test/BUILD_FILE rename to test/export/test_preload/test_repo/BUILD_FILE index 1b821ed99..fa4497840 100644 --- a/test/export/repo_preload/test/BUILD_FILE +++ b/test/export/test_preload/test_repo/BUILD_FILE @@ -1,16 +1,12 @@ -# BUILD_STMT_START native_not_including_preloaded genrule( - name = "native_not_including_preloaded", + name = "native_target", outs = ["file_no_preload.out"], cmd = "echo 'woosh' > $OUT", ) -# BUILD_STMT_END -# BUILD_STMT_START use_preloaded_def preloaded_target( name = "use_preloaded_def", srcs = ["file.txt"], outs = ["file_w_preload.out"], cmd = "cat", ) -# BUILD_STMT_END diff --git a/test/export/test_preload/test_repo/build_defs/BUILD_FILE b/test/export/test_preload/test_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..b3d36cb71 --- /dev/null +++ b/test/export/test_preload/test_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "preloaded_build_def", + srcs = ["preloaded.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_preload/test_repo/build_defs/preloaded.build_defs b/test/export/test_preload/test_repo/build_defs/preloaded.build_defs new file mode 100644 index 000000000..1666afbd0 --- /dev/null +++ b/test/export/test_preload/test_repo/build_defs/preloaded.build_defs @@ -0,0 +1,11 @@ +def preloaded_target( + name:str, + cmd:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = f"{cmd} $SRCS > $OUT", + ) diff --git a/test/export/repo_preload/test/file.txt b/test/export/test_preload/test_repo/file.txt similarity index 100% rename from test/export/repo_preload/test/file.txt rename to test/export/test_preload/test_repo/file.txt diff --git a/test/export/test_use_preloaded/expected_repo/.plzconfig b/test/export/test_use_preloaded/expected_repo/.plzconfig new file mode 100644 index 000000000..0b1b781c2 --- /dev/null +++ b/test/export/test_use_preloaded/expected_repo/.plzconfig @@ -0,0 +1,3 @@ +[parse] +BuildFileName = BUILD_FILE +preloadsubincludes = //build_defs:preloaded_build_def diff --git a/test/export/test_use_preloaded/expected_repo/BUILD_FILE b/test/export/test_use_preloaded/expected_repo/BUILD_FILE new file mode 100644 index 000000000..b57ba51de --- /dev/null +++ b/test/export/test_use_preloaded/expected_repo/BUILD_FILE @@ -0,0 +1,6 @@ +preloaded_target( + name = "use_preloaded_def", + srcs = ["file.txt"], + outs = ["file_w_preload.out"], + cmd = "cat", +) diff --git a/test/export/test_use_preloaded/expected_repo/build_defs/BUILD_FILE b/test/export/test_use_preloaded/expected_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..b3d36cb71 --- /dev/null +++ b/test/export/test_use_preloaded/expected_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "preloaded_build_def", + srcs = ["preloaded.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_use_preloaded/expected_repo/build_defs/preloaded.build_defs b/test/export/test_use_preloaded/expected_repo/build_defs/preloaded.build_defs new file mode 100644 index 000000000..1666afbd0 --- /dev/null +++ b/test/export/test_use_preloaded/expected_repo/build_defs/preloaded.build_defs @@ -0,0 +1,11 @@ +def preloaded_target( + name:str, + cmd:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = f"{cmd} $SRCS > $OUT", + ) diff --git a/test/export/test_use_preloaded/expected_repo/file.txt b/test/export/test_use_preloaded/expected_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_use_preloaded/expected_repo/file.txt @@ -0,0 +1 @@ +Test source file diff --git a/test/export/test_use_preloaded/test_repo/.plzconfig b/test/export/test_use_preloaded/test_repo/.plzconfig new file mode 100644 index 000000000..0b1b781c2 --- /dev/null +++ b/test/export/test_use_preloaded/test_repo/.plzconfig @@ -0,0 +1,3 @@ +[parse] +BuildFileName = BUILD_FILE +preloadsubincludes = //build_defs:preloaded_build_def diff --git a/test/export/test_use_preloaded/test_repo/BUILD_FILE b/test/export/test_use_preloaded/test_repo/BUILD_FILE new file mode 100644 index 000000000..fa4497840 --- /dev/null +++ b/test/export/test_use_preloaded/test_repo/BUILD_FILE @@ -0,0 +1,12 @@ +genrule( + name = "native_target", + outs = ["file_no_preload.out"], + cmd = "echo 'woosh' > $OUT", +) + +preloaded_target( + name = "use_preloaded_def", + srcs = ["file.txt"], + outs = ["file_w_preload.out"], + cmd = "cat", +) diff --git a/test/export/test_use_preloaded/test_repo/build_defs/BUILD_FILE b/test/export/test_use_preloaded/test_repo/build_defs/BUILD_FILE new file mode 100644 index 000000000..b3d36cb71 --- /dev/null +++ b/test/export/test_use_preloaded/test_repo/build_defs/BUILD_FILE @@ -0,0 +1,5 @@ +filegroup( + name = "preloaded_build_def", + srcs = ["preloaded.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/test/export/test_use_preloaded/test_repo/build_defs/preloaded.build_defs b/test/export/test_use_preloaded/test_repo/build_defs/preloaded.build_defs new file mode 100644 index 000000000..1666afbd0 --- /dev/null +++ b/test/export/test_use_preloaded/test_repo/build_defs/preloaded.build_defs @@ -0,0 +1,11 @@ +def preloaded_target( + name:str, + cmd:str, + srcs:list=[], + outs:list=[]): + return genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = f"{cmd} $SRCS > $OUT", + ) diff --git a/test/export/test_use_preloaded/test_repo/file.txt b/test/export/test_use_preloaded/test_repo/file.txt new file mode 100644 index 000000000..9768ee14c --- /dev/null +++ b/test/export/test_use_preloaded/test_repo/file.txt @@ -0,0 +1 @@ +Test source file From 91da1541c37ac0a7a6becbe64e5da067e044f9ed Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 17:48:08 +0000 Subject: [PATCH 18/22] update go tests --- test/export/BUILD | 44 +++++++++---------- test/export/please_export_e2e_test.build_defs | 4 +- .../expected_repo/.plzconfig | 7 +++ .../expected_repo/BUILD_FILE | 9 ++++ .../expected_repo/main.go | 11 +++++ .../expected_repo/plugins/BUILD_FILE | 5 +++ .../expected_repo/third_party/go/BUILD_FILE | 12 +++++ .../test_repo/.plzconfig | 7 +++ .../test_repo/BUILD_FILE | 9 ++++ .../test_go_bin_with_go_dep/test_repo/main.go | 11 +++++ .../test_repo/plugins/BUILD_FILE | 5 +++ .../test_repo/third_party/go/BUILD_FILE | 12 +++++ .../test_go_binary/expected_repo/.plzconfig | 7 +++ .../expected_repo/pkg/BUILD_FILE | 6 +++ .../test_go_binary/expected_repo/pkg/main.go | 7 +++ .../expected_repo/plugins/BUILD_FILE | 5 +++ .../expected_repo/third_party/go/BUILD_FILE | 7 +++ .../test_go_binary/test_repo/.plzconfig | 7 +++ .../test_go_binary/test_repo/pkg/BUILD_FILE | 6 +++ .../test_go_binary/test_repo/pkg/main.go | 7 +++ .../test_repo/plugins/BUILD_FILE | 5 +++ .../test_repo/third_party/go/BUILD_FILE | 7 +++ .../expected_repo/.plzconfig | 7 +++ .../expected_repo/BUILD_FILE | 6 +++ .../expected_repo/plugins/BUILD_FILE | 5 +++ .../expected_repo/third_party/go/BUILD_FILE | 12 +++++ .../test_repo/.plzconfig | 7 +++ .../test_repo/BUILD_FILE | 6 +++ .../test_repo/main.go | 11 +++++ .../test_repo/plugins/BUILD_FILE | 5 +++ .../test_repo/third_party/go/BUILD_FILE | 12 +++++ 31 files changed, 245 insertions(+), 26 deletions(-) create mode 100644 test/export/test_go_bin_with_go_dep/expected_repo/.plzconfig create mode 100644 test/export/test_go_bin_with_go_dep/expected_repo/BUILD_FILE create mode 100644 test/export/test_go_bin_with_go_dep/expected_repo/main.go create mode 100644 test/export/test_go_bin_with_go_dep/expected_repo/plugins/BUILD_FILE create mode 100644 test/export/test_go_bin_with_go_dep/expected_repo/third_party/go/BUILD_FILE create mode 100644 test/export/test_go_bin_with_go_dep/test_repo/.plzconfig create mode 100644 test/export/test_go_bin_with_go_dep/test_repo/BUILD_FILE create mode 100644 test/export/test_go_bin_with_go_dep/test_repo/main.go create mode 100644 test/export/test_go_bin_with_go_dep/test_repo/plugins/BUILD_FILE create mode 100644 test/export/test_go_bin_with_go_dep/test_repo/third_party/go/BUILD_FILE create mode 100644 test/export/test_go_binary/expected_repo/.plzconfig create mode 100644 test/export/test_go_binary/expected_repo/pkg/BUILD_FILE create mode 100644 test/export/test_go_binary/expected_repo/pkg/main.go create mode 100644 test/export/test_go_binary/expected_repo/plugins/BUILD_FILE create mode 100644 test/export/test_go_binary/expected_repo/third_party/go/BUILD_FILE create mode 100644 test/export/test_go_binary/test_repo/.plzconfig create mode 100644 test/export/test_go_binary/test_repo/pkg/BUILD_FILE create mode 100644 test/export/test_go_binary/test_repo/pkg/main.go create mode 100644 test/export/test_go_binary/test_repo/plugins/BUILD_FILE create mode 100644 test/export/test_go_binary/test_repo/third_party/go/BUILD_FILE create mode 100644 test/export/test_native_target_with_go_dep/expected_repo/.plzconfig create mode 100644 test/export/test_native_target_with_go_dep/expected_repo/BUILD_FILE create mode 100644 test/export/test_native_target_with_go_dep/expected_repo/plugins/BUILD_FILE create mode 100644 test/export/test_native_target_with_go_dep/expected_repo/third_party/go/BUILD_FILE create mode 100644 test/export/test_native_target_with_go_dep/test_repo/.plzconfig create mode 100644 test/export/test_native_target_with_go_dep/test_repo/BUILD_FILE create mode 100644 test/export/test_native_target_with_go_dep/test_repo/main.go create mode 100644 test/export/test_native_target_with_go_dep/test_repo/plugins/BUILD_FILE create mode 100644 test/export/test_native_target_with_go_dep/test_repo/third_party/go/BUILD_FILE diff --git a/test/export/BUILD b/test/export/BUILD index e56b0df69..6c8b4e722 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -72,32 +72,28 @@ please_export_e2e_test( ) # # Test go binary target. -# please_export_e2e_test( -# name = "export_go_binary", -# export_targets = ["test_go_bin:dummy"], -# include_go = True, -# repo = "repo_go", -# strict_check_build_stmt = True, -# ) +please_export_e2e_test( + name = "export_go_binary", + export_targets = ["//pkg:go_bin"], + include_go = True, + dir = "test_go_binary", +) -# # Test native target with go third_party dependency. -# please_export_e2e_test( -# name = "export_native_target_with_go_dep", -# export_targets = ["test_go_dep:genrule_go_dep"], -# include_go = True, -# repo = "repo_go", -# # TODO Enable strict check after after support for trimming subincludes #3496 -# # strict_check_build_stmt = True, -# ) +# Test native target with go third_party dependency. +please_export_e2e_test( + name = "export_native_target_with_go_dep", + export_targets = ["//:genrule_go_dep"], + include_go = True, + dir = "test_native_target_with_go_dep", +) -# # Test go target with go third_party dependency. -# please_export_e2e_test( -# name = "export_go_target_with_go_dep", -# export_targets = ["test_go_dep:bin_go_dep"], -# include_go = True, -# repo = "repo_go", -# strict_check_build_stmt = True, -# ) +# Test go target with go third_party dependency. +please_export_e2e_test( + name = "export_go_target_with_go_dep", + export_targets = ["//:bin_go_dep"], + include_go = True, + dir = "test_go_bin_with_go_dep", +) # # Generic catch-all test on internal repo. # plz_e2e_test( diff --git a/test/export/please_export_e2e_test.build_defs b/test/export/please_export_e2e_test.build_defs index 47d64ad3f..9db956ee3 100644 --- a/test/export/please_export_e2e_test.build_defs +++ b/test/export/please_export_e2e_test.build_defs @@ -12,6 +12,8 @@ def please_export_e2e_test( test_repo = f"{dir}/test_repo" expected_repo = f"{dir}/expected_repo" exported_repo = f"$DATA_TEST_REPO/{EXPORT_DIR}" + data = {} + tools = {} targets = " ".join(export_targets) @@ -32,11 +34,9 @@ def please_export_e2e_test( test_cmd = [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in test_cmd] test_cmd = ' && '.join(test_cmd) - data = {} data["TEST_REPO"] = [test_repo] data["EXPECTED_REPO"] = [expected_repo] - tools = {} tools["PLEASE"] = ["//package:installed_files|please"] return gentest( diff --git a/test/export/test_go_bin_with_go_dep/expected_repo/.plzconfig b/test/export/test_go_bin_with_go_dep/expected_repo/.plzconfig new file mode 100644 index 000000000..89210b615 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/expected_repo/.plzconfig @@ -0,0 +1,7 @@ +[Parse] +BuildFileName = BUILD # required by subrepos +BuildFileName = BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/test_go_bin_with_go_dep/expected_repo/BUILD_FILE b/test/export/test_go_bin_with_go_dep/expected_repo/BUILD_FILE new file mode 100644 index 000000000..d0d1a145c --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/expected_repo/BUILD_FILE @@ -0,0 +1,9 @@ +subinclude("///go//build_defs:go") + +go_binary( + name = "bin_go_dep", + srcs = ["main.go"], + deps = [ + "///third_party/go/github.com_google_go-cmp//cmp", + ], +) diff --git a/test/export/test_go_bin_with_go_dep/expected_repo/main.go b/test/export/test_go_bin_with_go_dep/expected_repo/main.go new file mode 100644 index 000000000..0853120a2 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/expected_repo/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/google/go-cmp/cmp" +) + +func main() { + fmt.Print(cmp.Equal(1, 1)) +} diff --git a/test/export/test_go_bin_with_go_dep/expected_repo/plugins/BUILD_FILE b/test/export/test_go_bin_with_go_dep/expected_repo/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/expected_repo/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/test_go_bin_with_go_dep/expected_repo/third_party/go/BUILD_FILE b/test/export/test_go_bin_with_go_dep/expected_repo/third_party/go/BUILD_FILE new file mode 100644 index 000000000..0af523288 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/expected_repo/third_party/go/BUILD_FILE @@ -0,0 +1,12 @@ +subinclude("///go//build_defs:go") + +package(default_visibility = ["PUBLIC"]) + +go_stdlib( + name = "std", +) + +go_repo( + module = "github.com/google/go-cmp", + version = "v0.5.6", +) diff --git a/test/export/test_go_bin_with_go_dep/test_repo/.plzconfig b/test/export/test_go_bin_with_go_dep/test_repo/.plzconfig new file mode 100644 index 000000000..89210b615 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/test_repo/.plzconfig @@ -0,0 +1,7 @@ +[Parse] +BuildFileName = BUILD # required by subrepos +BuildFileName = BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/test_go_bin_with_go_dep/test_repo/BUILD_FILE b/test/export/test_go_bin_with_go_dep/test_repo/BUILD_FILE new file mode 100644 index 000000000..d0d1a145c --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/test_repo/BUILD_FILE @@ -0,0 +1,9 @@ +subinclude("///go//build_defs:go") + +go_binary( + name = "bin_go_dep", + srcs = ["main.go"], + deps = [ + "///third_party/go/github.com_google_go-cmp//cmp", + ], +) diff --git a/test/export/test_go_bin_with_go_dep/test_repo/main.go b/test/export/test_go_bin_with_go_dep/test_repo/main.go new file mode 100644 index 000000000..0853120a2 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/test_repo/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/google/go-cmp/cmp" +) + +func main() { + fmt.Print(cmp.Equal(1, 1)) +} diff --git a/test/export/test_go_bin_with_go_dep/test_repo/plugins/BUILD_FILE b/test/export/test_go_bin_with_go_dep/test_repo/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/test_repo/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/test_go_bin_with_go_dep/test_repo/third_party/go/BUILD_FILE b/test/export/test_go_bin_with_go_dep/test_repo/third_party/go/BUILD_FILE new file mode 100644 index 000000000..0af523288 --- /dev/null +++ b/test/export/test_go_bin_with_go_dep/test_repo/third_party/go/BUILD_FILE @@ -0,0 +1,12 @@ +subinclude("///go//build_defs:go") + +package(default_visibility = ["PUBLIC"]) + +go_stdlib( + name = "std", +) + +go_repo( + module = "github.com/google/go-cmp", + version = "v0.5.6", +) diff --git a/test/export/test_go_binary/expected_repo/.plzconfig b/test/export/test_go_binary/expected_repo/.plzconfig new file mode 100644 index 000000000..89210b615 --- /dev/null +++ b/test/export/test_go_binary/expected_repo/.plzconfig @@ -0,0 +1,7 @@ +[Parse] +BuildFileName = BUILD # required by subrepos +BuildFileName = BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/test_go_binary/expected_repo/pkg/BUILD_FILE b/test/export/test_go_binary/expected_repo/pkg/BUILD_FILE new file mode 100644 index 000000000..85165ce64 --- /dev/null +++ b/test/export/test_go_binary/expected_repo/pkg/BUILD_FILE @@ -0,0 +1,6 @@ +subinclude("///go//build_defs:go") + +go_binary( + name = "go_bin", + srcs = ["main.go"], +) diff --git a/test/export/test_go_binary/expected_repo/pkg/main.go b/test/export/test_go_binary/expected_repo/pkg/main.go new file mode 100644 index 000000000..155420a26 --- /dev/null +++ b/test/export/test_go_binary/expected_repo/pkg/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Print("Woop Woop") +} diff --git a/test/export/test_go_binary/expected_repo/plugins/BUILD_FILE b/test/export/test_go_binary/expected_repo/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/test_go_binary/expected_repo/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/test_go_binary/expected_repo/third_party/go/BUILD_FILE b/test/export/test_go_binary/expected_repo/third_party/go/BUILD_FILE new file mode 100644 index 000000000..3263e5ba4 --- /dev/null +++ b/test/export/test_go_binary/expected_repo/third_party/go/BUILD_FILE @@ -0,0 +1,7 @@ +subinclude("///go//build_defs:go") + +package(default_visibility = ["PUBLIC"]) + +go_stdlib( + name = "std", +) diff --git a/test/export/test_go_binary/test_repo/.plzconfig b/test/export/test_go_binary/test_repo/.plzconfig new file mode 100644 index 000000000..89210b615 --- /dev/null +++ b/test/export/test_go_binary/test_repo/.plzconfig @@ -0,0 +1,7 @@ +[Parse] +BuildFileName = BUILD # required by subrepos +BuildFileName = BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/test_go_binary/test_repo/pkg/BUILD_FILE b/test/export/test_go_binary/test_repo/pkg/BUILD_FILE new file mode 100644 index 000000000..85165ce64 --- /dev/null +++ b/test/export/test_go_binary/test_repo/pkg/BUILD_FILE @@ -0,0 +1,6 @@ +subinclude("///go//build_defs:go") + +go_binary( + name = "go_bin", + srcs = ["main.go"], +) diff --git a/test/export/test_go_binary/test_repo/pkg/main.go b/test/export/test_go_binary/test_repo/pkg/main.go new file mode 100644 index 000000000..155420a26 --- /dev/null +++ b/test/export/test_go_binary/test_repo/pkg/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Print("Woop Woop") +} diff --git a/test/export/test_go_binary/test_repo/plugins/BUILD_FILE b/test/export/test_go_binary/test_repo/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/test_go_binary/test_repo/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/test_go_binary/test_repo/third_party/go/BUILD_FILE b/test/export/test_go_binary/test_repo/third_party/go/BUILD_FILE new file mode 100644 index 000000000..3263e5ba4 --- /dev/null +++ b/test/export/test_go_binary/test_repo/third_party/go/BUILD_FILE @@ -0,0 +1,7 @@ +subinclude("///go//build_defs:go") + +package(default_visibility = ["PUBLIC"]) + +go_stdlib( + name = "std", +) diff --git a/test/export/test_native_target_with_go_dep/expected_repo/.plzconfig b/test/export/test_native_target_with_go_dep/expected_repo/.plzconfig new file mode 100644 index 000000000..89210b615 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/expected_repo/.plzconfig @@ -0,0 +1,7 @@ +[Parse] +BuildFileName = BUILD # required by subrepos +BuildFileName = BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/test_native_target_with_go_dep/expected_repo/BUILD_FILE b/test/export/test_native_target_with_go_dep/expected_repo/BUILD_FILE new file mode 100644 index 000000000..69a21bbdd --- /dev/null +++ b/test/export/test_native_target_with_go_dep/expected_repo/BUILD_FILE @@ -0,0 +1,6 @@ +genrule( + name = "genrule_go_dep", + srcs = ["///third_party/go/github.com_google_go-cmp//cmp"], + outs = ["out.txt"], + cmd = "ls $SRCS > $OUT", +) diff --git a/test/export/test_native_target_with_go_dep/expected_repo/plugins/BUILD_FILE b/test/export/test_native_target_with_go_dep/expected_repo/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/expected_repo/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/test_native_target_with_go_dep/expected_repo/third_party/go/BUILD_FILE b/test/export/test_native_target_with_go_dep/expected_repo/third_party/go/BUILD_FILE new file mode 100644 index 000000000..0af523288 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/expected_repo/third_party/go/BUILD_FILE @@ -0,0 +1,12 @@ +subinclude("///go//build_defs:go") + +package(default_visibility = ["PUBLIC"]) + +go_stdlib( + name = "std", +) + +go_repo( + module = "github.com/google/go-cmp", + version = "v0.5.6", +) diff --git a/test/export/test_native_target_with_go_dep/test_repo/.plzconfig b/test/export/test_native_target_with_go_dep/test_repo/.plzconfig new file mode 100644 index 000000000..89210b615 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/test_repo/.plzconfig @@ -0,0 +1,7 @@ +[Parse] +BuildFileName = BUILD # required by subrepos +BuildFileName = BUILD_FILE + +[Plugin "go"] +Target = //plugins:go +stdlib = //third_party/go:std diff --git a/test/export/test_native_target_with_go_dep/test_repo/BUILD_FILE b/test/export/test_native_target_with_go_dep/test_repo/BUILD_FILE new file mode 100644 index 000000000..69a21bbdd --- /dev/null +++ b/test/export/test_native_target_with_go_dep/test_repo/BUILD_FILE @@ -0,0 +1,6 @@ +genrule( + name = "genrule_go_dep", + srcs = ["///third_party/go/github.com_google_go-cmp//cmp"], + outs = ["out.txt"], + cmd = "ls $SRCS > $OUT", +) diff --git a/test/export/test_native_target_with_go_dep/test_repo/main.go b/test/export/test_native_target_with_go_dep/test_repo/main.go new file mode 100644 index 000000000..0853120a2 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/test_repo/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/google/go-cmp/cmp" +) + +func main() { + fmt.Print(cmp.Equal(1, 1)) +} diff --git a/test/export/test_native_target_with_go_dep/test_repo/plugins/BUILD_FILE b/test/export/test_native_target_with_go_dep/test_repo/plugins/BUILD_FILE new file mode 100644 index 000000000..d8a4b2e66 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/test_repo/plugins/BUILD_FILE @@ -0,0 +1,5 @@ +plugin_repo( + name = "go", + plugin = "go-rules", + revision = "v1.21.5", +) diff --git a/test/export/test_native_target_with_go_dep/test_repo/third_party/go/BUILD_FILE b/test/export/test_native_target_with_go_dep/test_repo/third_party/go/BUILD_FILE new file mode 100644 index 000000000..0af523288 --- /dev/null +++ b/test/export/test_native_target_with_go_dep/test_repo/third_party/go/BUILD_FILE @@ -0,0 +1,12 @@ +subinclude("///go//build_defs:go") + +package(default_visibility = ["PUBLIC"]) + +go_stdlib( + name = "std", +) + +go_repo( + module = "github.com/google/go-cmp", + version = "v0.5.6", +) From d0cd6b784b0f9023e7a8d8a7c724fee3f1ce5757 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 18:06:44 +0000 Subject: [PATCH 19/22] update generic tests --- test/build_defs/test.build_defs | 6 +++- test/export/BUILD | 52 ++++++++++++++--------------- test/export/test_notrim/.plzconfig | 0 test/export/test_notrim/BUILD_FILE | 13 ++++++++ test/export/test_notrim/file1.txt | 1 + test/export/test_notrim/file2.txt | 1 + test/export/test_outputs/.plzconfig | 0 test/export/test_outputs/BUILD_FILE | 5 +++ 8 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 test/export/test_notrim/.plzconfig create mode 100644 test/export/test_notrim/BUILD_FILE create mode 100644 test/export/test_notrim/file1.txt create mode 100644 test/export/test_notrim/file2.txt create mode 100644 test/export/test_outputs/.plzconfig create mode 100644 test/export/test_outputs/BUILD_FILE diff --git a/test/build_defs/test.build_defs b/test/build_defs/test.build_defs index 5830e3f62..5a7f5a256 100644 --- a/test/build_defs/test.build_defs +++ b/test/build_defs/test.build_defs @@ -3,6 +3,7 @@ def please_repo_e2e_test( name: str, plz_command: str, repo: str, + defer_cmd: list = [], data: dict={}, deps: list=[], tools: dict={}, @@ -12,7 +13,6 @@ def please_repo_e2e_test( expect_output_doesnt_contain: dict = {}, labels: list = [], ): - plz_command = plz_command.replace("plz ", "$TOOLS_PLEASE ") if expected_failure: plz_command += "; [ ! $? -eq 0 ]" @@ -31,7 +31,11 @@ def please_repo_e2e_test( if expect_output_doesnt_contain: test_cmd += [f'_STR="$(cat {o})" _SUBSTR="{c}" && if [ -z "${_STR##*$_SUBSTR*}" ]; then echo "$_STR"; exit 1; fi' for o, c in expect_output_doesnt_contain.items()] + # defer commands should be added last + test_cmd += defer_cmd + test_cmd = ' && '.join(test_cmd) + test_cmd = test_cmd.replace("plz ", "$TOOLS_PLEASE ") data["REPO"] = [repo] data["BASE_CONFIG"] = ["//test/build_defs:base_config"] diff --git a/test/export/BUILD b/test/export/BUILD index 6c8b4e722..bd21cf045 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -95,31 +95,31 @@ please_export_e2e_test( dir = "test_go_bin_with_go_dep", ) -# # Generic catch-all test on internal repo. -# plz_e2e_test( -# name = "export_src_please_test", -# cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", -# ) +# Test outputs export. +please_repo_e2e_test( + name = "export_outputs", + defer_cmd = [ + 'test -f "plz-out/plzexport/some_output.txt"', + 'test ! -f "plz-out/plzexport/BUILD_FILE"', + ], + plz_command = "plz export outputs --output plz-out/plzexport //:out_target", + repo = "test_outputs", +) -# # Test outputs export. -# please_repo_e2e_test( -# name = "export_outputs", -# defer_cmd = [ -# 'test -f "plz-out/plzexport/some_output.txt"', -# 'test ! -f "plz-out/plzexport/BUILD_FILE"', -# ], -# plz_command = "plz export outputs --output plz-out/plzexport //test_outputs:out_target", -# repo = "repo", -# ) +# Test --notrim flag. +please_repo_e2e_test( + name = "export_notrim", + defer_cmd = [ + 'test -f "plz-out/plzexport/file2.txt"', + 'test -f "plz-out/plzexport/BUILD_FILE"', + 'grep -q \'name = "unrelated"\' "plz-out/plzexport/BUILD_FILE"', + ], + plz_command = "plz export --notrim --output plz-out/plzexport //:target1", + repo = "test_notrim", +) -# # Test --notrim flag. -# please_repo_e2e_test( -# name = "export_notrim", -# defer_cmd = [ -# 'test -f "plz-out/plzexport/test_notrim/file2.txt"', -# 'test -f "plz-out/plzexport/test_notrim/BUILD_FILE"', -# 'grep -q \'name = "unrelated"\' "plz-out/plzexport/test_notrim/BUILD_FILE"', -# ], -# plz_command = "plz export --notrim --output plz-out/plzexport //test_notrim:target1", -# repo = "repo", -# ) +# Generic catch-all test on internal repo. +plz_e2e_test( + name = "export_src_please_test", + cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core", +) diff --git a/test/export/test_notrim/.plzconfig b/test/export/test_notrim/.plzconfig new file mode 100644 index 000000000..e69de29bb diff --git a/test/export/test_notrim/BUILD_FILE b/test/export/test_notrim/BUILD_FILE new file mode 100644 index 000000000..3fce9ee8e --- /dev/null +++ b/test/export/test_notrim/BUILD_FILE @@ -0,0 +1,13 @@ +genrule( + name = "target1", + srcs = ["file1.txt"], + outs = ["out1.txt"], + cmd = "cat $SRCS > $OUT", +) + +genrule( + name = "unrelated", + srcs = ["file2.txt"], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/export/test_notrim/file1.txt b/test/export/test_notrim/file1.txt new file mode 100644 index 000000000..e2129701f --- /dev/null +++ b/test/export/test_notrim/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/test/export/test_notrim/file2.txt b/test/export/test_notrim/file2.txt new file mode 100644 index 000000000..6c493ff74 --- /dev/null +++ b/test/export/test_notrim/file2.txt @@ -0,0 +1 @@ +file2 diff --git a/test/export/test_outputs/.plzconfig b/test/export/test_outputs/.plzconfig new file mode 100644 index 000000000..e69de29bb diff --git a/test/export/test_outputs/BUILD_FILE b/test/export/test_outputs/BUILD_FILE new file mode 100644 index 000000000..f10a47d81 --- /dev/null +++ b/test/export/test_outputs/BUILD_FILE @@ -0,0 +1,5 @@ +genrule( + name = "out_target", + outs = ["some_output.txt"], + cmd = "echo 'hello world' > $OUT", +) From 41a345e86fd11311d5f5f7751f913aa8edf61a03 Mon Sep 17 00:00:00 2001 From: duarte Date: Wed, 25 Mar 2026 18:07:15 +0000 Subject: [PATCH 20/22] remove old repos --- test/export/repo/.plzconfig | 0 test/export/repo/test_builtins/BUILD_FILE | 16 ------------- test/export/repo/test_builtins/file.txt | 1 - test/export/repo/test_custom_defs/BUILD_FILE | 24 ------------------- .../test_custom_defs/build_defs/BUILD_FILE | 11 --------- .../build_defs/simple.build_defs | 10 -------- .../build_defs/standard_children.build_defs | 17 ------------- test/export/repo/test_custom_defs/file.txt | 1 - test/export/repo/test_deps/BUILD_FILE | 21 ---------------- test/export/repo/test_deps/file1.txt | 1 - test/export/repo/test_deps/file2.txt | 1 - test/export/repo/test_deps_other/BUILD_FILE | 8 ------- test/export/repo/test_multiple/BUILD_FILE | 17 ------------- test/export/repo/test_multiple/file1.txt | 1 - test/export/repo/test_multiple/file2.txt | 1 - test/export/repo/test_notrim/BUILD_FILE | 17 ------------- test/export/repo/test_notrim/file1.txt | 1 - test/export/repo/test_notrim/file2.txt | 1 - test/export/repo/test_outputs/BUILD_FILE | 5 ---- test/export/repo_go/.plzconfig | 6 ----- test/export/repo_go/plugins/BUILD_FILE | 5 ---- test/export/repo_go/test_go_bin/BUILD_FILE | 10 -------- test/export/repo_go/test_go_bin/main.go | 7 ------ test/export/repo_go/test_go_dep/BUILD_FILE | 22 ----------------- test/export/repo_go/test_go_dep/main.go | 11 --------- test/export/repo_go/third_party/go/BUILD_FILE | 12 ---------- 26 files changed, 227 deletions(-) delete mode 100644 test/export/repo/.plzconfig delete mode 100644 test/export/repo/test_builtins/BUILD_FILE delete mode 100644 test/export/repo/test_builtins/file.txt delete mode 100644 test/export/repo/test_custom_defs/BUILD_FILE delete mode 100644 test/export/repo/test_custom_defs/build_defs/BUILD_FILE delete mode 100644 test/export/repo/test_custom_defs/build_defs/simple.build_defs delete mode 100644 test/export/repo/test_custom_defs/build_defs/standard_children.build_defs delete mode 100644 test/export/repo/test_custom_defs/file.txt delete mode 100644 test/export/repo/test_deps/BUILD_FILE delete mode 100644 test/export/repo/test_deps/file1.txt delete mode 100644 test/export/repo/test_deps/file2.txt delete mode 100644 test/export/repo/test_deps_other/BUILD_FILE delete mode 100644 test/export/repo/test_multiple/BUILD_FILE delete mode 100644 test/export/repo/test_multiple/file1.txt delete mode 100644 test/export/repo/test_multiple/file2.txt delete mode 100644 test/export/repo/test_notrim/BUILD_FILE delete mode 100644 test/export/repo/test_notrim/file1.txt delete mode 100644 test/export/repo/test_notrim/file2.txt delete mode 100644 test/export/repo/test_outputs/BUILD_FILE delete mode 100644 test/export/repo_go/.plzconfig delete mode 100644 test/export/repo_go/plugins/BUILD_FILE delete mode 100644 test/export/repo_go/test_go_bin/BUILD_FILE delete mode 100644 test/export/repo_go/test_go_bin/main.go delete mode 100644 test/export/repo_go/test_go_dep/BUILD_FILE delete mode 100644 test/export/repo_go/test_go_dep/main.go delete mode 100644 test/export/repo_go/third_party/go/BUILD_FILE diff --git a/test/export/repo/.plzconfig b/test/export/repo/.plzconfig deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/export/repo/test_builtins/BUILD_FILE b/test/export/repo/test_builtins/BUILD_FILE deleted file mode 100644 index bfe0f4ab2..000000000 --- a/test/export/repo/test_builtins/BUILD_FILE +++ /dev/null @@ -1,16 +0,0 @@ -# BUILD_STMT_START native_genrule -genrule( - name = "native_genrule", - srcs = ["file.txt"], - outs = ["file.wordcount"], - cmd = "wc $SRCS > $OUT", -) -# BUILD_STMT_END - -# Dummy target to be trimmed -genrule( - name = "dummy", - srcs = ["file.txt"], - outs = ["dummy"], - cmd = "cat $SRCS > $OUT", -) diff --git a/test/export/repo/test_builtins/file.txt b/test/export/repo/test_builtins/file.txt deleted file mode 100644 index 9768ee14c..000000000 --- a/test/export/repo/test_builtins/file.txt +++ /dev/null @@ -1 +0,0 @@ -Test source file diff --git a/test/export/repo/test_custom_defs/BUILD_FILE b/test/export/repo/test_custom_defs/BUILD_FILE deleted file mode 100644 index aa6330182..000000000 --- a/test/export/repo/test_custom_defs/BUILD_FILE +++ /dev/null @@ -1,24 +0,0 @@ -# BUILD_STMT_START simple_custom_target -subinclude("//test_custom_defs/build_defs:simple_build_def") -# BUILD_STMT_END - -# BUILD_STMT_START simple_custom_target -simple_custom_target( - name = "simple_custom_target", - srcs = ["file.txt"], - outs = ["file_simple.out"], -) -# BUILD_STMT_END - -# BUILD_STMT_START standard_children_custom_target -subinclude("//test_custom_defs/build_defs:standard_children_build_def") -# BUILD_STMT_END - -# BUILD_STMT_START standard_children_custom_target -standard_children_custom_target( - name = "standard_children_custom_target", - srcs = ["file.txt"], - outs = ["file_standard.out"], - outs_child = ["file_child.out"], -) -# BUILD_STMT_END diff --git a/test/export/repo/test_custom_defs/build_defs/BUILD_FILE b/test/export/repo/test_custom_defs/build_defs/BUILD_FILE deleted file mode 100644 index db512e3a8..000000000 --- a/test/export/repo/test_custom_defs/build_defs/BUILD_FILE +++ /dev/null @@ -1,11 +0,0 @@ -filegroup( - name = "simple_build_def", - srcs = ["simple.build_defs"], - visibility = ["//test_custom_defs/..."], -) - -filegroup( - name = "standard_children_build_def", - srcs = ["standard_children.build_defs"], - visibility = ["//test_custom_defs/..."], -) diff --git a/test/export/repo/test_custom_defs/build_defs/simple.build_defs b/test/export/repo/test_custom_defs/build_defs/simple.build_defs deleted file mode 100644 index 8fe3a6021..000000000 --- a/test/export/repo/test_custom_defs/build_defs/simple.build_defs +++ /dev/null @@ -1,10 +0,0 @@ -def simple_custom_target( - name:str, - srcs:list=[], - outs:list=[]): - return genrule( - name = name, - srcs = srcs, - outs = outs, - cmd = "cat $SRCS > $OUT", - ) diff --git a/test/export/repo/test_custom_defs/build_defs/standard_children.build_defs b/test/export/repo/test_custom_defs/build_defs/standard_children.build_defs deleted file mode 100644 index 081154550..000000000 --- a/test/export/repo/test_custom_defs/build_defs/standard_children.build_defs +++ /dev/null @@ -1,17 +0,0 @@ -def standard_children_custom_target( - name:str, - srcs:list=[], - outs:list=[], - outs_child:list=[]): - genrule( - name = f"{name}#child", - srcs = srcs, - outs = outs_child, - cmd = "echo 'child' > $OUT && cat $SRCS >> $OUT ", - ) - return genrule( - name = name, - srcs = srcs, - outs = outs, - cmd = "echo 'main' > $OUT && cat $SRCS >> $OUT ", - ) diff --git a/test/export/repo/test_custom_defs/file.txt b/test/export/repo/test_custom_defs/file.txt deleted file mode 100644 index 9768ee14c..000000000 --- a/test/export/repo/test_custom_defs/file.txt +++ /dev/null @@ -1 +0,0 @@ -Test source file diff --git a/test/export/repo/test_deps/BUILD_FILE b/test/export/repo/test_deps/BUILD_FILE deleted file mode 100644 index 2240c467d..000000000 --- a/test/export/repo/test_deps/BUILD_FILE +++ /dev/null @@ -1,21 +0,0 @@ -# BUILD_STMT_START dep1 -genrule( - name = "dep1", - srcs = ["file1.txt"], - outs = ["out1.txt"], - cmd = "cat $SRCS > $OUT", -) -# BUILD_STMT_END - -# BUILD_STMT_START dep2 -genrule( - name = "dep2", - srcs = [ - "file2.txt", - ":dep1", - "//test_deps_other:other_target", - ], - outs = ["out2.txt"], - cmd = "cat $SRCS > $OUT", -) -# BUILD_STMT_END diff --git a/test/export/repo/test_deps/file1.txt b/test/export/repo/test_deps/file1.txt deleted file mode 100644 index e2129701f..000000000 --- a/test/export/repo/test_deps/file1.txt +++ /dev/null @@ -1 +0,0 @@ -file1 diff --git a/test/export/repo/test_deps/file2.txt b/test/export/repo/test_deps/file2.txt deleted file mode 100644 index 6c493ff74..000000000 --- a/test/export/repo/test_deps/file2.txt +++ /dev/null @@ -1 +0,0 @@ -file2 diff --git a/test/export/repo/test_deps_other/BUILD_FILE b/test/export/repo/test_deps_other/BUILD_FILE deleted file mode 100644 index 1c5fbb713..000000000 --- a/test/export/repo/test_deps_other/BUILD_FILE +++ /dev/null @@ -1,8 +0,0 @@ -# BUILD_STMT_START other_target -genrule( - name = "other_target", - outs = ["other.txt"], - cmd = "echo 'other' > $OUT", - visibility = ["PUBLIC"], -) -# BUILD_STMT_END diff --git a/test/export/repo/test_multiple/BUILD_FILE b/test/export/repo/test_multiple/BUILD_FILE deleted file mode 100644 index 3fd958da5..000000000 --- a/test/export/repo/test_multiple/BUILD_FILE +++ /dev/null @@ -1,17 +0,0 @@ -# BUILD_STMT_START target1 -genrule( - name = "target1", - srcs = ["file1.txt"], - outs = ["out1.txt"], - cmd = "cat $SRCS > $OUT", -) -# BUILD_STMT_END - -# BUILD_STMT_START target2 -genrule( - name = "target2", - srcs = ["file2.txt"], - outs = ["out2.txt"], - cmd = "cat $SRCS > $OUT", -) -# BUILD_STMT_END diff --git a/test/export/repo/test_multiple/file1.txt b/test/export/repo/test_multiple/file1.txt deleted file mode 100644 index e2129701f..000000000 --- a/test/export/repo/test_multiple/file1.txt +++ /dev/null @@ -1 +0,0 @@ -file1 diff --git a/test/export/repo/test_multiple/file2.txt b/test/export/repo/test_multiple/file2.txt deleted file mode 100644 index 6c493ff74..000000000 --- a/test/export/repo/test_multiple/file2.txt +++ /dev/null @@ -1 +0,0 @@ -file2 diff --git a/test/export/repo/test_notrim/BUILD_FILE b/test/export/repo/test_notrim/BUILD_FILE deleted file mode 100644 index 830f381b7..000000000 --- a/test/export/repo/test_notrim/BUILD_FILE +++ /dev/null @@ -1,17 +0,0 @@ -# BUILD_STMT_START target1 -genrule( - name = "target1", - srcs = ["file1.txt"], - outs = ["out1.txt"], - cmd = "cat $SRCS > $OUT", -) -# BUILD_STMT_END - -# BUILD_STMT_START unrelated -genrule( - name = "unrelated", - srcs = ["file2.txt"], - outs = ["out2.txt"], - cmd = "cat $SRCS > $OUT", -) -# BUILD_STMT_END diff --git a/test/export/repo/test_notrim/file1.txt b/test/export/repo/test_notrim/file1.txt deleted file mode 100644 index e2129701f..000000000 --- a/test/export/repo/test_notrim/file1.txt +++ /dev/null @@ -1 +0,0 @@ -file1 diff --git a/test/export/repo/test_notrim/file2.txt b/test/export/repo/test_notrim/file2.txt deleted file mode 100644 index 6c493ff74..000000000 --- a/test/export/repo/test_notrim/file2.txt +++ /dev/null @@ -1 +0,0 @@ -file2 diff --git a/test/export/repo/test_outputs/BUILD_FILE b/test/export/repo/test_outputs/BUILD_FILE deleted file mode 100644 index f10a47d81..000000000 --- a/test/export/repo/test_outputs/BUILD_FILE +++ /dev/null @@ -1,5 +0,0 @@ -genrule( - name = "out_target", - outs = ["some_output.txt"], - cmd = "echo 'hello world' > $OUT", -) diff --git a/test/export/repo_go/.plzconfig b/test/export/repo_go/.plzconfig deleted file mode 100644 index 51a718f2f..000000000 --- a/test/export/repo_go/.plzconfig +++ /dev/null @@ -1,6 +0,0 @@ -[Parse] -BuildFileName = BUILD # We override this in the e2e test profile and the subrepo has BUILD files not BUILD_FILE - -[Plugin "go"] -Target = //plugins:go -stdlib = //third_party/go:std diff --git a/test/export/repo_go/plugins/BUILD_FILE b/test/export/repo_go/plugins/BUILD_FILE deleted file mode 100644 index d8a4b2e66..000000000 --- a/test/export/repo_go/plugins/BUILD_FILE +++ /dev/null @@ -1,5 +0,0 @@ -plugin_repo( - name = "go", - plugin = "go-rules", - revision = "v1.21.5", -) diff --git a/test/export/repo_go/test_go_bin/BUILD_FILE b/test/export/repo_go/test_go_bin/BUILD_FILE deleted file mode 100644 index 3260bf080..000000000 --- a/test/export/repo_go/test_go_bin/BUILD_FILE +++ /dev/null @@ -1,10 +0,0 @@ -# BUILD_STMT_START dummy -subinclude("///go//build_defs:go") -# BUILD_STMT_END - -# BUILD_STMT_START dummy -go_binary( - name = "dummy", - srcs = ["main.go"], -) -# BUILD_STMT_END diff --git a/test/export/repo_go/test_go_bin/main.go b/test/export/repo_go/test_go_bin/main.go deleted file mode 100644 index 155420a26..000000000 --- a/test/export/repo_go/test_go_bin/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Print("Woop Woop") -} diff --git a/test/export/repo_go/test_go_dep/BUILD_FILE b/test/export/repo_go/test_go_dep/BUILD_FILE deleted file mode 100644 index 6ecfacc22..000000000 --- a/test/export/repo_go/test_go_dep/BUILD_FILE +++ /dev/null @@ -1,22 +0,0 @@ -# BUILD_STMT_START genrule_go_dep -genrule( - name = "genrule_go_dep", - srcs = ["///third_party/go/github.com_google_go-cmp//cmp"], - outs = ["out.txt"], - cmd = "ls $SRCS > $OUT", -) -# BUILD_STMT_END - -# BUILD_STMT_START bin_go_dep -subinclude("///go//build_defs:go") -# BUILD_STMT_END - -# BUILD_STMT_START bin_go_dep -go_binary( - name = "bin_go_dep", - srcs = ["main.go"], - deps = [ - "///third_party/go/github.com_google_go-cmp//cmp", - ], -) -# BUILD_STMT_END diff --git a/test/export/repo_go/test_go_dep/main.go b/test/export/repo_go/test_go_dep/main.go deleted file mode 100644 index 0853120a2..000000000 --- a/test/export/repo_go/test_go_dep/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/google/go-cmp/cmp" -) - -func main() { - fmt.Print(cmp.Equal(1, 1)) -} diff --git a/test/export/repo_go/third_party/go/BUILD_FILE b/test/export/repo_go/third_party/go/BUILD_FILE deleted file mode 100644 index 0af523288..000000000 --- a/test/export/repo_go/third_party/go/BUILD_FILE +++ /dev/null @@ -1,12 +0,0 @@ -subinclude("///go//build_defs:go") - -package(default_visibility = ["PUBLIC"]) - -go_stdlib( - name = "std", -) - -go_repo( - module = "github.com/google/go-cmp", - version = "v0.5.6", -) From b66f6327d4f73fd68dc8535d5bcbef2fd46eb47e Mon Sep 17 00:00:00 2001 From: duarte Date: Thu, 26 Mar 2026 11:10:32 +0000 Subject: [PATCH 21/22] doc string --- test/export/please_export_e2e_test.build_defs | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/export/please_export_e2e_test.build_defs b/test/export/please_export_e2e_test.build_defs index 9db956ee3..c266a0482 100644 --- a/test/export/please_export_e2e_test.build_defs +++ b/test/export/please_export_e2e_test.build_defs @@ -1,14 +1,30 @@ subinclude("//test/build_defs:build_defs") -# Runs an export e2e test. It purposely tests for different aspect (e.g. BUILD files, sources) -# within the same test to avoid the overhead of exporting multiple times. def please_export_e2e_test( name:str, - export_targets:list, dir:str, + export_targets:list, cmd_on_export:list=[], include_go:bool=False): - EXPORT_DIR="plz-out/plzexport" + """ + Runs an export e2e test. To use it, create a directory with both a `test_repo` with the targets + to be exported and an `expected_repo` with the expected resulting files. + The validation steps for the e2e test are: + * It performs a repo-wide diff between the exported files and the `expected_repo` + * Builds the exported target to ensure the exported repo, and consequently the + `expected_repo`, include valid sources and dependencies to build the target. + * Optionally you can specify additional commands to run on the exported directory by + passing them to `cmd_on_export`. + + Args: + name (str): Name of the test. + dir (str): A relative path to the directory containing `test_repo` and `expected_repo`. + export_targets (list): Targets to export as part of the test. + cmd_on_export (list): Optional. Additional commands to run on the exported directory. + include_go (bool): Optional. A flag to include Go dependencies in the e2e test. Use when + testing repos that include Go targets. + """ + EXPORT_DIR = "plz-out/plzexport" test_repo = f"{dir}/test_repo" expected_repo = f"{dir}/expected_repo" exported_repo = f"$DATA_TEST_REPO/{EXPORT_DIR}" @@ -32,7 +48,7 @@ def please_export_e2e_test( ] + [f'plz {config_override} --repo_root="{exported_repo}" {cmd}' for cmd in cmd_on_export] test_cmd = [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in test_cmd] - test_cmd = ' && '.join(test_cmd) + test_cmd = " && ".join(test_cmd) data["TEST_REPO"] = [test_repo] data["EXPECTED_REPO"] = [expected_repo] @@ -41,10 +57,10 @@ def please_export_e2e_test( return gentest( name = name, - test_cmd = test_cmd, - test_tools = tools, data = data, - no_test_output = True, labels = ["plz_e2e_test", "e2e"], + no_test_output = True, sandbox = False, + test_cmd = test_cmd, + test_tools = tools, ) From 0f8622f27b300c0bc4cb598a82f698edbe2e8616 Mon Sep 17 00:00:00 2001 From: duarte Date: Thu, 26 Mar 2026 11:11:13 +0000 Subject: [PATCH 22/22] linter --- test/export/BUILD | 20 +++++++++---------- .../test_builtins/expected_repo/.plzconfig | 1 + .../export/test_builtins/test_repo/.plzconfig | 1 + .../test_custom_def/expected_repo/.plzconfig | 1 + .../test_custom_def/test_repo/.plzconfig | 1 + .../expected_repo/.plzconfig | 1 + .../test_repo/.plzconfig | 1 + .../expected_repo/.plzconfig | 1 + .../test_repo/.plzconfig | 1 + .../export/test_deps/expected_repo/.plzconfig | 1 + test/export/test_deps/test_repo/.plzconfig | 1 + .../expected_repo/.plzconfig | 1 + .../test_repo/.plzconfig | 1 + 13 files changed, 22 insertions(+), 10 deletions(-) diff --git a/test/export/BUILD b/test/export/BUILD index bd21cf045..49958941b 100644 --- a/test/export/BUILD +++ b/test/export/BUILD @@ -16,16 +16,16 @@ please_export_e2e_test( # Export a target generated by a custom build def. please_export_e2e_test( name = "export_simple_custom_target", - export_targets = ["//:simple_custom_target"], dir = "test_custom_def", + export_targets = ["//:simple_custom_target"], ) # Export a target generated by a custom build def defined in the same # BUILD file. please_export_e2e_test( name = "export_custom_target_in_file", - export_targets = ["//:simple_custom_target"], dir = "test_custom_in_file_def", + export_targets = ["//:simple_custom_target"], ) # Export a target generated by a custom build def. @@ -35,64 +35,64 @@ please_export_e2e_test( # Child of build def "build //:standard_children_custom_target#child", ], - export_targets = ["//:standard_children_custom_target"], dir = "test_custom_def_children", + export_targets = ["//:standard_children_custom_target"], ) # Export a target that depends on another target. please_export_e2e_test( name = "export_deps", - export_targets = ["//:dep2"], dir = "test_deps", + export_targets = ["//:dep2"], ) # Test multiple targets. please_export_e2e_test( name = "export_multiple_targets", + dir = "test_multiple_targets", export_targets = [ "//:target1", "//:target2", ], - dir = "test_multiple_targets", ) # Export a target from a repo that preloads a build def. # This test purposely doesn't use the custom def but checks that the source files are still included. please_export_e2e_test( name = "export_preload_genrule", - export_targets = ["//:native_target"], dir = "test_preload", + export_targets = ["//:native_target"], ) # Export a custom target from a repo that preloads the build def used. please_export_e2e_test( name = "export_preload_use_preloaded_def", - export_targets = ["//:use_preloaded_def"], dir = "test_use_preloaded", + export_targets = ["//:use_preloaded_def"], ) # # Test go binary target. please_export_e2e_test( name = "export_go_binary", + dir = "test_go_binary", export_targets = ["//pkg:go_bin"], include_go = True, - dir = "test_go_binary", ) # Test native target with go third_party dependency. please_export_e2e_test( name = "export_native_target_with_go_dep", + dir = "test_native_target_with_go_dep", export_targets = ["//:genrule_go_dep"], include_go = True, - dir = "test_native_target_with_go_dep", ) # Test go target with go third_party dependency. please_export_e2e_test( name = "export_go_target_with_go_dep", + dir = "test_go_bin_with_go_dep", export_targets = ["//:bin_go_dep"], include_go = True, - dir = "test_go_bin_with_go_dep", ) # Test outputs export. diff --git a/test/export/test_builtins/expected_repo/.plzconfig b/test/export/test_builtins/expected_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_builtins/expected_repo/.plzconfig +++ b/test/export/test_builtins/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_builtins/test_repo/.plzconfig b/test/export/test_builtins/test_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_builtins/test_repo/.plzconfig +++ b/test/export/test_builtins/test_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def/expected_repo/.plzconfig b/test/export/test_custom_def/expected_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_custom_def/expected_repo/.plzconfig +++ b/test/export/test_custom_def/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def/test_repo/.plzconfig b/test/export/test_custom_def/test_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_custom_def/test_repo/.plzconfig +++ b/test/export/test_custom_def/test_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def_children/expected_repo/.plzconfig b/test/export/test_custom_def_children/expected_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_custom_def_children/expected_repo/.plzconfig +++ b/test/export/test_custom_def_children/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_def_children/test_repo/.plzconfig b/test/export/test_custom_def_children/test_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_custom_def_children/test_repo/.plzconfig +++ b/test/export/test_custom_def_children/test_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_in_file_def/expected_repo/.plzconfig b/test/export/test_custom_in_file_def/expected_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_custom_in_file_def/expected_repo/.plzconfig +++ b/test/export/test_custom_in_file_def/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_custom_in_file_def/test_repo/.plzconfig b/test/export/test_custom_in_file_def/test_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_custom_in_file_def/test_repo/.plzconfig +++ b/test/export/test_custom_in_file_def/test_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_deps/expected_repo/.plzconfig b/test/export/test_deps/expected_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_deps/expected_repo/.plzconfig +++ b/test/export/test_deps/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_deps/test_repo/.plzconfig b/test/export/test_deps/test_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_deps/test_repo/.plzconfig +++ b/test/export/test_deps/test_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_multiple_targets/expected_repo/.plzconfig b/test/export/test_multiple_targets/expected_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_multiple_targets/expected_repo/.plzconfig +++ b/test/export/test_multiple_targets/expected_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE diff --git a/test/export/test_multiple_targets/test_repo/.plzconfig b/test/export/test_multiple_targets/test_repo/.plzconfig index f8ba31854..8e1ae5655 100644 --- a/test/export/test_multiple_targets/test_repo/.plzconfig +++ b/test/export/test_multiple_targets/test_repo/.plzconfig @@ -1,2 +1,3 @@ [Parse] + BuildFileName = BUILD_FILE