Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

openssl: add bash dependency #1251

Merged
merged 1 commit into from
Jan 9, 2024
Merged

openssl: add bash dependency #1251

merged 1 commit into from
Jan 9, 2024

Conversation

neheb
Copy link
Collaborator

@neheb neheb commented Oct 15, 2023

generator.sh relies on bash. Gives a better error message when not found.

@neheb
Copy link
Collaborator Author

neheb commented Oct 15, 2023

@nazar-pc should this be rewritten in python?

@eli-schwartz
Copy link
Member

It "only runs on Linux", so I see very little point in rewriting the generator.sh script in python for portability.

But if you're going to check for dependencies I'd check for perl and GNU Make too...

@neheb neheb force-pushed the rev branch 2 times, most recently from c878803 to f0aca06 Compare October 26, 2023 19:39
Comment on lines 33 to 54
# Copy meson.build template file
subprocess.run(["cp", "../../../meson.build.tmpl", "config/"])

# Clone the upstream OpenSSL repository
subprocess.run(["rm", "-rf", "openssl"])
subprocess.run(["git", "clone", "--depth", "1", "--branch", "openssl-" + openssl_version, "https://github.com/openssl/openssl.git"])

# Remove the config/archs directory
subprocess.run(["rm", "-rf", "config/archs"])

# Run the make command with LANG set to C
os.environ['LANG'] = 'C'
subprocess.run(["make", "-C", "config"])

# Copy generated files back into the correct place
find_cmd = 'mkdir -p ../../../generated-$(dirname "$1"); cp "$1" ../../../generated-"$1"'
subprocess.run(["find", "config/archs", "-name", "meson.build", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-name", "*.asm", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-name", "*.c", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-name", "*.h", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
subprocess.run(["find", "config/archs", "-iname", "*.s", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not understand the purpose of this PR.

But this right here.

This is not rewriting the generator from bash into python. This is just... no.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper rewrite would be much more complex to deal with globbing and whatnot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok?

So what exactly is wrong with the bash version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpine CI is lightweight and does not come with bash by default. It's probably not a good idea to mandate bash.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install a normal userland on the alpine CI then? idk what the problem is.

bash is more lightweight than python, that's for sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but python is needed for meson anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eli-schwartz updated version and ported more of these calls to python.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a bunch of find -execs in there...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came up with

+def copy_files(extension):
+    for root, _, files in os.walk("config/archs"):
+        for file in files:
+            if file.lower().endswith(extension.lower()):
+                source_path = os.path.join(root, file)
+                relative_path = os.path.relpath(source_path, search_dir)
+                destination_dir = os.path.join("../../../generated", os.path.dirname(relative_path))
+                destination_path = os.path.join(destination_dir, file)
+
+                os.makedirs(destination_dir, exist_ok=True)
+                shutil.copy(source_path, destination_path)
+
 # Change to the directory of the Bash script
 script_dir = os.path.dirname(os.path.abspath(__file__))
 os.chdir(script_dir)
@@ -47,12 +59,11 @@ os.environ['LANG'] = 'C'
 subprocess.run(["make", "-C", "config"])

 # Copy generated files back into the correct place
-find_cmd = 'mkdir -p ../../../generated-$(dirname "$1"); cp "$1" ../../../generated-"$1"'
-subprocess.run(["find", "config/archs", "-name", "meson.build", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
-subprocess.run(["find", "config/archs", "-name", "*.asm", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
-subprocess.run(["find", "config/archs", "-name", "*.c", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
-subprocess.run(["find", "config/archs", "-name", "*.h", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
-subprocess.run(["find", "config/archs", "-iname", "*.s", "-exec", "sh", "-c", find_cmd, "_ignored", "{}", ";"])
+copy_files("meson.build")
+copy_files(".asm")
+copy_files(".c")
+copy_files(".h")
+copy_files(".s")

I don't think it's equivalent.

@neheb neheb force-pushed the rev branch 6 times, most recently from 23a27d4 to 9e18b27 Compare October 27, 2023 00:21
@eli-schwartz
Copy link
Member

I'd feel a lot more comfortable if @nazar-pc okay'ed this, as the person most likely to be updating it in the future.

@nazar-pc
Copy link
Contributor

If we want to make it usable on Windows, this makes some sense, otherwise not really. This is exactly that kind of stuff Bash is well suited for: running a series of simple CLI commands one after another.

I don't really know Python, so maintaining Bash would probably be easier and it is arguably nicer to read than a bunch of subprocess.run. And except those enjoying doing OpenSSL upgrades, there is little value in this since CI will run this stuff once on Linux and publish all the necessary files as a wrap, so shouldn't really be necessary for most people to run this manually, let alone on Windows.

While I appreciate the effort, I'm not convinced this is better or necessary.

@neheb
Copy link
Collaborator Author

neheb commented Oct 30, 2023

Goal is Alpine compatibility. The Python code currently is not much different than the bash script.

@nazar-pc
Copy link
Contributor

Goal is Alpine compatibility.

apk add bash?

@eli-schwartz
Copy link
Member

Yeah but the original PR simply installed bash on Alpine (and the PR title still says that's what it does). So it's not clear why the goal suddenly became to rewrite it in python (especially if that causes it to be less easy for people working on updating the openssl wrap to do so).

"Install the bash package" is pretty compatible with Alpine, no?

@neheb
Copy link
Collaborator Author

neheb commented Oct 30, 2023

Sure but it’s an extra dependency.

@Tachi107
Copy link
Contributor

Tachi107 commented Nov 6, 2023

Goal is Alpine compatibility

What about removing the script's bashisms so that it runs on Alpine's sh? Doesn't look that hard.

@eli-schwartz
Copy link
Member

Doesn't look that hard.

Do tell.

@neheb
Copy link
Collaborator Author

neheb commented Nov 6, 2023

IIRC, the python script ran faster when I tested it. May have been a fluke.

@benoit-pierre
Copy link
Contributor

Or just install bash?

@eli-schwartz
Copy link
Member

Still waiting to hear what the POSIX sh version of the BASH_SOURCE bashism is.

@Tachi107
Copy link
Contributor

Tachi107 commented Nov 7, 2023

Still waiting to hear what the POSIX sh version of the BASH_SOURCE bashism is.

Not exactly as useful as BASH_SOURCE, but I've used $0 in the past and in worked for me

for d in glob.glob("../../../generated-config/archs/*/asm_avx2"):
shutil.rmtree(d)
for d in glob.glob("../../../generated-config/archs/*/*/crypto/buildinf.h"):
os.remove(d)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe go over a list of globs and remove everything within in a nested loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow.

generator.sh relies on bash. Gives a better error message when not
found.

Signed-off-by: Rosen Penev <[email protected]>
@neheb neheb merged commit 662e5e7 into mesonbuild:master Jan 9, 2024
8 checks passed
@neheb neheb deleted the rev branch January 9, 2024 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants