Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ idocument:
darwin-style-code:
node platform/darwin/scripts/generate-style-code.js
style-code: darwin-style-code

.PHONY: check-public-symbols
check-public-symbols:
node platform/darwin/scripts/check-public-symbols.js macOS
endif

#### Linux targets #####################################################
Expand Down
83 changes: 83 additions & 0 deletions platform/darwin/scripts/check-public-symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node

'use strict';

const fs = require('fs');
const path = require('path');
const execFileSync = require('child_process').execFileSync;
const _ = require('lodash');

const keyword = /\bMGL_EXPORT\b/;

let scanned = [];

function hasMissingSymbols(os) {
let missing = false;
let sdk = os === 'iOS' ? 'iphonesimulator' : 'macosx';
let sysroot = execFileSync('xcrun', ['--show-sdk-path', '--sdk', sdk]).toString().trim();
let umbrellaPath = `platform/${os.toLowerCase()}/src/Mapbox.h`;
let docArgs = ['doc', '--objc', umbrellaPath, '--',
'-x', 'objective-c', '-I', 'platform/darwin/src/', '-isysroot', sysroot];
let docStr = execFileSync('sourcekitten', docArgs).toString().trim();
let docJson = JSON.parse(docStr);
_.forEach(docJson, function (result) {
_.forEach(result, function (structure, path) {
// Prevent multiple scans of the same file.
if (scanned.indexOf(path) >= 0) return;
scanned.push(path);

const src = fs.readFileSync(path, 'utf8').split('\n');
_.forEach(structure['key.substructure'], function (substructure) {
switch (substructure['key.kind']) {
case 'sourcekitten.source.lang.objc.decl.class':
if (!(keyword.test(src[substructure['key.doc.line'] - 1]) || keyword.test(src[substructure['key.doc.line'] - 2]))) {
console.warn(`- missing symbol export for class ${substructure['key.name']} in ${path}:${substructure['key.doc.line']}:${substructure['key.doc.column']}`);
missing = true;
}
break;
case 'sourcekitten.source.lang.objc.decl.constant':
if (!keyword.test(src[substructure['key.doc.line'] - 1])) {
console.warn(`- missing symbol export for constant ${substructure['key.name']} in ${path}:${substructure['key.doc.line']}:${substructure['key.doc.column']}`);
missing = true;
}
break;
}
});
});
});

return missing;
}

function ensureSourceKittenIsInstalled() {
try {
execFileSync('which', ['sourcekitten']);
} catch (e) {
console.log(`Installing SourceKitten via Homebrew…`);
execFileSync('brew', ['install', 'sourcekitten']);
}
}

if (process.argv.length < 3) {
console.warn(`Usage: ${path.relative(process.cwd(), process.argv[1])} [macOS|iOS] ...`);
process.exit(1);
}

ensureSourceKittenIsInstalled();

let missing = false;
for (var i = 2; i < process.argv.length; i++) {
let os = process.argv[i];
if (os == 'iOS' || os == 'macOS') {
missing |= hasMissingSymbols(os);
} else {
console.warn(`Argument must be one of iOS or macOS`);
process.exit(1);
}
}

if (missing) {
process.exit(1);
} else {
console.warn(`All symbols are correctly exported.`);
}
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLAccountManager.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#import <Foundation/Foundation.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Apparently we need these import statements or else Swift declarations in the generated documentation lack specific types: realm/jazzy#609. Importing required system frameworks is good practice anyways, unless you use a precompiled header that imports them.

