Skip to content

Commit

Permalink
install-from-sources.sh: install as AeroSpace-Dev.app
Browse files Browse the repository at this point in the history
If we didn't separate those builds, macOS would re-request accessibility permission when users switch between "-Dev" and GitHub builds.
"-Dev" builds and GitHub builds differ only in the application name and App Bundle ID.

Related: #530
  • Loading branch information
nikitabobko committed Sep 23, 2024
1 parent add8099 commit a4e00e5
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 65 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ jobs:
# "-" means "Sign to run locally". There is no aerospace-codesign-certificate in GH Actions
# build-release.sh takes too much time to complete in macos-13.
# Running build-release.sh only in macos-14, cuts the build time twice in GH Actions.
- name: ./build-release.sh on macos-14
- name: ./build-release.sh --configuration Dev on macos-14
run: |
sw_vers -productVersion
if sw_vers -productVersion | grep -q "^14"; then
./build-release.sh --codesign-identity -
./install-from-sources.sh --dont-rebuild
./build-release.sh --configuration Dev --codesign-identity -
./install-dev-from-sources.sh --dont-rebuild
fi
- name: ./build-release.sh --configuration Release on macos-14
run: |
sw_vers -productVersion
if sw_vers -productVersion | grep -q "^14"; then
./build-release.sh --configuration Release --codesign-identity -
fi
81 changes: 80 additions & 1 deletion AeroSpace.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 49 additions & 34 deletions build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ source ./script/setup.sh

build_version="0.0.0-SNAPSHOT"
codesign_identity="aerospace-codesign-certificate"
configuration="Release"
while [[ $# -gt 0 ]]; do
case $1 in
--build-version) build_version="$2"; shift 2 ;;
--codesign-identity) codesign_identity="$2"; shift 2 ;;
*) echo "Unknown option $1"; exit 1 ;;
--build-version) build_version="$2"; shift 2;;
--codesign-identity) codesign_identity="$2"; shift 2;;
--configuration) configuration="$2"; shift 2;;
*) echo "Unknown option $1" > /dev/stderr; exit 1 ;;
esac
done

case $configuration in
Release)
aerospace_dot_app='AeroSpace.app'
aerospace_dot_app_bin='AeroSpace'
cask_name='aerospace'
;;
Dev)
aerospace_dot_app='AeroSpace-Dev.app'
aerospace_dot_app_bin='AeroSpace-Dev'
cask_name='aerospace-dev'
;;
*) echo "Unknown configuration: $configuration" > /dev/stderr; exit 1;;
esac

