@@ -2,6 +2,7 @@ import * as path from "path";
22import * as shell from "shelljs" ;
33import * as semver from "semver" ;
44import * as constants from "../constants" ;
5+ import { Configurations } from "../common/constants" ;
56import * as helpers from "../common/helpers" ;
67import { attachAwaitDetach } from "../common/helpers" ;
78import * as projectServiceBaseLib from "./platform-project-service-base" ;
@@ -21,6 +22,12 @@ interface INativeSourceCodeGroup {
2122 files : string [ ] ;
2223}
2324
25+ const DevicePlatformSdkName = "iphoneos" ;
26+ const SimulatorPlatformSdkName = "iphonesimulator" ;
27+
28+ const getPlatformSdkName = ( forDevice : boolean ) : string => forDevice ? DevicePlatformSdkName : SimulatorPlatformSdkName ;
29+ const getConfigurationName = ( release : boolean ) : string => release ? Configurations . Release : Configurations . Debug ;
30+
2431export class IOSProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
2532 private static XCODEBUILD_MIN_VERSION = "6.0" ;
2633 private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__" ;
@@ -67,8 +74,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
6774 appDestinationDirectoryPath : path . join ( projectRoot , projectData . projectName ) ,
6875 platformProjectService : this ,
6976 projectRoot : projectRoot ,
70- deviceBuildOutputPath : path . join ( projectRoot , constants . BUILD_DIR , "device" ) ,
71- emulatorBuildOutputPath : path . join ( projectRoot , constants . BUILD_DIR , "emulator" ) ,
77+ getBuildOutputPath : ( options : IBuildOutputOptions ) : string => {
78+ const config = getConfigurationName ( ! options || options . release ) ;
79+ return path . join ( projectRoot , constants . BUILD_DIR , `${ config } -${ getPlatformSdkName ( ! options || options . buildForDevice ) } ` ) ;
80+ } ,
7281 getValidBuildOutputData : ( buildOptions : IBuildOutputOptions ) : IValidBuildOutputData => {
7382 const forDevice = ! buildOptions || ! ! buildOptions . buildForDevice ;
7483 if ( forDevice ) {
@@ -206,10 +215,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
206215 * Returns the path to the .xcarchive.
207216 */
208217 public async archive ( projectData : IProjectData , buildConfig ?: IBuildConfig , options ?: { archivePath ?: string , additionalArgs ?: string [ ] } ) : Promise < string > {
218+ const platformData = this . getPlatformData ( projectData ) ;
209219 const projectRoot = this . getPlatformData ( projectData ) . projectRoot ;
210- const archivePath = options && options . archivePath ? path . resolve ( options . archivePath ) : path . join ( projectRoot , "/build/archive/" , projectData . projectName + ".xcarchive" ) ;
220+ const archivePath = options && options . archivePath ? path . resolve ( options . archivePath ) : path . join ( platformData . getBuildOutputPath ( buildConfig ) , projectData . projectName + ".xcarchive" ) ;
211221 let args = [ "archive" , "-archivePath" , archivePath , "-configuration" ,
212- ( ! buildConfig || buildConfig . release ) ? "Release" : "Debug" ]
222+ getConfigurationName ( ! buildConfig || buildConfig . release ) ]
213223 . concat ( this . xcbuildProjectArgs ( projectRoot , projectData , "scheme" ) ) ;
214224
215225 if ( options && options . additionalArgs ) {
@@ -278,12 +288,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
278288 /**
279289 * Exports .xcarchive for a development device.
280290 */
281- private async exportDevelopmentArchive ( projectData : IProjectData , buildConfig : IBuildConfig , options : { archivePath : string , exportDir ?: string , teamID ?: string , provision ?: string } ) : Promise < string > {
291+ private async exportDevelopmentArchive ( projectData : IProjectData , buildConfig : IBuildConfig , options : { archivePath : string , provision ?: string } ) : Promise < string > {
282292 const platformData = this . getPlatformData ( projectData ) ;
283293 const projectRoot = platformData . projectRoot ;
284294 const archivePath = options . archivePath ;
285- const buildOutputPath = path . join ( projectRoot , "build" , "device" ) ;
286- const exportOptionsMethod = await this . getExportOptionsMethod ( projectData ) ;
295+ const exportOptionsMethod = await this . getExportOptionsMethod ( projectData , archivePath ) ;
287296 let plistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
288297<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
289298<plist version="1.0">
@@ -311,7 +320,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
311320 this . $fs . writeFile ( exportOptionsPlist , plistTemplate ) ;
312321
313322 // The xcodebuild exportPath expects directory and writes the <project-name>.ipa at that directory.
314- const exportPath = path . resolve ( options . exportDir || buildOutputPath ) ;
323+ const exportPath = path . resolve ( path . dirname ( archivePath ) ) ;
315324 const exportFile = path . join ( exportPath , projectData . projectName + ".ipa" ) ;
316325
317326 await this . xcodebuild (
@@ -407,8 +416,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
407416 args = args . concat ( ( buildConfig && buildConfig . architectures ) || this . getBuildArchitectures ( projectData , buildConfig , [ "armv7" , "arm64" ] ) ) ;
408417
409418 args = args . concat ( [
410- "-sdk" , "iphoneos" ,
411- "CONFIGURATION_BUILD_DIR =" + path . join ( projectRoot , "build" , "device" )
419+ "-sdk" , DevicePlatformSdkName ,
420+ "BUILD_DIR =" + path . join ( projectRoot , constants . BUILD_DIR )
412421 ] ) ;
413422
414423 const xcodeBuildVersion = await this . getXcodeVersion ( ) ;
@@ -574,10 +583,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
574583 . concat ( architectures )
575584 . concat ( [
576585 "build" ,
577- "-configuration" , buildConfig . release ? "Release" : "Debug" ,
578- "-sdk" , "iphonesimulator" ,
586+ "-configuration" , getConfigurationName ( buildConfig . release ) ,
587+ "-sdk" , SimulatorPlatformSdkName ,
579588 "ONLY_ACTIVE_ARCH=NO" ,
580- "CONFIGURATION_BUILD_DIR =" + path . join ( projectRoot , "build" , "emulator" ) ,
589+ "BUILD_DIR =" + path . join ( projectRoot , constants . BUILD_DIR ) ,
581590 "CODE_SIGN_IDENTITY=" ,
582591 ] )
583592 . concat ( this . xcbuildProjectArgs ( projectRoot , projectData ) ) ;
@@ -1390,8 +1399,8 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
13901399 }
13911400 }
13921401
1393- private getExportOptionsMethod ( projectData : IProjectData ) : string {
1394- const embeddedMobileProvisionPath = path . join ( this . getPlatformData ( projectData ) . projectRoot , "build" , "archive" , ` ${ projectData . projectName } .xcarchive` , 'Products' , 'Applications' , `${ projectData . projectName } .app` , "embedded.mobileprovision" ) ;
1402+ private getExportOptionsMethod ( projectData : IProjectData , archivePath : string ) : string {
1403+ const embeddedMobileProvisionPath = path . join ( archivePath , 'Products' , 'Applications' , `${ projectData . projectName } .app` , "embedded.mobileprovision" ) ;
13951404 const provision = mobileprovision . provision . readFromFile ( embeddedMobileProvisionPath ) ;
13961405
13971406 return {
0 commit comments