(Sorry, I started this review a couple weeks ago but forgot to publish it.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

MGLTypes.h imports Foundation.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As mentioned in that jazzy ticket, this header itself must import Foundation.h. It's unfortunate, but that shouldn't pose a problem for the visibility changes you're making, should it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m not sure why, but we don’t seem to be affected by realm/jazzy#609 even with these changes. Running make xdocument turns up some broken Swift declarations, but that happens on master too. (@incanus may have a stronger opinion than I about explicitly importing frameworks in headers. My concern was limited to jazzy output.)


#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/**
The MGLAccountManager object provides a global way to set a Mapbox API access
token.
*/
MGL_EXPORT
@interface MGLAccountManager : NSObject

#pragma mark Authorizing Access
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLAttributionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import <CoreGraphics/CoreGraphics.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"
#import "MGLTypes.h"

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -10,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
Information about an attribution statement, usually a copyright or trademark
statement, associated with a map content source.
*/
MGL_EXPORT
@interface MGLAttributionInfo : NSObject

/**
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLBackgroundStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLFoundation.h"
#import "MGLStyleValue.h"
#import "MGLStyleLayer.h"

Expand All @@ -12,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
`style` and obtain the background layer using the `-[MGLStyle layerWithIdentifier:]`
method and passing `background` for the identifier.
*/
MGL_EXPORT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change will get blown away as soon as anyone invokes make style-code. Make this change in platform/darwin/src/MGLStyleLayer.h.ejs and run make style-code to propagate the change to all the affected headers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is fixed

@interface MGLBackgroundStyleLayer : MGLStyleLayer

- (instancetype)initWithIdentifier:(NSString *)identifier NS_DESIGNATED_INITIALIZER;
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLFoundation.h"
#import "MGLStyleValue.h"
#import "MGLVectorStyleLayer.h"

Expand Down Expand Up @@ -44,6 +45,7 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
MGL_EXPORT
@interface MGLCircleStyleLayer : MGLVectorStyleLayer

#pragma mark - Accessing the Paint Attributes
Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLClockDirectionFormatter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/**
Expand All @@ -14,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
irrespective of the user’s orientation, use `MGLCompassDirectionFormatter`
instead.
*/
MGL_EXPORT
@interface MGLClockDirectionFormatter : NSFormatter

/**
Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLCompassDirectionFormatter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/**
Expand All @@ -12,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
irrespective of the user’s current location. To format a direction relative to
the user’s current location, use `MGLClockDirectionFormatter` instead.
*/
MGL_EXPORT
@interface MGLCompassDirectionFormatter : NSFormatter

/**
Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLCoordinateFormatter.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/**
The `MGLCoordinateFormatter` class provides properly formatted descriptions of
geographic coordinate pairs. Use this class to create localized coordinate
strings when displaying location information to users.
*/
MGL_EXPORT
@interface MGLCoordinateFormatter : NSFormatter

/**
Expand Down
8 changes: 8 additions & 0 deletions platform/darwin/src/MGLFeature.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>

#import "MGLFoundation.h"
#import "MGLPolyline.h"
#import "MGLPolygon.h"
#import "MGLPointAnnotation.h"
Expand Down Expand Up @@ -117,48 +118,55 @@ NS_ASSUME_NONNULL_BEGIN
The `MGLPointFeature` class represents a point in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLPointFeature : MGLPointAnnotation <MGLFeature>
@end

/**
The `MGLPolylineFeature` class represents a polyline in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLPolylineFeature : MGLPolyline <MGLFeature>
@end

/**
The `MGLPolygonFeature` class represents a polygon in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLPolygonFeature : MGLPolygon <MGLFeature>
@end

/**
The `MGLPointCollectionFeature` class represents a multipoint in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLPointCollectionFeature : MGLPointCollection <MGLFeature>
@end

/**
The `MGLMultiPolylineFeature` class represents a multipolyline in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLMultiPolylineFeature : MGLMultiPolyline <MGLFeature>
@end

/**
The `MGLMultiPolygonFeature` class represents a multipolygon in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLMultiPolygonFeature : MGLMultiPolygon <MGLFeature>
@end

/**
The `MGLShapeCollectionFeature` class represents a shape collection in a
<a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
*/
MGL_EXPORT
@interface MGLShapeCollectionFeature : MGLShapeCollection <MGLFeature>

@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLShape<MGLFeature> *) *shapes;
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLFeature_Private.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "MGLFoundation.h"
#import "MGLFeature.h"
#import "MGLShape.h"

Expand All @@ -11,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
Returns an array of `MGLFeature` objects converted from the given vector of
vector tile features.
*/
MGL_EXPORT
NS_ARRAY_OF(MGLShape <MGLFeature> *) *MGLFeaturesFromMBGLFeatures(const std::vector<mbgl::Feature> &features);

