diff --git a/Makefile b/Makefile index 4954ccbf..71d5a86a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,105 @@ +ifeq ($(shell uname -s),Darwin) + +IS_MAC = 1 + +ifneq ($(VERBOSE),1) +ifeq ($(shell type -p xcbeautify &>/dev/null && echo 1),1) +XC_FORMAT = | xcbeautify +endif +endif + +endif + +ifeq ($(RELEASE),1) +INTERNAL_SWIFTFLAGS = -c release +INTERNAL_XCFLAGS = -configuration Release +else +INTERNAL_SWIFTFLAGS = -c debug +INTERNAL_XCFLAGS = -configuration Debug +endif + +ALL_SWIFTFLAGS = $(INTERNAL_SWIFTFLAGS) $(SWIFTFLAGS) +ALL_XCFLAGS = $(INTERNAL_XCFLAGS) $(XCFLAGS) + +TEAM_CONFIG = macOS/Support/Private-Team.xcconfig + +.PHONY: all +# dev build for the current platform +all: +ifeq ($(IS_MAC),1) + @+$(MAKE) mac +else + @+$(MAKE) linux +endif + +.PHONY: linux +# dev build for Linux +linux: + swift build --product xtool $(ALL_SWIFTFLAGS) + +.PHONY: linux-dist +# dist build for Linux +linux-dist: + docker compose run --build --rm xtool Linux/build.sh + +.PHONY: mac +# dev build for macOS +mac: project + @rm -rf macOS/Build/XcodeInstall + @set -o pipefail && cd macOS && \ + xcodebuild build install \ + -skipMacroValidation -skipPackagePluginValidation \ + -scheme XToolMac -destination generic/platform=macOS \ + DSTROOT="$$PWD"/Build/XcodeInstall INSTALL_PATH=/ \ + $(ALL_XCFLAGS) $(XC_FORMAT) + @ln -fs XcodeInstall/xtool.app/Contents/Resources/bin/xtool macOS/Build/xtool + @echo "Output: ./macOS/Build/xtool" + +.PHONY: mac-dist +# dist build for macOS +# requires a few secrets in the env (see .github/workflows/release.yml) +mac-dist: + @echo "bundle exec fastlane package" + @cd macOS && bundle exec fastlane package + +.PHONY: reload +# update Xcode project and restart Xcode +reload: + killall Xcode || : + @+$(MAKE) project + xed macOS/XToolMac.xcodeproj + +.PHONY: project +# update Xcode project +project: $(TEAM_CONFIG) + @echo "xcodegen" + @cd macOS && xcodegen + +.PHONY: team +# update development team +team: + @+$(MAKE) -B $(TEAM_CONFIG) + +# update development team if needed. +# +# will prompt interactively if there are multiple valid options. +# set DEVELOPMENT_TEAM=... to force a specific value. +$(TEAM_CONFIG): +ifeq ($(DEVELOPMENT_TEAM),) + @mkdir -p macOS/Support + @team=$$(./scripts/select-identity.sh); \ + echo "echo \"DEVELOPMENT_TEAM = $$team\" > $@"; \ + echo "DEVELOPMENT_TEAM = $$team" > $@ +else + @mkdir -p macOS/Support + echo "DEVELOPMENT_TEAM = $(DEVELOPMENT_TEAM)" > $@ +.PHONY: $(TEAM_CONFIG) +endif + SPEC_URL = https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip -.PHONY: api update-api - +.PHONY: api +# Regenerate the OpenAPI client code api: openapi/openapi.json swift run swift-openapi-generator generate \ openapi/openapi.json \ @@ -11,6 +109,8 @@ api: openapi/openapi.json sed -i '' -e 's/[[:<:]]Client[[:>:]]/DeveloperAPIClient/g' $$file; \ done +.PHONY: update-api +# Update OpenAPI spec and regenerate the client code update-api: @+$(MAKE) -B api diff --git a/macOS/Support/Base.xcconfig b/macOS/Support/Base.xcconfig index a23580ff..5b122f21 100644 --- a/macOS/Support/Base.xcconfig +++ b/macOS/Support/Base.xcconfig @@ -6,4 +6,5 @@ ENABLE_HARDENED_RUNTIME = YES PRODUCT_NAME = xtool PRODUCT_MODULE_NAME = XToolMac +#include? "Private-Team.xcconfig" #include? "Private.xcconfig" diff --git a/scripts/select-identity.sh b/scripts/select-identity.sh new file mode 100755 index 00000000..7382ab15 --- /dev/null +++ b/scripts/select-identity.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +IFS=$'\n' names=($(security find-identity -vp codesigning | grep -E '(?:iPhone Developer|Apple Development):' | cut -d'"' -f2 | uniq)) +if [[ "${#names[@]}" -eq 1 ]]; then + identity="${names[0]}" +else + echo "Select identity" >&2 + for i in "${!names[@]}"; do + printf "%s. %s\n" $((i + 1)) "${names[$i]}" >&2 + done + # ask for choice until the user supplies a valid answer + function select_identity { + read -p "Choice (enter number): " identity_idx >&2 + if [[ "$identity_idx" -lt 1 || "$identity_idx" -gt "${#names[@]}" ]]; then + select_identity + else + identity="${names[$((identity_idx - 1))]}" + fi + } + select_identity +fi + +# we can't simply extract the portion in brackets because some times the Organizational Unit is different from that +# so extract that info from the certificate +team=$(security find-certificate -pc "$identity" | openssl x509 -noout -subject | grep -o 'OU=[A-Z0-9]*' | cut -d= -f2) + +echo -n "$team"