Skip to content

Commit

Permalink
crashpad: use patches + msvc + win_helper.py -> py3
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed May 21, 2021
1 parent eb7a82a commit 38c4462
Show file tree
Hide file tree
Showing 11 changed files with 543 additions and 43 deletions.
16 changes: 16 additions & 0 deletions recipes/crashpad/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@ sources:
mini_chromium:
url: "https://github.com/chromium/mini_chromium/archive/ccb198907cecf072d8f5b2543d4d348e834a298a.zip"
sha256: "d526f659b0d44932bb4b5ff1277d855569572eb3fcad6ec1c69a71aac6a3d6ee"
patches:
"cci.20210507":
- patch_file: "patches/cci.20210507-0001-fix-openssl-link-order.patch"
base_path: "source_subfolder"
- patch_file: "patches/cci.20210507-0002-remove-fPIC-Werror-LTO.patch"
base_path: "source_subfolder"
- patch_file: "patches/cci.20210507-0003-compilers-from-env.patch"
base_path: "source_subfolder"
- patch_file: "patches/cci.20210507-0004-use-conan-linux-syscall-support-package.patch"
base_path: "source_subfolder"
- patch_file: "patches/cci.20210507-0005-allow-all-archs.patch"
base_path: "source_subfolder"
- patch_file: "patches/cci.20210507-0006-mini_chromium-win_helper-py3.patch"
base_path: "source_subfolder"
- patch_file: "patches/cci.20210507-0007-use-system-zlib.patch"
base_path: "source_subfolder"
64 changes: 21 additions & 43 deletions recipes/crashpad/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def validate(self):
if not self.options["libcurl"].shared:
# FIXME: is this true?
self.output.warn("crashpad needs a shared libcurl library")
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("Windows is not (yet) supported by this recipe because the build system requires python 2.x which is not (yet) available on CCI.")
# if self.settings.os == "Windows":
# raise ConanInvalidConfiguration("Windows is not (yet) supported by this recipe because the build system requires python 2.x which is not (yet) available on CCI.")

def source(self):
tools.get(**self.conan_data["sources"][self.version]["url"]["crashpad"], destination=self._source_subfolder, strip_root=True)
Expand Down Expand Up @@ -123,42 +123,18 @@ def _http_transport_impl(self):
return str(self.options.http_transport)

def build(self):
# Order of ssl and crypto is wrong (first ssl, then crypto)
tools.replace_in_file(os.path.join(self._source_subfolder, "util", "BUILD.gn"), "\"crypto\"", "SSL_LABEL")
tools.replace_in_file(os.path.join(self._source_subfolder, "util", "BUILD.gn"), "\"ssl\"", "\"crypto\"")
tools.replace_in_file(os.path.join(self._source_subfolder, "util", "BUILD.gn"), "SSL_LABEL", "\"ssl\"")

tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "zlib", "BUILD.gn"), "zlib_source = \"embedded\"", "zlib_source = \"system\"")
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "common.gypi"), "-fPIC", "")
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party","mini_chromium", "mini_chromium", "build", "config", "BUILD.gn"), "-fPIC", "")

# Allow compiling crashpad with gcc (fetch compiler from environment variables)
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "config", "BUILD.gn"),
"\"clang\"", "getenv(\"CC\")")
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "config", "BUILD.gn"),
"\"clang++\"", "getenv(\"CXX\")")
toolchain_path = os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "config", "BUILD.gn")

# Use conan linux-syscall-support package
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "lss", "lss.h"),
"include \"third_party/lss/linux_syscall_support.h\"",
"include <linux_syscall_support.h>")
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "lss", "lss.h"),
"include \"third_party/lss/lss/linux_syscall_support.h\"",
"include <linux_syscall_support.h>")

tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "config", "BUILD.gn"),
"assert(false, \"Unsupported architecture\")",
"print(\"Unknown architecture -> assume conan knows how to handle it\")")

tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "win_helper.py"),
"print line", "print(line)")
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "win_helper.py"),
"print result", "print(result)")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

if self.settings.compiler == "Visual Studio":
tools.replace_in_file(os.path.join(self._source_subfolder, "third_party", "zlib", "BUILD.gn"),
"libs = [ \"z\" ]",
"libs = [ {} ]".format(", ".join("\"{}.lib\"".format(l) for l in self.deps_cpp_info["zlib"].libs)))

