How do I use libproc.h in a modular Swift framework? - macos

I've followed all the steps from other similar questions, and I'm still stuck.
I need to use the function proc_pidpath in libproc.h to get the path of a BSD process by its PID. However, libproc.h is not a modular header, so I can't include it in my umbrella header:
Fair enough; now I try to include it in my module map:
framework module My_Modular_Framework {
umbrella header "My_Modular_Framework.h"
private header "/usr/include/libproc.h"
export *
module * { export * }
}
Well now I get this error-vomit where it seems like it thinks many system modules/headers are within my project:
I can't figure out what else to do. Like I said, I already tried following all the steps of other similar questions without any success. What can be done here? How can I use proc_pidpath? Is there another, more Swift-in-modular-framework friendly way to get a path from a process ID?
I don't want to enable "Allow Non-modular Includes In Framework Modules" because that defeats the purpose of a modular framework.

Since libproc.h and libproc.c are open-source (APSL 2.0) as a part of Apple's Darwin project, you can just include them (under the terms of the license, of course) in your project. Since neither imports any non-modular headers, you can compile it yourself and the compiler won't complain!

Related

Have specific scheme to use a specific target

I have an app with a module that contains two schemes, SchemeA and SchemeB.
When running SchemeA, it uses a target called FirstTargetA.
When running SchemeB, it uses a target called FirstTargetB.
I also have another module in my app which contains two targets: SecondTargetA and SecondTargetB. The only diff between those two are different custom flags.
I have added SecondTargetA as a framework to FirstTargetA and added SecondTargetB to FirstTargetA, but when I run SchemeB, FirstTargetB is actually calling SecondTargetB and I don't understand why. It should even know it as it's not in the General->Frameworks, Libraries and embedded content section.
Can anyone tell me what should I look for? What could I miss?

Globalize.js with MVC - missing locale

I'm trying to get the Globalize.js library to work under an ASP.NET MVC 5 application + unobstrusive validation. Specifically, I have most of the libraries and requirements working as per the post https://stackoverflow.com/a/25289555/1838819. However, when validation actually kicks in on an input tag of type="text" but contains a decimal number, I get the following error;
Uncaught Error: E_MISSING_BUNDLE: {"locale":"en"}
at createError (cldr.js:339)
at validate (cldr.js:355)
at Cldr.main (cldr.js:669)
at numberNumberingSystem (number.js:450)
at numberPattern (number.js:1325)
at Function.Globalize.numberParser.Globalize.numberParser (number.js:1429)
at Function.Globalize.parseNumber.Globalize.parseNumber (number.js:1474)
at a.validator.methods.number (jquery.validate.globalize.min.js:1)
at a.validator.check (jquery.validate.min.js:4)
at a.validator.checkForm (jquery.validate.min.js:4)
I'm loading and configuring the library via;
$.when($.get("/Scripts/cldr/supplemental/likelySubtags.json"))
.done(function(result) {
Globalize.load(result);
Globalize.locale("en");
});
Which works and runs through fine until validation is attempted via;
$.validator.unobtrusive.parse(_form);
_form.validate();
if (_form.valid()) { // ** error thrown here
_uiModalConfirmForm.modal('toggle');
}
I'm nearly sure that I'm missing a load reference to locale/en.json or something very similar but finding that resource is seemingly next to impossible. The documentation for cldr (what Globalize currently uses as it's main source of localized data), is...self referential at best and quite frustrating to navigate. There are no specific NuGet packages for this either that I can find.
The documentation that I can find says that the resource should be compiled. Looking at the documentation for that compiler links back to the Gloablize documentation and further goes on about spinning up a test server, installing Node Package Manger or Bower and installing from there. Which...seems like overkill when all I want is a file. I haven't yet gone down this road as I'm hoping there's an easier, quicker method to locate the needed file.
Any help on actually configuring the resources for this library in Visual studio would be greatly appreciated.
CLDR-core: https://github.com/unicode-cldr/cldr-core
Globalize doc: https://github.com/globalizejs/globalize/blob/master/README.md
likelySubtags.json (weirdly difficult to find): https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/likelySubtags.json

Using MaterializeCSS with Webpack - Cannot resolve module 'hammerjs'

I'm building a project with webpack. The project uses materializecss. When I add materialize.js to the entry file, it complains with the error below
Cannot resolve module 'hammerjs'
When I open the file, I can see the definition there but it appears webpack is unable to identify it. Same thing with weakmap in knockout-es6. My solution to this was to add a reference to hammer.min.js in resolve.alias but not sure if that is the correct thing to do.
How do I get webpack to recognize these dependencies when they are bundled together with the library in question - in this case materialize.js?
As long as you have hammerjs installed to your project (ie. npm i hammerjs --save), it should find it. As pointed out by #egunays you should also have import 'expose?Hammer!hammerjs/hammer to get access to Hammer object.
In case you are worried about possible duplication (you can verify this by examining the generated bundle), you can use webpack.optimize.DedupePlugin. webpack.optimize.CommonsChunkPlugin can come in handy as well. That will allow you to separate your app code from a vendor bundle.
See official optimization docs for more info.
It's better to use ProvidePlugin for this.
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"Hammer": "hammerjs/hammer"
}),
This does not require an extra loader and is actually recommended in the docs:
There are cases where you want a module to export itself to the global context. Don't do this unless you really need this. (Better use the ProvidePlugin) 1

