Skip to content

Commit

Permalink
Merge pull request #227 from mroswald/feat/support-iosprojectpath-param
Browse files Browse the repository at this point in the history
Support (ios)-project-path param
  • Loading branch information
digeff committed Apr 26, 2016
2 parents 66816a3 + 3806430 commit 7091dc1
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 19 deletions.
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -121,6 +121,11 @@
"type": "string",
"description": "The location of the generated JavaScript code (the bundle file). Normally this should be \"${workspaceRoot}/.vscode/.react\"",
"default": null
},
"iosRelativeProjectPath": {
"type": "string",
"description": "Relative path to the ios/ folder, if it is not located on the project root.",
"default": "ios"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/ios/plistBuddy.ts
Expand Up @@ -25,7 +25,7 @@ export class PlistBuddy {
public getBundleId(projectRoot: string, simulator: boolean = true): Q.Promise<string> {
return this.xcodeproj.findXcodeprojFile(projectRoot).then((projectFile: string) => {
const appName = path.basename(projectFile, path.extname(projectFile));
const infoPlistPath = path.join(projectRoot, "ios", "build", "Build", "Products",
const infoPlistPath = path.join(projectRoot, "build", "Build", "Products",
simulator ? "Debug-iphonesimulator" : "Debug-iphoneos",
`${appName}.app`, "Info.plist");

Expand Down
3 changes: 1 addition & 2 deletions src/common/ios/xcodeproj.ts
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as path from "path";
import * as Q from "q";

import {ErrorHelper} from "../../common/error/errorHelper";
Expand All @@ -21,7 +20,7 @@ export class Xcodeproj {

public findXcodeprojFile(projectRoot: string): Q.Promise<string> {
return this.nodeFileSystem
.findFilesByExtension(path.join(projectRoot, "ios"), "xcodeproj")
.findFilesByExtension(projectRoot, "xcodeproj")
.then((projectFiles: string[]) => {
if (projectFiles.length > 1) {
TelemetryHelper.sendSimpleEvent("multipleXcodeprojFound");
Expand Down
1 change: 1 addition & 0 deletions src/common/launchArgs.ts
Expand Up @@ -6,6 +6,7 @@
*/
export interface IRunOptions extends ILaunchArgs {
projectRoot: string;
iosRelativeProjectPath?: string;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/debugger/ios/compiler.ts
Expand Up @@ -27,10 +27,10 @@ export class Compiler {
return new Xcodeproj().findXcodeprojFile(this.projectRoot).then((projectFile: string) => {
const projectName = path.basename(projectFile, path.extname(projectFile));
return [
"-project", path.join(this.projectRoot, "ios", projectFile),
"-project", path.join(this.projectRoot, projectFile),
"-scheme", projectName,
"-destination", "generic/platform=iOS", // Build for a generic iOS device
"-derivedDataPath", path.join(this.projectRoot, "ios", "build"),
"-derivedDataPath", path.join(this.projectRoot, "build"),
];
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/ios/deviceDeployer.ts
Expand Up @@ -19,7 +19,7 @@ export class DeviceDeployer {
public deploy(): Q.Promise<void> {
return new Xcodeproj().findXcodeprojFile(this.projectRoot).then((projectFile: string) => {
const projectName = path.basename(projectFile, path.extname(projectFile));
const pathToCompiledApp = path.join(this.projectRoot, "ios", "build",
const pathToCompiledApp = path.join(this.projectRoot, "build",
"Build", "Products", "Debug-iphoneos", `${projectName}.app`);
return new CommandExecutor(this.projectRoot)
.spawn("ideviceinstaller", ["-i", pathToCompiledApp]).catch((err) => {
Expand Down
20 changes: 13 additions & 7 deletions src/debugger/ios/iOSPlatform.ts
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as Q from "q";
import * as path from "path";

import {Log} from "../../common/log/log";
import {ChildProcess} from "../../common/node/childProcess";
Expand All @@ -16,6 +17,8 @@ import {IOSDebugModeManager} from "../../common/ios/iOSDebugModeManager";
import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier";

export class IOSPlatform implements IAppPlatform {
public static DEFAULT_IOS_PROJECT_RELATIVE_PATH = "ios";

private static deviceString = "device";
private static simulatorString = "simulator";

Expand All @@ -24,6 +27,7 @@ export class IOSPlatform implements IAppPlatform {
private projectPath: string;
private simulatorTarget: string;
private isSimulator: boolean;
private iosProjectPath: string;

// We should add the common iOS build/run erros we find to this list
private static RUN_IOS_FAILURE_PATTERNS: PatternToFailure = {
Expand All @@ -37,6 +41,7 @@ export class IOSPlatform implements IAppPlatform {
this.projectPath = this.runOptions.projectRoot;
this.simulatorTarget = this.runOptions.target || IOSPlatform.simulatorString;
this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
this.iosProjectPath = path.join(this.projectPath, this.runOptions.iosRelativeProjectPath);
}

public runApp(): Q.Promise<void> {
Expand All @@ -45,10 +50,11 @@ export class IOSPlatform implements IAppPlatform {
// React native supports running on the iOS simulator from the command line
let runArguments: string[] = [];
if (this.simulatorTarget.toLowerCase() !== IOSPlatform.simulatorString) {
runArguments.push("--simulator");
runArguments.push(this.simulatorTarget);
runArguments.push("--simulator", this.simulatorTarget);
}

runArguments.push("--project-path", this.runOptions.iosRelativeProjectPath);

const runIosSpawn = new CommandExecutor(this.projectPath).spawnReactCommand("run-ios", runArguments);
return new OutputVerifier(
() =>
Expand All @@ -57,10 +63,10 @@ export class IOSPlatform implements IAppPlatform {
Q(IOSPlatform.RUN_IOS_FAILURE_PATTERNS)).process(runIosSpawn);
}

return new Compiler(this.projectPath).compile().then(() => {
return new DeviceDeployer(this.projectPath).deploy();
return new Compiler(this.iosProjectPath).compile().then(() => {
return new DeviceDeployer(this.iosProjectPath).deploy();
}).then(() => {
return new DeviceRunner(this.projectPath).run();
return new DeviceRunner(this.iosProjectPath).run();
});
}

Expand All @@ -72,7 +78,7 @@ export class IOSPlatform implements IAppPlatform {
return Q.resolve<void>(void 0);
}

const iosDebugModeManager = new IOSDebugModeManager(this.projectPath);
const iosDebugModeManager = new IOSDebugModeManager(this.iosProjectPath);

// Wait until the configuration file exists, and check to see if debugging is enabled
return Q.all([
Expand Down Expand Up @@ -112,6 +118,6 @@ export class IOSPlatform implements IAppPlatform {
}

private getBundleId(): Q.Promise<string> {
return this.plistBuddy.getBundleId(this.projectPath);
return this.plistBuddy.getBundleId(this.iosProjectPath);
}
}
7 changes: 4 additions & 3 deletions src/debugger/launcher.ts
Expand Up @@ -86,15 +86,16 @@ export class Launcher {
* Parses the launch arguments set in the launch configuration.
*/
private parseRunOptions(): Q.Promise<IRunOptions> {
// We expect our debugAdapter to pass in arguments as [platform, debugAdapterPort, target?, logCatArguments?];
// We expect our debugAdapter to pass in arguments as [platform, debugAdapterPort, iosRelativeProjectPath, target?, logCatArguments?];
return this.remoteExtension.getPackagerPort().then(packagerPort => {
return {
projectRoot: this.projectRootPath,
platform: process.argv[2].toLowerCase(),
debugAdapterPort: parseInt(process.argv[3], 10) || 9090,
target: process.argv[4],
target: process.argv[5],
packagerPort: packagerPort,
logCatArguments: process.argv[5],
iosRelativeProjectPath: process.argv[4],
logCatArguments: process.argv[6],
};
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/debugger/nodeDebugWrapper.ts
Expand Up @@ -11,6 +11,7 @@ import {RemoteExtension} from "../common/remoteExtension";
import {EntryPointHandler, ProcessType} from "../common/entryPointHandler";
import {ErrorHelper} from "../common/error/errorHelper";
import {InternalErrorCode} from "../common/error/internalErrorCode";
import {IOSPlatform} from "./ios/iOSPlatform";
import {ExtensionTelemetryReporter, NullTelemetryReporter, ReassignableTelemetryReporter} from "../common/telemetryReporters";

// These typings do not reflect the typings as intended to be used
Expand Down Expand Up @@ -49,6 +50,7 @@ interface ILaunchArgs {
platform: string;
target?: string;
internalDebuggerPort?: any;
iosRelativeProjectPath?: string;
args: string[];
logCatArguments: any;
program: string;
Expand Down Expand Up @@ -158,6 +160,7 @@ new EntryPointHandler(ProcessType.Debugger).runApp(appName, () => version,
args.args = [
args.platform,
debugServerListeningPort.toString(),
!isNullOrUndefined(args.iosRelativeProjectPath) ? args.iosRelativeProjectPath : IOSPlatform.DEFAULT_IOS_PROJECT_RELATIVE_PATH,
args.target || "simulator",
];

Expand Down
4 changes: 2 additions & 2 deletions src/debugger/scriptImporter.ts
Expand Up @@ -71,7 +71,7 @@ export class ScriptImporter {
* Writes the script file to the project temporary location.
*/
private writeAppScript(scriptBody: string, scriptUrl: url.Url): Q.Promise<String> {
let scriptFilePath = path.join(this.sourcesStoragePath, scriptUrl.pathname); // scriptFilePath = "$TMPDIR/index.ios.bundle"
let scriptFilePath = path.join(this.sourcesStoragePath, path.basename(scriptUrl.pathname)); // scriptFilePath = "$TMPDIR/index.ios.bundle"
return new FileSystem().writeFile(scriptFilePath, scriptBody)
.then(() => scriptFilePath);
}
Expand All @@ -82,7 +82,7 @@ export class ScriptImporter {
private writeAppSourceMap(sourceMapUrl: url.Url, scriptUrl: url.Url): Q.Promise<void> {
return new Request().request(sourceMapUrl.href, true)
.then((sourceMapBody: string) => {
let sourceMappingLocalPath = path.join(this.sourcesStoragePath, sourceMapUrl.pathname); // sourceMappingLocalPath = "$TMPDIR/index.ios.map"
let sourceMappingLocalPath = path.join(this.sourcesStoragePath, path.basename(sourceMapUrl.pathname)); // sourceMappingLocalPath = "$TMPDIR/index.ios.map"
let scriptFileRelativePath = path.basename(scriptUrl.pathname); // scriptFileRelativePath = "index.ios.bundle"
let updatedContent = this.sourceMapUtil.updateSourceMapFile(sourceMapBody, scriptFileRelativePath, this.sourcesStoragePath);
return new FileSystem().writeFile(sourceMappingLocalPath, updatedContent);
Expand Down
2 changes: 1 addition & 1 deletion src/test/common/ios/plistBuddy.test.ts
Expand Up @@ -64,7 +64,7 @@ suite("plistBuddy", function() {
const appName = "myApp";

const infoPlistPath = (simulator: boolean) =>
path.join(projectRoot, "ios", "build", "Build", "Products",
path.join(projectRoot, "build", "Build", "Products",
simulator ? "Debug-iphonesimulator" : "Debug-iphoneos",
`${appName}.app`, "Info.plist");

Expand Down

0 comments on commit 7091dc1

Please sign in to comment.