if self.settings.compiler == "gcc":
toolchain_path = os.path.join(self._source_subfolder, "third_party", "mini_chromium", "mini_chromium", "build", "config", "BUILD.gn")
# Remove gcc-incompatible compiler arguments
for comp_arg in ("-Werror", "-Wheader-hygiene", "-Wnewline-eof", "-Wstring-conversion", "-Wexit-time-destructors", "-fobjc-call-cxx-cdtors", "-Wextra-semi", "-Wimplicit-fallthrough"):
for comp_arg in ("-Wheader-hygiene", "-Wnewline-eof", "-Wstring-conversion", "-Wexit-time-destructors", "-fobjc-call-cxx-cdtors", "-Wextra-semi", "-Wimplicit-fallthrough"):
tools.replace_in_file(toolchain_path,
"\"{}\"".format(comp_arg), "\"\"")

Expand All @@ -169,8 +145,8 @@ def build(self):
extra_ldflags = autotools.link_flags
if self.options.get_safe("fPIC"):
extra_cflags.append("-fPIC")
extra_cflags.extend("-I'{}'".format(inc) for inc in autotools.include_paths)
extra_ldflags.extend("-L'{}'".format(libdir) for libdir in autotools.library_paths)
extra_cflags.extend("-I {}".format(inc) for inc in autotools.include_paths)
extra_ldflags.extend("-{}{}".format("LIBPATH:" if self.settings.compiler == "Visual Studio" else "L ", libdir) for libdir in autotools.library_paths)
if self.settings.compiler == "clang":
if self.settings.compiler.get_safe("libcxx"):
stdlib = {
Expand All @@ -195,11 +171,9 @@ def build(self):
targets = ["client", "minidump", "crashpad_handler", "snapshot"]
if self.settings.os == "Windows":
targets.append("crashpad_handler_com")
for target in targets:
# FIXME: Remove verbose once everything is working hunky dory
self.run("ninja -C out/Default {target} -j{parallel}".format(
target=target,
parallel=tools.cpu_count()), run_environment=True)
self.run("ninja -C out/Default {targets} -j{parallel}".format(
targets=" ".join(targets),
parallel=tools.cpu_count()), run_environment=True)

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
Expand All @@ -211,9 +185,13 @@ def package(self):
self.copy("*.h", src=os.path.join(self._source_subfolder, "out", "Default", "gen", "build"), dst=os.path.join("include", "build"))

self.copy("*.a", src=os.path.join(self._source_subfolder, "out", "Default"), dst="lib", keep_path=False)
self.copy("*.lib", src=os.path.join(self._source_subfolder, "out", "Default"), dst="lib", keep_path=False)
self.copy("crashpad_handler", src=os.path.join(self._source_subfolder, "out", "Default"), dst="bin", keep_path=False)
self.copy("crashpad_handler.exe", src=os.path.join(self._source_subfolder, "out", "Default"), dst="bin", keep_path=False)
self.copy("crashpad_handler.com", src=os.path.join(self._source_subfolder, "out", "Default"), dst="bin", keep_path=False)
self.copy("crashpad_handler_com.com", src=os.path.join(self._source_subfolder, "out", "Default"), dst="bin", keep_path=False)

# Remove accidentally copied libraries. These are used by the executables, not by the libraries.
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*getopt*")

tools.save(os.path.join(self.package_folder, "lib", "cmake", "crashpad-cxx.cmake"),
textwrap.dedent("""\
Expand Down
245 changes: 245 additions & 0 deletions recipes/crashpad/all/patches/0002-all.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
diff -ur source/source_subfolder/third_party/lss/lss.h build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/lss/lss.h
--- source/source_subfolder/third_party/lss/lss.h 2021-05-21 23:40:37.288208700 +0200
+++ build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/lss/lss.h 2021-05-21 23:40:46.381240300 +0200
@@ -16,9 +16,9 @@
#define CRASHPAD_THIRD_PARTY_LSS_LSS_H_

#if defined(CRASHPAD_LSS_SOURCE_EXTERNAL)
-#include "third_party/lss/linux_syscall_support.h"
+#include <linux_syscall_support.h>
#elif defined(CRASHPAD_LSS_SOURCE_EMBEDDED)
-#include "third_party/lss/lss/linux_syscall_support.h"
+#include <linux_syscall_support.h>
#else
#error Unknown lss source
#endif
diff -ur source/source_subfolder/third_party/mini_chromium/mini_chromium/build/common.gypi build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/mini_chromium/mini_chromium/build/common.gypi
--- source/source_subfolder/third_party/mini_chromium/mini_chromium/build/common.gypi 2021-05-21 23:40:37.700972700 +0200
+++ build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/mini_chromium/mini_chromium/build/common.gypi 2021-05-21 23:40:46.354256400 +0200
@@ -124,7 +124,7 @@

['OS=="linux" or OS=="android"', {
'cflags': [
- '-fPIC',
+ '',
'-fno-exceptions',
'-fno-strict-aliasing', # See http://crbug.com/32204
'-fstack-protector-all', # Implies -fstack-protector
@@ -148,7 +148,7 @@
'_FILE_OFFSET_BITS=64',
],
'ldflags': [
- '-fPIC',
+ '',
'-pthread',
'-Wl,--as-needed',
'-Wl,-z,noexecstack',
diff -ur source/source_subfolder/third_party/mini_chromium/mini_chromium/build/config/BUILD.gn build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/mini_chromium/mini_chromium/build/config/BUILD.gn
--- source/source_subfolder/third_party/mini_chromium/mini_chromium/build/config/BUILD.gn 2021-05-21 23:40:37.702970800 +0200
+++ build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/mini_chromium/mini_chromium/build/config/BUILD.gn 2021-05-21 23:40:46.423216100 +0200
@@ -103,7 +103,7 @@
}
} else if (mini_chromium_is_win) {
cflags = [
- "/GL", # LTCG.
+ # LTCG.
"/O2",
"/Ob2", # Both explicit and auto inlining.
"/Oy-", # Disable omitting frame pointers, must be after /O2.
@@ -193,7 +193,7 @@
"arm64",
]
} else {
- assert(false, "Unsupported architecture")
+ print("Unknown architecture -> assume conan knows how to handle it")
}
}

@@ -239,7 +239,7 @@
"/D_UNICODE",
"/FS",
"/W4",
- "/WX",
+
"/Zi",
"/bigobj", # Support larger number of sections in obj file.
"/wd4100", # Unreferenced formal parameter.
@@ -268,7 +268,7 @@
"-m64",
]
} else {
- assert(false, "Unsupported architecture")
+ print("Unknown architecture -> assume conan knows how to handle it")
}

# This is currently required by the clang toolchain build that DEPS uses
@@ -302,7 +302,7 @@
} else if (target_cpu == "x64") {
common_flags += [ "--target=x86_64-fuchsia" ]
} else {
- assert(false, "Unsupported architecture")
+ print("Unknown architecture -> assume conan knows how to handle it")
}

# fdio is listed in ldflags instead of libs because it’s important for it to
@@ -319,7 +319,7 @@

if ((mini_chromium_is_posix && !mini_chromium_is_mac &&
!mini_chromium_is_ios) || mini_chromium_is_fuchsia) {
- cflags += [ "-fPIC" ]
+ cflags += [ "" ]
ldflags += [
# This must follow Fuchsia’s fdio library above.
"-Wl,--as-needed",
@@ -393,8 +393,8 @@
ar = rebase_path(clang_path, root_build_dir) + "/bin/llvm-ar"
ld = cxx
} else {
- cc = "clang"
- cxx = "clang++"
+ cc = getenv("CC")
+ cxx = getenv("CXX")
asm = cxx
ld = cxx

diff -ur source/source_subfolder/third_party/mini_chromium/mini_chromium/build/win_helper.py build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/mini_chromium/mini_chromium/build/win_helper.py
--- source/source_subfolder/third_party/mini_chromium/mini_chromium/build/win_helper.py 2021-05-21 23:40:37.715964200 +0200
+++ build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/mini_chromium/mini_chromium/build/win_helper.py 2021-05-21 23:40:46.406226100 +0200
@@ -4,7 +4,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

-import _winreg
+try:
+ import _winreg
+except ImportError:
+ import winreg as _winreg
import os
import re
import subprocess
@@ -62,7 +65,7 @@
CreateProcess() documentation for more details."""
block = ''
nul = '\0'
- for key, value in envvar_dict.iteritems():
+ for key, value in envvar_dict.items():
block += key + '=' + value + nul
block += nul
return block
@@ -81,7 +84,7 @@
archs = ('x86', 'amd64', 'arm64')
result = []
for arch in archs:
- # Extract environment variables for subprocesses.
+ sys.stderr.write("install_dir {} script_path {}".format(install_dir, script_path))
args = [os.path.join(install_dir, script_path)]
script_arch_name = arch
if script_path.endswith('SetEnv.cmd') and arch == 'amd64':
@@ -94,12 +97,12 @@
variables, _ = popen.communicate()
if popen.returncode != 0:
raise Exception('"%s" failed with error %d' % (args, popen.returncode))
- env = _ExtractImportantEnvironment(variables)
+ env = _ExtractImportantEnvironment(variables.decode())

env_block = _FormatAsEnvironmentBlock(env)
basename = 'environment.' + arch
with open(os.path.join(out_dir, basename), 'wb') as f:
- f.write(env_block)
+ f.write(env_block.encode())
result.append(basename)
return result

@@ -139,10 +142,10 @@
link = subprocess.Popen(args, env=env, shell=True, stdout=subprocess.PIPE)
out, _ = link.communicate()
for line in out.splitlines():
- if (not line.startswith(' Creating library ') and
- not line.startswith('Generating code') and
- not line.startswith('Finished generating code')):
- print line
+ if (not line.startswith(b' Creating library ') and
+ not line.startswith(b'Generating code') and
+ not line.startswith(b'Finished generating code')):
+ print(line)
return link.returncode

def ExecAsmWrapper(self, arch, *args):
@@ -152,11 +155,11 @@
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
for line in out.splitlines():
- if (not line.startswith('Copyright (C) Microsoft Corporation') and
- not line.startswith('Microsoft (R) Macro Assembler') and
- not line.startswith(' Assembling: ') and
+ if (not line.startswith(b'Copyright (C) Microsoft Corporation') and
+ not line.startswith(b'Microsoft (R) Macro Assembler') and
+ not line.startswith(b' Assembling: ') and
line):
- print line
+ print(line)
return popen.returncode

def ExecGetVisualStudioData(self, outdir, toolchain_path):
@@ -178,7 +181,7 @@
'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
if os.path.exists(vswhere_path):
installation_path = subprocess.check_output(
- [vswhere_path, '-latest', '-property', 'installationPath']).strip()
+ [vswhere_path, '-latest', '-property', 'installationPath']).strip().decode()
if installation_path:
return (installation_path,
os.path.join('VC', 'Auxiliary', 'Build', 'vcvarsall.bat'))
@@ -207,7 +210,7 @@
x86_environment_file = "%s"
x64_environment_file = "%s"
arm64_environment_file = "%s"''' % (install_dir, x86_file, x64_file, arm64_file)
- print result
+ print(result)
return 0

def ExecStamp(self, path):
diff -ur source/source_subfolder/third_party/zlib/BUILD.gn build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/zlib/BUILD.gn
--- source/source_subfolder/third_party/zlib/BUILD.gn 2021-05-21 23:40:37.300202000 +0200
+++ build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/third_party/zlib/BUILD.gn 2021-05-21 23:40:46.425215600 +0200
@@ -19,7 +19,7 @@
} else if (!crashpad_is_win && !crashpad_is_fuchsia) {
zlib_source = "system"
} else if (crashpad_is_standalone) {
- zlib_source = "embedded"
+ zlib_source = "system"
} else if (crashpad_is_external) {
zlib_source = "external_with_embedded_build"
}
@@ -46,7 +46,7 @@
} else if (zlib_source == "system") {
source_set("zlib") {
public_configs = [ ":zlib_config" ]
- libs = [ "z" ]
+ libs = [ "zlib.lib" ]
}
} else if (zlib_source == "embedded" ||
zlib_source == "external_with_embedded_build") {
diff -ur source/source_subfolder/util/BUILD.gn build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/util/BUILD.gn
--- source/source_subfolder/util/BUILD.gn 2021-05-21 23:40:37.318190700 +0200
+++ build/d140711d95cc16a85766a8fc3a551dfafe84cf63/source_subfolder/util/BUILD.gn 2021-05-21 23:40:46.344261900 +0200
@@ -402,8 +402,8 @@
deps += [ "//third_party/boringssl" ]
} else {
libs = [
- "crypto",
"ssl",
+ "crypto",
]
}
}
@@ -670,8 +670,8 @@
deps += [ "//third_party/boringssl" ]
} else {
libs = [
- "crypto",
"ssl",
+ "crypto",
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Order of ssl and crypto is wrong (first ssl, then crypto)
--- util/BUILD.gn
+++ util/BUILD.gn
@@ -402,8 +402,8 @@
deps += [ "//third_party/boringssl" ]
} else {
libs = [
- "crypto",
"ssl",
+ "crypto",
]
}
}
@@ -670,8 +670,8 @@
deps += [ "//third_party/boringssl" ]
} else {
libs = [
- "crypto",
"ssl",
+ "crypto",
]
}
}
Loading

0 comments on commit 38c4462

Please sign in to comment.