Based on productbuild's Distribution XML structure, pkg-ref's version attribute is auto-filled by productbuild itself. You can also specify the package version using a --version parameter to productbuild.
I made two packages: package A with version 1.0 and package B with the same binaries with version 2.0. These versions were given in three ways:
As --version parameter
As version of the binary being packed
version values inside the Distribution.xml file
However, it seems Installer doesn't bother checking version and just installs any package being run. If you install version 2.0 first and then run the version 1.0 package next, the app is overwritten.
How do I enforce Installer to check the versions? Is there a key/attribute/parameter I need to specify somewhere to make the package version sensitive?
In your Distribution.xml code, add this function:
function dontDowngrade(prefix) {
if (typeof(my.result) != 'undefined') my.result.message = system.localizedString('ERROR_2');
var bundle = system.files.bundleAtPath(prefix + '/Applications/YOURAPPNAMEHERE');
if (!bundle) {
return true;
}
var bundleKeyValue = bundle['CFBundleShortVersionString'];
if (!bundleKeyValue) {
return true;
}
if (system.compareVersions(bundleKeyValue, '$packageVersion') > 0) {
return false;
}
return true;
}
The error string ERROR_2 is in Localizable.strings:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ERROR_0</key>
<string>This update requires Mac OS X version %# or later.</string>
<key>ERROR_1</key>
<string>This software is not supported on your system.</string>
<key>ERROR_2</key>
<string>A newer version of this software is already installed. </string>
<key>SU_TITLE</key>
<string>YOURAPPNAMEHERE</string>
</dict>
</plist>
I put all this in a bash script and use a here document to replace text with shell variables. For example, $packageVersion is the version of my app, e.g. "2.0.0.0". The string YOURAPPNAMEHERE could also be replaced with a shell variable.
cat <<EOF >"Distribution.xml"
<?xml version="1.0" encoding="utf-8"?>
...other text...
EOF
You can learn a lot by examining the iTunes installer. Download the installer, mount it, drag the .pkg file out and expand it:
$ /usr/sbin/pkgutil --expand Install\ iTunes.pkg iTunesExpanded
Then you can see the code and poke around
Related
I'm trying to programmatically capture GPU frames using MTLCaptureManager in a command line application.
So far, the capture manager fails to support the MTLCaptureDestinationGPUTraceDocument destination.
I tried to create a very minimal repro case using XCode :
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
MTLCaptureManager* captureManager = [MTLCaptureManager sharedCaptureManager];
if (![captureManager supportsDestination:MTLCaptureDestinationGPUTraceDocument])
{
NSLog(#"********** captureManager does not support MTLCaptureDestinationGPUTraceDocument ************");
}
else
{
NSLog(#"captureManager support is fine");
}
}
return 0;
}
When run with XCode, it seems to be willing to work : the output is :
2020-09-02 16:25:59.712217+0200 testMetalCapture[20095:416447] Metal GPU Frame Capture Enabled
2020-09-02 16:25:59.712503+0200 testMetalCapture[20095:416447] Metal API Validation Enabled
2020-09-02 16:26:00.669092+0200 testMetalCapture[20095:416447] captureManager support is fine
Program ended with exit code: 0
But when I archive the build result, and run from a terminal, it fails :
2020-09-02 16:32:57.607 testMetalCapture[20126:419837] ********** captureManager does not support MTLCaptureDestinationGPUTraceDocument ************
Is there any runtime environment I could reproduce in terminal to get the MTLCaptureManager working ?
(Environment is XCode 11.6 + MacOS 10.15 Catalina)
From what I understood (I could not find any official documentation) :
MTLCaptureManager needs an authorization from the Info.plist: the MetalCaptureEnabled should set to YES.
The proper way is to bundle the command line application with such a plist
This is quite involved, see for example Building OSX App Bundle
I found by accident that MTLCaptureManager also works if there's an Info.plist in the same directory as the command line application.
This Info.plist can be almost empty, like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MetalCaptureEnabled</key>
<true/>
</dict>
</plist>
With this simple setup, I can run my test program (and my real one too)
% ./testMetalCapture
2020-10-02 15:53:08.507 testMetalCapture[28559:686864] Metal GPU Frame Capture Enabled
2020-10-02 15:53:08.523 testMetalCapture[28559:686864] captureManager support is fine
(I'm currently using MacOSX 10.15.6, it may break in the future)
The trick from #rotoglup was working for me, until it wasn't anymore: some buffers were full of zeros, and no image appeared in the 'screenshots' inside the metal debugger. I don't know if this was because of an update of the OS or of XCode or something else.
I still needed an Info.plist with this content, as #rotoglup suggested:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MetalCaptureEnabled</key>
<true/>
</dict>
</plist>
but I also needed to set the METAL_DEVICE_WRAPPER_TYPE env variable to 1 in the terminal that launches the command line app:
export METAL_DEVICE_WRAPPER_TYPE=1
With this, buffers are filled up correctly, and I get non-empty screenshots.
When building for iOS, Facebook's PostProcessBuild method, OnPostProcessBuild, tries to parse some data to do some things, like adding the Facebook libraries to the final XCode project.
The parser receives a wrong file format. In its Decode() method, it expects data that begins with:
public const string PBX_HEADER_TOKEN = "// !$*UTF8*$!\n";
like this:
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/ Begin PBXBuildFile section /
011C65182C1C4E78903D645B / libxml2.dylib / = {isa = PBXBuildFile; fileRef = 318C8AB7C5D04BBFA6BA701D / libxml2.dylib /; };
but instead, it receives a string with the project.pbxproj contents, in the correct xml format. like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>archiveVersion</key>
<string>1</string>
<key>classes</key>
<dict/>
<key>objectVersion</key>
<string>46</string>
<key>objects</key>
<dict>
Is anybody else experiencing this?
I found these questions to be related, but none of them answers the real issue.
FacebookSDK for Unity iOS Mach-O linker error - undefined symbols _iosLogin,
http://forum.unity3d.com/threads/mach-o-linker-error-with-facebook-sdk.239085/
Any ideas on how to solve it?
You can force FB to make its changes the project.pbxproj file later, when the file is back in the original PBX format:
By changing the line [PostProcessBuild(100)] to [PostProcessBuild(99999999)] in file FacebookPostprocess.cs.
I have the same problem. After I installed another plugin that modifies the project.pbxproj file the data coming in the PBXParser is in xml1 format. I found somewhere that it is easy to modify the json like format, but hard to save it in a format that Xcode can understand. The standard process is to save it in xml1 format. Xcode can understand the xml1 format, so this is not a problem.
So my workaround is as follow:
Run the build as usual.
After the build fails close Xcode (Xcode will write the project file in the right json format on close).
Copy the modified project.pbxproj file to another location.
Change the PBXParser to read the data from the modified file if in xml
format!
Run the build again.
This isn't very clean, but worked for me. Better option will be to convert the xml to json for the PBXParser...
I'm using py2app to bundle a Mac application and am trying to figure out how it works. Based on reading the Bundle Programming Guide it seems that CFBundleExecutable is a required key and that this is the key OSX uses to figure out which file in the MacOS subfolder to run. However, I stripped my Info.plist file to the following, and the app loads just fine:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PyMainFileNames</key>
<array>
<string>__boot__</string>
</array>
<key>PyRuntimeLocations</key>
<array>
<string>#executable_path/../Frameworks/Python.framework/Versions/2.7/Python</string>
</array>
</dict>
</plist>
How can this be so? Given that exact plist file, how can OSX load my application?
The CFBundleExecutable key is required in the sense that you really should have it, but CoreFoundation will do its best to deal with its absence. By looking at the source of CFBundle we can get an idea how it deals with this key:
static CFStringRef _CFBundleCopyExecutableName(CFBundleRef bundle, CFURLRef url, CFDictionaryRef infoDict) {
CFStringRef executableName = NULL;
// …
if (infoDict) {
// Figure out the name of the executable.
// First try for the new key in the plist.
executableName = (CFStringRef)CFDictionaryGetValue(infoDict, kCFBundleExecutableKey);
// Second try for the old key in the plist.
if (!executableName) executableName = (CFStringRef)CFDictionaryGetValue(infoDict, _kCFBundleOldExecutableKey);
if (executableName && CFGetTypeID(executableName) == CFStringGetTypeID() && CFStringGetLength(executableName) > 0) {
CFRetain(executableName);
} else {
executableName = NULL;
}
}
if (!executableName && url) {
// Third, take the name of the bundle itself (with path extension stripped)
So you can see that they look for the following in order:
The CFBundleExecutable key.
The NSExecutable key, a legacy name predating OS X public beta.
If neither is present, fall back to using the name of the bundle with the path extension removed.
Having determined the executable name, the manner in which the directory that it lives in is found is equally full of quirks. I'll leave discovering those as an exercise for interested parties.
Apple's document on submitting an app to the Mac App store contains this example use of the command productbuild, from in /Developer/usr/bin/.
productbuild \
--component build/Release/Sample.app /Applications \
--sign "3rd Party Mac Developer Installer: Name1 Name2" \
--product product_definition.plist Sample.pkg
When I run this command on my Sample app, I get the error:
productbuild: error: No product definition plist found at
"product_definition.plist".
What is this product_definition.plist, where should it come from, what should be inside it, and what tool should be used to create this plist?
From the Apple document you linked: "You should specify a single component, a signature, and (optionally) a product definition file."
Unless you have a specific requirement, you don't need a product definition file. If you need it, the man page of productbuild has a lot of information. It is just a plist dictionary, like this example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>gl-renderer</key>
<string>( 'GL_APPLE_float_pixels' IN extensions )</string>
</dict>
</plist>
I've verified that Xcode doesn't use a product definition file when you share an archived application as package. This is the actual command line:
/usr/bin/productbuild --component <path-to-xcarchive>/Cool.app
/Applications
<tmp-path>/package.pkg
--sign 3rd Party Mac Developer Installer
If you run man productbuild and look for the section PRODUCT DEFINITION PROPERTY LIST which starts with
PRODUCT DEFINITION PROPERTY LIST
When you use productbuild to synthesize a distribution (e.g. with the --component option), you can specify additional parameters and
requirements in a separate property list file, specified with the --product option. At the top level, this property list is a dictio-
nary, with the following keys:
Key Description
os Minimum allowable OS versions (array of strings)
arch Supported architectures (array of strings)
ram Minimum required RAM in gigabytes (real)
bundle Specific bundles that must exist on the system (array of dictionaries)
all-bundles Are all of the bundles specified required? (Boolean)
gl-renderer Required OpenGL capabilities (string)
cl-device Required OpenCL capabilities (string)
single-graphics-device Must OpenGL and OpenCL requirements be met by a single device? (Boolean)
home Should installation be allowed in user home directory? (Boolean)
Lots more information is given, which you should be able to generate with XCode or a text editor.
Within XCode just create a new plist and add the key/value pairs according to your requirements and the possible values listed in the man file.
Whenever I create a new .cpp/.h file in Xcode a comment is added to the top of the file. For example:
/*
* <file>.cpp
* <Name of project>
*
* Created by <My name> on <Date>.
* Copyright <Year and company>. All rights reserved.
*
*/
I want to change the default comment to be another license, like GPL/LGPL/ or something else. Is there somewhere I can change this behavior in Xcode?
With Xcode 9 there is a built-in option which you can find in the details below.
Create a property list file named IDETemplateMacros.plist
Add a FILEHEADER value to the Root and set its string value with your copyright text like Copyright © 2017 ...
Copy the file to one of the following locations
For a single project and user
<ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
For all team members in a single project
<ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
For all projects in a workspace for a single user
<WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
For all projects in a workspace for all team members
<WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist
For everything you work on, regardless of project
~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist
Create a new file - you should see the new copyright header
Sample IDETemplateMacros.plist for copy and paste:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
// Created by Your Name on 29.12.17.
// Copyright © 2017 Your Company. All rights reserved.
// </string>
</dict>
</plist>
First try changing your Name and Organization your contact card in Address Book.
If that doesn't work, open System Preferences > Users & Groups > Right click on your user (System Preferences must already be unlocked) > Advanced Options... > Change the name in the Full Name text box.
To change the organization name in Xcode click on the project file so it is selected (left sidebar of Xcode in the Project navigator) > In the File Inspector (right sidebar of Xcode) change the Organization text box.
This blog post has some good steps for modifying file templates in Xcode 4.3:
http://error-success.piku.org.uk/2012/04/27/how-to-make-xcode-4-3-2-templates/
The /Developer folder no longer exists, so you copy the templates from within the Xcode.app bundle located in /Applications:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/
And place your modified copy here, as before:
~/Library/Developer/Xcode/Templates/File\ Templates/
UPDATE: I decided to write a script that would extract the built in Xcode templates and replace the headers. Source and instructions can be found at the following url:
https://github.com/royclarkson/xcode-templates
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates
any update of your SDK will wipe changes here so keep your template backed up somewhere else
Don't edit anything in /Developer as Apple can overwrite this at any time.
The following works for Xcode 4, 5 and 6 except later source differs and is under /Applications
Instead copy the templates that you want to change from /Applications/Xcode<version>.app/Contents/Developer/Library/Xcode/Templates to ~/Library/Developer/Xcode/Templates/File Templates and then edit the files keeping the same directory structure but edit the directory name that is the template to not show up a a duplicate in Xcode.
e.g for a new category of C/C+ files in Xcode 5 copy /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/C and C++ to ~/Library/Developer/Xcode/Templates/File Templates/GPL C and C++
this process is copied from Red Glasses's blog
For Xcode 4 the source path is or for Xcode 4 /Developer/Library/Xcode/Templates/File Templates
– Press ⌘ 1 to display the File Navigator.
– Click on the name of your project at the top of the File Navigator.
– Press ⌘⌥⇧ ⏎ (that's Command Option Shift Return) to view the Version Editor.
– Make sure that the Comparison View is shown(View > Version Editor > Show Comparison View).
This lets you see the raw text of your project's project.pbxproj file.
– Press ⌘ f to search the project.pbxproj file, paste in ORGANIZATIONNAME and press Return.
This is where the name of the organization that follows the copyright text is defined.
Or open Xcode's plist at
~/Library/Preferences/com.apple.dt.Xcode.plist
And change the organizationName key's value.
Or select the project from the Navigator pane and display the File Inspector with ⌘⌥ 1.
Look at the Organization value under Project Document. Change the value there.
In Xcode 12.4
Using Xcode, create a plist file named IDETemplateMacros.
Save it to the Desktop initially while you configure it.
If you cannot see the file in the Project Navigator then from the Xcode menu, select View > Navigators > Project
Right click on the filename and select Open as > Source Code
The following is a template that works nicely for me so chances are it will for you too.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
//
// ___FILENAME___
// ___PACKAGENAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___
// Copyright © ___YEAR___ ___FULLUSERNAME___. All rights reserved.
//
</string>
</dict>
</plist>
Copy and paste the above overwriting the existing contents.
Save the file and close it.
In Finder navigate to the following folder:
~/Library/Developer/Xcode/UserdData/
Drag the file from your Desktop to this Folder and then test using Xcode to create a new project.
It's very simple:
Open up terminal
In one line, write the following:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions -dict ORGANIZATIONNAME "Blah, Inc"
You don't have to worry about changing directories beforehand or anything else. It works instantly.
Change the details in your Address Book - add a company name. It will pick it up from there.
Try modifying this file:
/Developer/Library/Xcode/File\ Templates/C\ and\ C++/Header\ File.pbfiletemplate/header.h
Works with Xcode 14
Say you want to modify (or get rid of) the XCode Header comment.
First open XCode, Use File > New File... (⌘N) and choose Property List from the file templates.
Name it file IDETemplateMacros.plist
On the navigator, select the file as right-click Open as source code. Xcode will show us the property file as text. Property files are really just XML files.
Copy paste the following content:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>Created for ___PROJECTNAME___ in ___YEAR___
// Using Swift ___DEFAULTTOOLCHAINSWIFTVERSION___</string>
</dict>
</plist>
On the root dict we have added an entry with key FILEHEADER and a two-lines string as a value:
Created for ___PROJECTNAME___ in ___YEAR___
// Using Swift ___DEFAULTTOOLCHAINSWIFTVERSION___
Save the file IDETemplateMacros.plist on the folder:
~/Library/Developer/Xcode/UserData/
That's it, now when creating a new project called MyProject, the header will be:
//Created for MyProject in 2022
// Using Swift 5.0
Note1. There is a list of macros on https://help.apple.com/xcode/mac/9.0/index.html?localePath=en.lproj#/dev7fe737ce0
Note 2. As an example you can write:
Created ___DATE___
// ___COPYRIGHT___
Note that there is a leading space but you do not include the // for the comment on the first line.
Note 3. For a more list of options see:
https://useyourloaf.com/blog/changing-xcode-header-comment/
In Xcode 4.2, they're here:
/Developer/Library/Xcode/Templates/File Templates
I just changed the template of a SwiftUI file, you have to open Xcode's Contents and look for the template files you want to change.
To change the SwiftUI template the path is this:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/MultiPlatform/User\ Interface/SwiftUI\ View.xctemplate
You nedd open with sudo
For AppCode users:
Go to preferences (CMD + ,)
Editor-File and Code Templates
Change Scheme to Project
Modify Files and/or Includes as you need.
add to git .idea/fileTemplates if needed
You can override the text macros globally, or for an individual workspace or project. You can also decide to keep the macros for a single user or share it with all users.
The full list of locations that Xcode searches, in order of priority:
Project - single user
<ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/
Project - shared by all users
<ProjectName>.xcodeproj/xcshareddata/
Workspace - single user
<WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/
Workspace - shared by all users
<WorkspaceName>.xcworkspace/xcshareddata/
Globally for Xcode
~/Library/Developer/Xcode/UserData/
I don't remember what was the default template but you can make a template in any way you like using textMacros:
// ___FILENAME___
// ___PACKAGENAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// ___COPYRIGHT___
//
There are some other textMacros if you like more customization, but these are enough for making something like the default one.
You can create the file yourself if no files found at the path