comphead commented on code in PR #7382: URL: https://github.com/apache/datafusion-comet/pull/7382#discussion_r4459281143
########## dev/ci/test-jar-contents.py: ########## @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Check source-only JAR entries against both artifact roles using real ZIP files.""" + +from pathlib import Path +import subprocess +import tempfile +import unittest +import zipfile + +ROOT = Path(__file__).resolve().parents[2] +CHECKER = ROOT / "dev/ensure-jars-have-correct-contents.sh" +LICENSE = (ROOT / "dev/licenses/LICENSE-binary.txt").read_bytes() + + +class JarContents(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + self.main = self.jar("main.jar") + + def jar(self, name, entry=None): + path = self.root / name + with zipfile.ZipFile(path, "w") as archive: + archive.writestr("org/apache/comet/linux/amd64/libcomet.so", b"") + archive.writestr("META-INF/LICENSE", LICENSE) + if entry: + archive.writestr(entry, "// source\n") + return str(path) + + def check(self, *args): + return subprocess.run( + ["bash", str(CHECKER), *args], capture_output=True, text=True) + + def rejected(self, args, entry): + result = self.check(*args) + self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("unexpected contents", result.stdout) + self.assertIn(entry, result.stdout) + + def check_source_entry(self, entry): + artifact = self.jar("payload.jar", entry) + self.rejected([artifact], entry) + result = self.check(self.main, artifact) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + # Permissions must not leak into the main list, even for the same path. + self.rejected([self.main + ";" + artifact, artifact], entry) + self.rejected([artifact, artifact], entry) + + def test_module_descriptor(self): + self.check_source_entry("module-info.java") + + def test_plugins_source(self): + self.check_source_entry("org/apache/spark/Plugins.scala") + + def test_row_partition_source(self): + self.check_source_entry("org/apache/spark/shuffle/sort/RowPartition.scala") + + def test_unrelated_source_rejected_in_both_roles(self): + entry = "Unexpected.java" + artifact = self.jar("unexpected.jar", entry) + self.rejected([artifact], entry) + self.rejected([self.main, artifact], entry) Review Comment: The description lists eight checks (missing, truncated and duplicate `META-INF/LICENSE`, missing copyrights, non-native JARs, the RC1 artifact). This file has four, and all of them cover the source-only allowlist. Running the checker by hand from this head, a truncated or missing LICENSE fails, a missing sources JAR fails unless the third argument is `true`, and a lock file with lz4_flex 0.14.1 fails, but no committed test pins any of that. Could tests cover those cases, or the description match what is committed? Also, `check_source_entry` expects success with the real `native/Cargo.lock`, so a dependabot bump of `lz4_flex`, or of `zstd-sys` to a new Zstandard, now fails Preflight until `LICENSE-binary.txt` is edited. Is that intended? ########## dev/ensure-jars-have-correct-contents.sh: ########## @@ -147,6 +208,26 @@ for artifact in "${artifact_list[@]}"; do else echo "[INFO] Artifact looks correct: '$(basename "${artifact}")'" fi + + # Check the complete license text in both main and sources jars containing libcomet. + # Common/test-only jars without the native library keep their existing legal resources. + if jar tf "${artifact}" | tr -d '\r' | + grep -E '^org/apache/comet/[^/]+/[^/]+/(libcomet\.(so|dylib)|comet\.dll)$' > /dev/null; then + if ! check_native_license_versions; then + bad_artifacts=${bad_artifacts}+1 + continue + fi + license_count=$(jar tf "${artifact}" | tr -d '\r' | awk '$0 == "META-INF/LICENSE" { n++ } END { print n+0 }') Review Comment: This lists the same JAR three times per artifact (the content scan above, the native library probe here and the LICENSE count below). Could the entries be read once into a variable, for example `entries=$(jar tf "${artifact}" | tr -d '\r')`, and the three checks run on it? That also gives the `jar tf` failure one place to be handled, since the two new calls sit inside `if` and `$(...)`, where a failure does not reach the `SIGUSR1` trap. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