How to find usage of non-public API in Mac Qt App

Our qtwebkit-based application is rejected by apple after submission to mac app store. One of the reasons for rejection is the usage of non-public API. I've managed found six of them in the source code for qtwebkit. But I have no where to find the rest. I searched through the source code of our application and the entire source code of QT.
The six non-public api I found in qtwebkit source is:
CFHTTPCookieStorageSetCookieAcceptPolicy
CFURLCacheCopyResponseForRequest
CFURLResponseGetMIMEType
CFURLResponseCopySuggestedFilename
CFURLCacheSetMemoryCapacity
CFURLCacheSetDiskCapacity
Here is the full list of violations found by apple:
The use of non-public APIs can lead to a poor user experience should
these APIs change in the future, and is therefore not permitted. The
following non-public APIs are included in your application:
NSAccessibilityCreateAXUIElementRef
NSAccessibilityHandleFocusChanged
NSAccessibilityUnregisterUniqueIdForUIElement NSAppKitPropertyCreator
NSCarbonWindowPropertyTag NSMouseMovedNotification
_NSDrawCarbonThemeBezel _NSDrawCarbonThemeListBox _NSPopUpCarbonMenu3 _NXShowKeyAndMain from the framework: '/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit'
AXTextMarkerCreate AXTextMarkerGetBytePtr AXTextMarkerGetLength
AXTextMarkerGetTypeID AXTextMarkerRangeCopyEndMarker
AXTextMarkerRangeCopyStartMarker AXTextMarkerRangeCreate
AXTextMarkerRangeGetTypeID CTLineCreateWithUniCharProvider
CoreDragGetCurrentDrag CoreDragSetImage from the framework:
'/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices'
GetNativeWindowFromWindowRef TSMGetInputSourceProperty from the
framework:
'/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon'
CFReadStreamSignalEvent _CFAppVersionCheckLessThan
_CFBundleSetDefaultLocalization _CFStringGetUserDefaultEncoding from the framework:
'/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation'
CFHTTPCookieStorageCopyCookiesForURL CFHTTPCookieStorageDeleteCookie
CFHTTPCookieStorageGetCookieAcceptPolicy
CFHTTPCookieStorageSetCookieAcceptPolicy
CFHTTPCookieStorageSetCookies CFURLCacheCopyResponseForRequest
CFURLCacheSetDiskCapacity CFURLCacheSetMemoryCapacity
CFURLRequestCreateMutableCopy CFURLResponseCopySuggestedFilename
CFURLResponseGetExpectedContentLength CFURLResponseGetHTTPResponse
CFURLResponseGetMIMEType CFURLResponseGetURL
CFURLResponseSetExpectedContentLength CFURLResponseSetMIMEType
_CFNetworkHTTPConnectionCacheGetLimit _CFNetworkHTTPConnectionCacheSetLimit _CFURLCacheCopyCacheDirectory _CFURLRequestCreateArchiveList _CFURLRequestCreateFromArchiveList _CFURLResponseCreateArchiveList _CFURLResponseCreateFromArchiveList _CFURLResponseGetSSLCertificateContext _LSGetCurrentApplicationASN _LSSetApplicationInformationItem _kLSDisplayNameKey kCFStreamPropertyCONNECTAdditionalHeaders
kCFStreamPropertyCONNECTProxy kCFStreamPropertyCONNECTProxyHost
kCFStreamPropertyCONNECTProxyPort kCFStreamPropertyCONNECTResponse
kCFURLResponseExpectedContentLengthUnknown from the framework:
'/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices'
NSPopAutoreleasePool NSPushAutoreleasePool from the framework:
'/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation'
CARenderCGDestroy CARenderCGNew CARenderCGRender
CARenderNotificationAddObserver CARenderNotificationRemoveObserver
CARenderServerGetPort CARenderServerStart CARenderUpdateAddContext
CARenderUpdateAddRect CARenderUpdateBegin CARenderUpdateFinish
kCAContextPortNumber from the framework:
'/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore'
If you have defined methods in your source code with the same names as
the above-mentioned APIs, we suggest altering your method names so
that they no longer collide with Apple's private APIs to avoid your
application being flagged in future submissions.
Additionally, one or more of the above-mentioned APIs may reside in a
library included with your application. If you do not have access to
the library's source, you may be able to search the compiled binary
using "strings" or "otool" command line tools. The "strings" tool can
output a list of the methods that the library calls and "otool -ov"
will output the Objective-C class structures and their defined
methods. These techniques can help you narrow down where the
problematic code resides.
I've finally traced down to the location where these so-called privatate apis are called. They are called from inside webkit. webkit uses a webkit system interface library which is directly supplied from apple in the format of compiled static library+header file. More specifically, they are the four files located under the path src\3rdparty\webkit\WebKitLibraries:
libWebKitSystemInterfaceLeopard.a
libWebKitSystemInterfaceLion.a
libWebKitSystemInterfaceMountainLion.a
libWebKitSystemInterfaceSnowLeopard.a
I always wondered if it's really a private api, who else would know how to call it without any documentation? Now it's turned out to be apple itself. Since neither nokia or digia has the source code to these libraries, there is probably nothing they can do about it.
Now isn't it ironic that any qtwebkit-based apps will be rejected by apple due to private api access from libraries created?
Please correct me if I am wrong or miss anything. I really hope I am wrong.