generate-git-hash() {
cat > Sources/Common/gitHashGenerated.swift <<EOF
public let gitHash = "$(git rev-parse HEAD)"
Expand All @@ -35,13 +51,13 @@ swift build -c release --arch arm64 --arch x86_64 --product aerospace # CLI
xcodebuild clean build \
-scheme AeroSpace \
-destination "generic/platform=macOS" \
-configuration Release \
-configuration "$configuration" \
-derivedDataPath .xcode-build

git checkout .

rm -rf .release && mkdir .release
cp -r .xcode-build/Build/Products/Release/AeroSpace.app .release
cp -r ".xcode-build/Build/Products/$configuration/$aerospace_dot_app" .release
cp -r .build/apple/Products/Release/aerospace .release

################
Expand All @@ -55,69 +71,68 @@ codesign -s "$codesign_identity" .release/aerospace
################

expected_layout=$(cat <<EOF
.release/AeroSpace.app
.release/AeroSpace.app/Contents
.release/AeroSpace.app/Contents/_CodeSignature
.release/AeroSpace.app/Contents/_CodeSignature/CodeResources
.release/AeroSpace.app/Contents/MacOS
.release/AeroSpace.app/Contents/MacOS/AeroSpace
.release/AeroSpace.app/Contents/Resources
.release/AeroSpace.app/Contents/Resources/default-config.toml
.release/AeroSpace.app/Contents/Resources/AppIcon.icns
.release/AeroSpace.app/Contents/Resources/Assets.car
.release/AeroSpace.app/Contents/Info.plist
.release/AeroSpace.app/Contents/PkgInfo
.release/$aerospace_dot_app
.release/$aerospace_dot_app/Contents
.release/$aerospace_dot_app/Contents/_CodeSignature
.release/$aerospace_dot_app/Contents/_CodeSignature/CodeResources
.release/$aerospace_dot_app/Contents/MacOS
.release/$aerospace_dot_app/Contents/MacOS/$aerospace_dot_app_bin
.release/$aerospace_dot_app/Contents/Resources
.release/$aerospace_dot_app/Contents/Resources/default-config.toml
.release/$aerospace_dot_app/Contents/Resources/AppIcon.icns
.release/$aerospace_dot_app/Contents/Resources/Assets.car
.release/$aerospace_dot_app/Contents/Info.plist
.release/$aerospace_dot_app/Contents/PkgInfo
EOF
)

if [ "$expected_layout" != "$(find .release/AeroSpace.app)" ]; then
if [ "$expected_layout" != "$(find .release/$aerospace_dot_app)" ]; then
echo "!!! Expect/Actual layout don't match !!!"
find .release/AeroSpace.app
find .release/$aerospace_dot_app
exit 1
fi

check-universal-binary() {
if ! file $1 | grep --fixed-string -q "Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64"; then
if ! file "$1" | grep --fixed-string -q "Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64"; then
echo "$1 is not a universal binary"
exit 1
fi
}

check-contains-hash() {
hash=$(git rev-parse HEAD)
if ! strings $1 | grep --fixed-string $hash > /dev/null; then
if ! strings "$1" | grep --fixed-string "$hash" > /dev/null; then
echo "$1 doesn't contain $hash"
exit 1
fi
}

check-universal-binary .release/AeroSpace.app/Contents/MacOS/AeroSpace
check-universal-binary .release/$aerospace_dot_app/Contents/MacOS/$aerospace_dot_app_bin
check-universal-binary .release/aerospace

check-contains-hash .release/AeroSpace.app/Contents/MacOS/AeroSpace
check-contains-hash .release/$aerospace_dot_app/Contents/MacOS/$aerospace_dot_app_bin
check-contains-hash .release/aerospace

codesign -v .release/AeroSpace.app
codesign -v .release/$aerospace_dot_app
codesign -v .release/aerospace

############
### PACK ###
############

mkdir -p .release/AeroSpace-v$build_version/manpage && cp .man/*.1 .release/AeroSpace-v$build_version/manpage
cp -r ./legal .release/AeroSpace-v$build_version/legal
cp -r .shell-completion .release/AeroSpace-v$build_version/shell-completion
mkdir -p ".release/AeroSpace-v$build_version/manpage" && cp .man/*.1 ".release/AeroSpace-v$build_version/manpage"
cp -r ./legal ".release/AeroSpace-v$build_version/legal"
cp -r .shell-completion ".release/AeroSpace-v$build_version/shell-completion"
cd .release
mkdir -p AeroSpace-v$build_version/bin && cp -r aerospace AeroSpace-v$build_version/bin
cp -r AeroSpace.app AeroSpace-v$build_version
zip -r AeroSpace-v$build_version.zip AeroSpace-v$build_version
mkdir -p "AeroSpace-v$build_version/bin" && cp -r aerospace "AeroSpace-v$build_version/bin"
cp -r $aerospace_dot_app "AeroSpace-v$build_version"
zip -r "AeroSpace-v$build_version.zip" "AeroSpace-v$build_version"
cd -

#################
### Brew Cask ###
#################
./script/build-brew-cask.sh \
--zip-uri .release/AeroSpace-v$build_version.zip \
--cask-name aerospace-dev \
--build-version $build_version \
--conflicts-with-casks aerospace
--cask-name "$cask_name" \
--zip-uri ".release/AeroSpace-v$build_version.zip" \
--build-version "$build_version"
16 changes: 13 additions & 3 deletions dev-docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Feel free to report GitHub issues if something doesn't work for you

If you struggle to build AeroSpace locally, you can also refer to [builds in GitHub Actions](https://github.com/nikitabobko/AeroSpace/actions?query=branch%3Amain)

## Definitions

**SPM.** Swift package manager and Swift build tool. In other words, `swift` CLI tool

## 1. Install dependencies

1. Install Xcode from App Store https://apps.apple.com/us/app/xcode/id497799835
Expand Down Expand Up @@ -36,7 +40,7 @@ If you only plan to build the debug version of AeroSpace, you can run it from th
## 3. Entry point scripts

**Debug build**
- `build-debug.sh` - Build debug build to `.debug` dir.
- `build-debug.sh` - Build debug build to `.debug` dir by using SPM. (Xcode is not involved)
- `run-tests.sh` - Run tests.
- `run-debug.sh` - Run AeroSpace.app debug build.
- `run-cli.sh` - Run `aerospace` in CLI. Arguments are forwarded to `aerospace` binary.
Expand All @@ -50,8 +54,14 @@ If you only plan to build the debug version of AeroSpace, you can run it from th
> Debug build uses `~/.aerospace-debug.toml` instead of `~/.aerospace.toml`
**Release build**
- `build-release.sh` - Build release build to `.release` dir.
- `install-from-sources.sh` - Build from sources and install release build to `aerospace-dev` brew cask
- `build-release.sh` - Build release build to `.release` dir by using Xcode.
- `install-dev-from-sources.sh` - Build `AeroSpace-Dev.app` release build from sources and install it as `aerospace-dev` brew cask.
Suffix "-Dev" is used to distinguish self-build **release** builds from **release** builds published to GitHub.
Builds published to GitHub are signed by Nikita Bobko's private certificate.
"-Dev" builds are signed by your local `aerospace-codesign-certificate`.
If we didn't separate those builds, macOS would re-request accessibility permission when users switch between "-Dev" and GitHub builds.
"-Dev" builds and GitHub builds differ only in the application name and App Bundle ID.
If you want to build the release without "-Dev" suffix, you can use `./build-release.sh --configuration Release`, but be aware of the mentioned problem.

## IDE

Expand Down
4 changes: 1 addition & 3 deletions install-from-sources.sh → install-dev-from-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ while [[ $# -gt 0 ]]; do
done

if test $rebuild == 1; then
./build-release.sh
./build-release.sh --configuration Dev
fi

brew list aerospace-dev > /dev/null 2>&1 && brew uninstall aerospace-dev
brew list aerospace > /dev/null 2>&1 && brew uninstall aerospace
rm -rf /Applications/AeroSpace.app
rm -rf ~/Applications/AeroSpace.app

# Override HOMEBREW_CACHE. Otherwise, homebrew refuses to "redownload" the snapshot file
# Maybe there is a better way, I don't know
Expand Down
16 changes: 13 additions & 3 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ packages:
AeroSpacePackage:
path: .

configs:
Debug: debug
Release: release
Dev: release

targets:
AeroSpace:
type: application
Expand All @@ -31,12 +36,17 @@ targets:
INFOPLIST_KEY_LSUIElement: YES
CODE_SIGN_IDENTITY: ${XCODEGEN_AEROSPACE_CODE_SIGN_IDENTITY}
configs:
debug:
Debug:
PRODUCT_NAME: AeroSpace-Debug
PRODUCT_BUNDLE_IDENTIFIER: bobko.debug.aerospace
release:
PRODUCT_BUNDLE_IDENTIFIER: bobko.aerospace.debug
Release:
PRODUCT_NAME: AeroSpace
PRODUCT_BUNDLE_IDENTIFIER: bobko.aerospace
# Dev builds have different identifier because they are signed by user's certificate.
# Release builds are signed by Nikita Bobko's certificate
Dev:
PRODUCT_NAME: AeroSpace-Dev
PRODUCT_BUNDLE_IDENTIFIER: bobko.aerospace.dev
entitlements:
path: resources/AeroSpace.entitlements
properties:
Expand Down
Loading

0 comments on commit a4e00e5

Please sign in to comment.