/**
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLFillStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLFoundation.h"
#import "MGLStyleValue.h"
#import "MGLVectorStyleLayer.h"

Expand Down Expand Up @@ -28,6 +29,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
MGL_EXPORT
@interface MGLFillStyleLayer : MGLVectorStyleLayer

#pragma mark - Accessing the Paint Attributes
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLForegroundStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>

#import "MGLFoundation.h"
#import "MGLStyleLayer.h"

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -14,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
subclasses of this class. Instead, create instances of `MGLRasterStyleLayer`
and the concrete subclasses of `MGLVectorStyleLayer`.
*/
MGL_EXPORT
@interface MGLForegroundStyleLayer : MGLStyleLayer

#pragma mark Initializing a Style Layer
Expand Down
5 changes: 5 additions & 0 deletions platform/darwin/src/MGLFoundation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#import <Foundation/Foundation.h>

#define MGL_EXPORT __attribute__((visibility ("default")))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How do we decide when something goes in MGLFoundation.h versus MGLTypes.h? Should we bring more macros over here, like the nullability and lightweight generics shims?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As per convention in other system frameworks, it has things that are required in virtually every header file. Most other *Foundation.h files I checked only have the export (or extern) macro.

4 changes: 3 additions & 1 deletion platform/darwin/src/MGLGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import <CoreLocation/CoreLocation.h>
#import <CoreGraphics/CGBase.h>

#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/** Defines the area spanned by an `MGLCoordinateBounds`. */
Expand Down Expand Up @@ -33,7 +35,7 @@ NS_INLINE BOOL MGLCoordinateSpanEqualToCoordinateSpan(MGLCoordinateSpan span1, M
}

/** An area of zero width and zero height. */
extern const MGLCoordinateSpan MGLCoordinateSpanZero;
extern MGL_EXPORT const MGLCoordinateSpan MGLCoordinateSpanZero;

/** A rectangular area as measured on a two-dimensional map projection. */
typedef struct MGLCoordinateBounds {
Expand Down
4 changes: 4 additions & 0 deletions platform/darwin/src/MGLGeometry.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "MGLGeometry_Private.h"

#import "MGLFoundation.h"

#import <mbgl/util/projection.hpp>

/** Vertical field of view, measured in degrees, for determining the altitude
Expand Down Expand Up @@ -30,13 +32,15 @@ CGRect MGLExtendRect(CGRect rect, CGPoint point) {
return rect;
}

MGL_EXPORT
CLLocationDistance MGLAltitudeForZoomLevel(double zoomLevel, CGFloat pitch, CLLocationDegrees latitude, CGSize size) {
CLLocationDistance metersPerPixel = mbgl::Projection::getMetersPerPixelAtLatitude(latitude, zoomLevel);
CLLocationDistance metersTall = metersPerPixel * size.height;
CLLocationDistance altitude = metersTall / 2 / std::tan(MGLRadiansFromDegrees(MGLAngularFieldOfView) / 2.);
return altitude * std::sin(M_PI_2 - MGLRadiansFromDegrees(pitch)) / std::sin(M_PI_2);
}

MGL_EXPORT
double MGLZoomLevelForAltitude(CLLocationDistance altitude, CGFloat pitch, CLLocationDegrees latitude, CGSize size) {
CLLocationDistance eyeAltitude = altitude / std::sin(M_PI_2 - MGLRadiansFromDegrees(pitch)) * std::sin(M_PI_2);
CLLocationDistance metersTall = eyeAltitude * 2 * std::tan(MGLRadiansFromDegrees(MGLAngularFieldOfView) / 2.);
Expand Down
2 changes: 2 additions & 0 deletions platform/darwin/src/MGLLineStyleLayer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLFoundation.h"
#import "MGLStyleValue.h"
#import "MGLVectorStyleLayer.h"

Expand Down Expand Up @@ -68,6 +69,7 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) {
`MGLMapView` for its `style` and obtain existing layers using the
`-[MGLStyle layerWithIdentifier:]` method.
*/
MGL_EXPORT
@interface MGLLineStyleLayer : MGLVectorStyleLayer

#pragma mark - Accessing the Layout Attributes
Expand Down
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLMapCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#import <CoreGraphics/CoreGraphics.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/**
An `MGLMapCamera` object represents a viewpoint from which the user observes
some point on an `MGLMapView`.
*/
MGL_EXPORT
@interface MGLMapCamera : NSObject <NSSecureCoding, NSCopying>

/** Coordinate at the center of the map view. */
Expand Down
Loading