From 97f463a70618b37d9cf32e1b4189768e290f439f Mon Sep 17 00:00:00 2001 From: mhucka Date: Sat, 8 Nov 2025 17:04:39 +0000 Subject: [PATCH 1/2] Reformat cuquantum_configure.bzl using Buildifier I missed this file in PR https://github.com/quantumlib/qsim/pull/948 --- third_party/cuquantum/cuquantum_configure.bzl | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index 6864bd16c..1038987ad 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -15,7 +15,6 @@ """Setup cuQuantum as external dependency""" _CUQUANTUM_ROOT = "CUQUANTUM_ROOT" - def _tpl(repository_ctx, tpl, substitutions = {}, out = None): if not out: out = tpl @@ -25,14 +24,12 @@ def _tpl(repository_ctx, tpl, substitutions = {}, out = None): substitutions, ) - def _fail(msg): """Output failure message when auto configuration fails.""" red = "\033[0;31m" no_color = "\033[0m" fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg)) - def _execute( repository_ctx, cmdline, @@ -60,7 +57,6 @@ def _execute( ])) return result - def _read_dir(repository_ctx, src_dir): """Returns a string with all files in a directory. @@ -76,18 +72,17 @@ def _read_dir(repository_ctx, src_dir): result = find_result.stdout return result - def _find_file(repository_ctx, filename): """Returns a string with a directory path including the filename. The returned string contains the parent path of the filename. """ result = repository_ctx.execute( - ["timeout", "5", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"]).stdout - result = result[:result.find(filename)+len(filename)] + ["timeout", "5", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"], + ).stdout + result = result[:result.find(filename) + len(filename)] return result - def _genrule(genrule_name, command, outs): """Returns a string with a genrule. @@ -121,7 +116,6 @@ def _norm_path(path): path = path[:-1] return path - def _symlink_genrule_for_dir( repository_ctx, src_dir, @@ -170,9 +164,9 @@ def _symlink_genrule_for_dir( """ if is_empty_genrule: if dest_dir != "": - target_path = "%s/%s.h" % (dest_dir, genrule_name) + target_path = "%s/%s.h" % (dest_dir, genrule_name) else: - target_path = genrule_name + target_path = genrule_name genrule = _genrule( genrule_name, "touch $(OUTS)", @@ -208,21 +202,20 @@ def _symlink_genrule_for_dir( ) return genrule - def _cuquantum_pip_impl(repository_ctx): if _CUQUANTUM_ROOT in repository_ctx.os.environ: - cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT] + cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT] else: - repository_ctx.os.environ[_CUQUANTUM_ROOT] = "" - cuquantum_root = "" + repository_ctx.os.environ[_CUQUANTUM_ROOT] = "" + cuquantum_root = "" if cuquantum_root == "": - cuquantum_header_path = _find_file(repository_ctx, "custatevec.h") - cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")] - custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so") + cuquantum_header_path = _find_file(repository_ctx, "custatevec.h") + cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")] + custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so") else: - cuquantum_header_path = "%s/include" % cuquantum_root - custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) + cuquantum_header_path = "%s/include" % cuquantum_root + custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) is_empty_genrule = cuquantum_header_path == "" or custatevec_shared_library_path == "" @@ -231,7 +224,7 @@ def _cuquantum_pip_impl(repository_ctx): cuquantum_header_path, "include", "cuquantum_header_include", - is_empty_genrule=is_empty_genrule, + is_empty_genrule = is_empty_genrule, ) custatevec_shared_library_rule = _symlink_genrule_for_dir( @@ -241,7 +234,7 @@ def _cuquantum_pip_impl(repository_ctx): "libcustatevec.so", [custatevec_shared_library_path], ["libcustatevec.so"], - is_empty_genrule=is_empty_genrule, + is_empty_genrule = is_empty_genrule, ) _tpl(repository_ctx, "BUILD", { @@ -249,7 +242,6 @@ def _cuquantum_pip_impl(repository_ctx): "%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule, }) - cuquantum_configure = repository_rule( implementation = _cuquantum_pip_impl, environ = [ From da688e3b4d1663935dae2c3766b540a1d1a04452 Mon Sep 17 00:00:00 2001 From: mhucka Date: Sat, 8 Nov 2025 17:28:38 +0000 Subject: [PATCH 2/2] Apply fix suggested by Gemini Code Assist From the review comment by Gemini Code Assist on GitHub: > The find command has a logic error. The `-quit` primary causes find to > exit immediately after printing the first match, so the subsequent > `-not -path "'*/.*'"` condition is never evaluated. This means the > intended filtering of dot-directories (like `.git`) is not happening. > Additionally, the single quotes in `"'*/.*'"` are passed literally to > find, which is incorrect as `repository_ctx.execute` does not use a shell > to strip them. > To correctly and robustly exclude dot-directories from the search, the > command should be modified. --- third_party/cuquantum/cuquantum_configure.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index 1038987ad..5b9414f63 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -78,7 +78,7 @@ def _find_file(repository_ctx, filename): The returned string contains the parent path of the filename. """ result = repository_ctx.execute( - ["timeout", "5", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"], + ["timeout", "5", "find", "/", "-path", "*/.*", "-prune", "-o", "-name", filename, "-print", "-quit"], ).stdout result = result[:result.find(filename) + len(filename)] return result