Skip to content

Commit

Permalink
py-matplotlib: fix build failure in MacOSX backend
Browse files Browse the repository at this point in the history
The earlier patch for the backend is obsolete already
since matplotlib version 2.0.0.
  • Loading branch information
reneeotten committed Jul 19, 2020
1 parent 29bf0f4 commit b07e0eb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 39 deletions.
8 changes: 3 additions & 5 deletions python/py-matplotlib/Portfile
Expand Up @@ -5,7 +5,7 @@ PortGroup python 1.0

name py-matplotlib
version 3.3.0
revision 0
revision 1

categories-append graphics math
platforms darwin
Expand Down Expand Up @@ -53,7 +53,7 @@ if {${name} ne ${subport}} {

if {${python.version} eq 27} {
version 2.2.5
revision 1
revision 2
checksums rmd160 4532a205e8f40d6f40346b2e461d3dca144b38b9 \
sha256 a3037a840cd9dfdc2df9fee8af8f76ca82bfab173c0f9468193ca7a89a2b60ea \
size 36678633
Expand All @@ -65,19 +65,17 @@ if {${name} ne ${subport}} {
port:py${python.version}-tz

patchfiles patch-v2-setup.cfg.diff \
patch-v2-src-macosx.m.diff \
patch-v2-qhull.diff \
patch-v2-setupext.py.diff \
patch-v2-jquery-ui.diff
} elseif {${python.version} eq 35} {
version 3.0.3
revision 2
revision 3
checksums rmd160 98ecd1ca25d555bde5d43fcaef800f7436d7d738 \
sha256 e1d33589e32f482d0a7d1957bf473d43341115d40d33f578dad44432e47df7b7 \
size 36640137

patchfiles patch-v30-setup.cfg.diff \
patch-v30-src-macosx.m.diff \
patch-v30-qhull.diff \
patch-v30-setupext.py.diff \
patch-v30-jquery-ui.diff
Expand Down
11 changes: 0 additions & 11 deletions python/py-matplotlib/files/patch-v2-src-macosx.m.diff

This file was deleted.

11 changes: 0 additions & 11 deletions python/py-matplotlib/files/patch-v30-src-macosx.m.diff

This file was deleted.

35 changes: 23 additions & 12 deletions python/py-matplotlib/files/patch-v33-src-macosx.m.diff
@@ -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];

4 comments on commit b07e0eb

@ryandesign
Copy link
Contributor

@ryandesign ryandesign commented on b07e0eb Jul 20, 2020

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:

error: unexpected '@' in program
    if (@available(macOS 10.11, *)) {
        ^
1 error generated.

@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:

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 && MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
        messagebox.textContainer.maximumNumberOfLines = 2;
        messagebox.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
#endif

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.

@kencu
Copy link
Contributor

@kencu kencu commented on b07e0eb Jul 20, 2020

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 with macports-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.

@ryandesign
Copy link
Contributor

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.

@reneeotten
Copy link
Contributor Author

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., pick Agg ad the default).

Please sign in to comment.