Skip to content

protobuf: do not use symlinks #2212

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,7 @@
"protoc"
],
"versions": [
"25.2-3",
"25.2-2",
"25.2-1",
"3.21.12-5",
Expand Down
8 changes: 6 additions & 2 deletions subprojects/packagefiles/protobuf/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
python = find_program('python3')
proto_includes_link = custom_target(
'proto_includes_link',
input: files('symlink.py'),
output: 'include', # directory adjacent to protoc binary
command: [python, '@INPUT@', meson.current_source_dir(), '@OUTPUT@'],
command: [
python,
files('symlink_or_copy.py'),
meson.current_source_dir(),
'@OUTPUT@',
],
)
proto_includes_link_dep = declare_dependency(
sources: proto_includes_link,
Expand Down
40 changes: 0 additions & 40 deletions subprojects/packagefiles/protobuf/src/symlink.py

This file was deleted.

67 changes: 67 additions & 0 deletions subprojects/packagefiles/protobuf/src/symlink_or_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python3

"""
Helper-script, a replacement to unix
`ln -s [source] [destination] || cp -r [source] [destination]` command
should work everywhere where meson does
"""

import argparse
import os
import platform
import shutil
import sys
from pathlib import Path


def main() -> int:
"""Your script main entry point"""

parser = argparse.ArgumentParser()
parser.add_argument("source")
parser.add_argument("destination")
args = parser.parse_args()

source = Path(args.source)
destination = Path(args.destination)
destination_parent = destination.absolute().parent

if not source.exists():
print("Source not found at:", source.absolute())
return -2
if not destination_parent.exists():
print("Destination directory not found at:", destination_parent)
return -3

relative_target = Path(os.path.relpath(source.absolute(), destination_parent))
print(f"creating symlink {destination} -> {relative_target}")
if destination.is_symlink():
destination.unlink()
elif destination.is_dir():
shutil.rmtree(destination)
try:
destination.symlink_to(relative_target, target_is_directory=source.is_dir())
except OSError as exc:
# 1314: A required privilege is not held by the client.
# Windows raises these errors when the script doesn't have
# sufficient (administrator) priviledges and Developer mode
# is not enabled (which enables regular users to create
# symlinks).
if platform.system() == "Windows" and exc.winerror == 1314:
try:
shutil.copytree(source, destination)
except (FileNotFoundError, NotADirectoryError, PermissionError) as exc:
print(exc, file=sys.stderr)
return -4
else:
print(exc, file=sys.stderr)
return -4
except (FileNotFoundError, PermissionError) as exc:
print(exc, file=sys.stderr)
return -4

return 0


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion tools/sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
'pcreposix.def'
],
'protobuf': [
'symlink.py',
'symlink_or_copy.py',
],
'sdl2': [
'find-dylib-name.py'
Expand Down
Loading