Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
py-matplotlib: fix build failure in MacOSX backend
The earlier patch for the backend is obsolete already since matplotlib version 2.0.0.
- Loading branch information
1 parent
29bf0f4
commit b07e0eb
Showing
4 changed files
with
26 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
--- src/_macosx.m.orig 2019-05-18 14:01:10.000000000 -0400 | ||
+++ src/_macosx.m 2019-05-21 09:49:01.000000000 -0400 | ||
@@ -1,6 +1,9 @@ | ||
#define PY_SSIZE_T_CLEAN | ||
#include <Cocoa/Cocoa.h> | ||
#include <ApplicationServices/ApplicationServices.h> | ||
+#ifndef kCTForegroundColorFromContextAttributeName | ||
+extern const CFStringRef kCTForegroundColorFromContextAttributeName AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | ||
+#endif | ||
#include <sys/socket.h> | ||
#include <Python.h> | ||
|
||
In version 3.3.0 upstream started making use of features introduced | ||
in macOS 10.11, which caused failures when building the MacOSX | ||
backend on earlier macOS versions.. | ||
|
||
see: https://github.com/matplotlib/matplotlib/pull/17956 | ||
|
||
--- src/_macosx.m.orig 2020-07-18 17:50:09.000000000 -0400 | ||
+++ src/_macosx.m 2020-07-18 19:44:06.000000000 -0400 | ||
@@ -1207,8 +1207,12 @@ | ||
rect.size.height = 0; | ||
rect.origin.x += height; | ||
NSTextView* messagebox = [[NSTextView alloc] initWithFrame: rect]; | ||
- messagebox.textContainer.maximumNumberOfLines = 2; | ||
- messagebox.textContainer.lineBreakMode = NSLineBreakByTruncatingTail; | ||
+ | ||
+ if (@available(macOS 10.11, *)) { | ||
+ messagebox.textContainer.maximumNumberOfLines = 2; | ||
+ messagebox.textContainer.lineBreakMode = NSLineBreakByTruncatingTail; | ||
+ } | ||
+ | ||
[messagebox setFont: font]; | ||
[messagebox setDrawsBackground: NO]; | ||
[messagebox setSelectable: NO]; |
b07e0eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails to build on 10.11:
@available
is a relatively new compiler feature (added in Xcode 9) and it only helps you run code that was compiled on newer systems on earlier systems, so it's not very useful in MacPorts since we don't do that. It does not help you compile the code on earlier systems; for that, you need to hide newer code from older systems. For example, you could wrap those two lines in:That will only compile the code in if we're compiling with the 10.11 SDK or later and the macOS deployment target is 10.11 or later. I don't know what the consequence to the program would be of those settings being absent on older systems. The scenario of compiling with the 10.11 SDK but for an earlier deployment target should probably be handled better than my example. For example, you want to set the values if you detect at runtime that those symbols are available.
b07e0eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI the
@available
operator came in withmacports-clang-5.0
so any newer should accept it.As you say, it only helps building if you are building against a newer SDK that understands what is in the section guarded by the
@available
test.This is actively being encouraged and it is increasingly being used in macOS software I notice, so there may come a time when we have to more frequently build on older systems like 10.11 using a newer SDK and a macports-clang version > 5.0.
b07e0eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Or for a different approach, see https://trac.macports.org/ticket/60878.
b07e0eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @ryandesign for your explanation! I will go with your suggestion for now; the only side-effect for systems below 10.11 is that the scaling of a text-box in the plot windows isn't perfect (but that is the same behavior as in earlier matplotlib versions). At some point, we might need to stop compiling the
MacOSx
backend on older systems and hope that other ones still work (e.g., pickAgg
ad the default).