Building a plugin system for a nodejs based MVC platform

I would like to be able to build functionality for my application in a plugin style system for a couple reasons:
New projects can choose which plugins are necessary and not have code for functionality that's not needed
Other developers can build plugins for the system without needing too much knowledge of the core workings.
I'm not really sure how to go about implementing this. I would like to have a plugins folder to host these separately but I guess my questions are:
How do plugins interact with the core system?
How does the folder structure work? Would each hold the standard MVC structure: controllers, services, models, views, etc?
I guess if anyone has a tutorial or some documentation relating to this technique that would be helpful. I've done a bit of searching but it's all a little too closely related to the actual code they're working with instead of the concept and I hadn't found anything specifically related to nodejs.
I suggest an approach similar to what I've done on the uptime project (https://github.com/fzaninotto/uptime/blob/master/app.js#L46):
trigger application events in critical parts of your application
add a 'plugins' section in the applicaition configuration
each plugin name must be a package name. The plugin packages should return either a callback, or an object with an init() function.
either way, inject to the plugins the objects they will need to run (configuration, connections, etc) when calling init(), or executing the callback.
plugin modules register listeners to the application events and modify it
Benefits:
lightweight
rely on npm for dependencies
don't reivent the wheel
Create a plugin prototype for the base
functionality, and let the user define its plugin in a module. In the
module the user would inherit an object from the prototype, extend its
functionality, and then export a constructor which returns the plugin
object.
The main system loads all plugins by require("pluginname") and for
each calls the constructor.

Resources