Skip to content

Fix failed ios build after second info-plist merge #1083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/definitions/npm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ declare module "npm" {
var commands: { [index: string]: any };
var prefix: string;
function load(config: Object, callback: (err: any, data: any) => void): void;
module config {
var loaded: boolean;
module sources {
var cli: { data: Object };
}
}
}
1 change: 1 addition & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface IPlatformData {
targetedOS?: string[];
configurationFileName?: string;
configurationFilePath?: string;
relativeToFrameworkConfigurationFilePath: string;
mergeXmlConfig?: any[];
}

Expand Down
3 changes: 2 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ interface IPlatformProjectService {
platformData: IPlatformData;
validate(): IFuture<void>;
createProject(frameworkDir: string, frameworkVersion: string): IFuture<void>;
interpolateData(projectRoot: string): IFuture<void>;
interpolateData(): IFuture<void>;
interpolateConfigurationFile(configurationFilePath?: string): IFuture<void>;
afterCreateProject(projectRoot: string): IFuture<void>;
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
prepareProject(): IFuture<void>;
Expand Down
25 changes: 17 additions & 8 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ export class NodePackageManager implements INodePackageManager {
}

public load(config?: any): IFuture<void> {
let future = new Future<void>();
npm.load(config, (err: Error) => {
if(err) {
future.throw(err);
} else {
future.return();
if (npm.config.loaded) {
let data = npm.config.sources.cli.data;
Object.keys(data).forEach(k => delete data[k]);
if (config) {
_.assign(data, config);
}
});
return future;
return Future.fromResult();
} else {
let future = new Future<void>();
npm.load(config, (err: Error) => {
if(err) {
future.throw(err);
} else {
future.return();
}
});
return future;
}
}

public install(packageName: string, pathToSave: string, config?: any): IFuture<any> {
Expand Down
17 changes: 12 additions & 5 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as semver from "semver";
import * as projectServiceBaseLib from "./platform-project-service-base";
import * as androidDebugBridgePath from "../common/mobile/android/android-debug-bridge";

class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
private static VALUES_DIRNAME = "values";
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
private static ANDROID_PLATFORM_NAME = "android";
Expand Down Expand Up @@ -57,6 +57,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
frameworkFilesExtensions: [".jar", ".dat", ".so"],
configurationFileName: "AndroidManifest.xml",
configurationFilePath: path.join(projectRoot, "src", "main", "AndroidManifest.xml"),
relativeToFrameworkConfigurationFilePath: path.join("src", "main", "AndroidManifest.xml"),
mergeXmlConfig: [{ "nodename": "manifest", "attrname": "*" }, {"nodename": "application", "attrname": "*"}]
};
}
Expand Down Expand Up @@ -134,18 +135,24 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
}).future<void>()();
}

public interpolateData(projectRoot: string): IFuture<void> {
public interpolateData(): IFuture<void> {
return (() => {
// Interpolate the activity name and package
let manifestPath = this.platformData.configurationFilePath;
shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, manifestPath);
// Interpolate the apilevel and package
this.interpolateConfigurationFile().wait();

let stringsFilePath = path.join(this.getAppResourcesDestinationDirectoryPath().wait(), 'values', 'strings.xml');
shell.sed('-i', /__NAME__/, this.$projectData.projectName, stringsFilePath);
shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath);

let gradleSettingsFilePath = path.join(this.platformData.projectRoot, "settings.gradle");
shell.sed('-i', /__PROJECT_NAME__/, this.getProjectNameFromId(), gradleSettingsFilePath);
}).future<void>()();
}

public interpolateConfigurationFile(): IFuture<void> {
return (() => {
let manifestPath = this.platformData.configurationFilePath;
shell.sed('-i', /__PACKAGE__/, this.$projectData.projectId, manifestPath);
shell.sed('-i', /__APILEVEL__/, this.$options.sdk || this.$androidToolsInfo.getToolsInfo().wait().compileSdkVersion.toString(), manifestPath);
}).future<void>()();
}
Expand Down
22 changes: 15 additions & 7 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
targetedOS: ['darwin'],
configurationFileName: "Info.plist",
configurationFilePath: path.join(projectRoot, this.$projectData.projectName, this.$projectData.projectName+"-Info.plist"),
relativeToFrameworkConfigurationFilePath: path.join("__PROJECT_NAME__", "__PROJECT_NAME__-Info.plist"),
mergeXmlConfig: [{ "nodename": "plist", "attrname": "*" }, {"nodename": "dict", "attrname": "*"}]
};
}
Expand Down Expand Up @@ -118,20 +119,27 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}).future<void>()();
}

public interpolateData(projectRoot: string): IFuture<void> {
public interpolateData(): IFuture<void> {
return (() => {
let infoPlistFilePath = path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, util.format("%s-%s", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, "Info.plist"));
shell.sed('-i', "__CFBUNDLEIDENTIFIER__", this.$projectData.projectId, infoPlistFilePath);
let infoPlistFilePath = path.join(this.platformData.projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, util.format("%s-%s", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, "Info.plist"));
this.interpolateConfigurationFile(infoPlistFilePath).wait();

this.replaceFileName("-Info.plist", path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)).wait();
this.replaceFileName("-Prefix.pch", path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)).wait();
this.replaceFileName(IOSProjectService.XCODE_PROJECT_EXT_NAME, projectRoot).wait();
let projectRootFilePath = path.join(this.platformData.projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER);
this.replaceFileName("-Info.plist", projectRootFilePath).wait();
this.replaceFileName("-Prefix.pch", projectRootFilePath).wait();
this.replaceFileName(IOSProjectService.XCODE_PROJECT_EXT_NAME, this.platformData.projectRoot).wait();

let pbxprojFilePath = path.join(projectRoot, this.$projectData.projectName + IOSProjectService.XCODE_PROJECT_EXT_NAME, "project.pbxproj");
let pbxprojFilePath = path.join(this.platformData.projectRoot, this.$projectData.projectName + IOSProjectService.XCODE_PROJECT_EXT_NAME, "project.pbxproj");
this.replaceFileContent(pbxprojFilePath).wait();
}).future<void>()();
}

public interpolateConfigurationFile(configurationFilePath?: string): IFuture<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this function to return a future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (() => {
shell.sed('-i', "__CFBUNDLEIDENTIFIER__", this.$projectData.projectId, configurationFilePath || this.platformData.configurationFilePath);
}).future<void>()();
}

public afterCreateProject(projectRoot: string): IFuture<void> {
return (() => {
this.$fs.rename(path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER),
Expand Down
2 changes: 1 addition & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class PlatformService implements IPlatformService {
this.$fs.deleteDirectory(path.join(frameworkDir, "../../")).wait();
}

platformData.platformProjectService.interpolateData(platformData.projectRoot).wait();
platformData.platformProjectService.interpolateData().wait();
platformData.platformProjectService.afterCreateProject(platformData.projectRoot).wait();

this.$projectDataService.initialize(this.$projectData.projectDir);
Expand Down
70 changes: 33 additions & 37 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ export class PluginsService implements IPluginsService {

public remove(pluginName: string): IFuture<void> {
return (() => {
let isUninstallCommandExecuted = false;

let executeUninstallCommand = () => {
return (() => {
if(!isUninstallCommandExecuted) {
this.executeNpmCommand(PluginsService.UNINSTALL_COMMAND_NAME, pluginName).wait();
isUninstallCommandExecuted = true;
}
}).future<void>()();
};

let removePluginNativeCodeAction = (modulesDestinationPath: string, platform: string, platformData: IPlatformData) => {
return (() => {
let pluginData = this.convertToPluginData(this.getNodeModuleData(pluginName).wait());
Expand All @@ -86,25 +75,7 @@ export class PluginsService implements IPluginsService {
// Remove the plugin and call merge for another plugins that have configuration file
let pluginConfigurationFilePath = this.getPluginConfigurationFilePath(pluginData, platformData);
if(this.$fs.exists(pluginConfigurationFilePath).wait()) {
let tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, constants.TNS_MODULES_FOLDER_NAME);
let nodeModules = this.$broccoliBuilder.getChangedNodeModules(tnsModulesDestinationPath, platform).wait();

_(nodeModules)
.map(nodeModule => this.getNodeModuleData(pluginName).wait())
.map(nodeModuleData => this.convertToPluginData(nodeModuleData))
.filter(data => data.isPlugin && this.$fs.exists(this.getPluginConfigurationFilePath(data, platformData)).wait())
.forEach((data, index) => {
executeUninstallCommand().wait();

if(index === 0) {
this.initializeConfigurationFileFromCache(platformData).wait();
}

if(data.name !== pluginName) {
this.merge(data, platformData).wait();
}
})
.value();
this.merge(pluginData, platformData, (data: IPluginData) => data.name !== pluginData.name).wait();
}

if(pluginData.pluginVariables) {
Expand All @@ -114,7 +85,7 @@ export class PluginsService implements IPluginsService {
};
this.executeForAllInstalledPlatforms(removePluginNativeCodeAction).wait();

executeUninstallCommand().wait();
this.executeNpmCommand(PluginsService.UNINSTALL_COMMAND_NAME, pluginName).wait();

let showMessage = true;
let action = (modulesDestinationPath: string, platform: string, platformData: IPlatformData) => {
Expand All @@ -137,15 +108,17 @@ export class PluginsService implements IPluginsService {
return (() => {
this.$projectDataService.initialize(this.$projectData.projectDir);
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait().version;
this.$npm.cache(platformData.frameworkPackageName, frameworkVersion).wait();

let relativeConfigurationFilePath = path.relative(platformData.projectRoot, platformData.configurationFilePath);
// We need to resolve this manager here due to some restrictions from npm api and in order to load PluginsService.NPM_CONFIG config
let npmInstallationManager: INpmInstallationManager = this.$injector.resolve("npmInstallationManager");
npmInstallationManager.addToCache(platformData.frameworkPackageName, frameworkVersion).wait();

let cachedPackagePath = npmInstallationManager.getCachedPackagePath(platformData.frameworkPackageName, frameworkVersion);
let cachedConfigurationFilePath = path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, relativeConfigurationFilePath);
let cachedConfigurationFilePath = path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, platformData.relativeToFrameworkConfigurationFilePath);
let cachedConfigurationFileContent = this.$fs.readText(cachedConfigurationFilePath).wait();
this.$fs.writeFile(platformData.configurationFilePath, cachedConfigurationFileContent).wait();

shelljs.cp("-f", cachedConfigurationFilePath, path.dirname(platformData.configurationFilePath));
platformData.platformProjectService.interpolateConfigurationFile().wait();
}).future<void>()();
}

Expand All @@ -164,7 +137,6 @@ export class PluginsService implements IPluginsService {
shelljs.cp("-Rf", pluginData.fullPath, pluginDestinationPath);

let pluginConfigurationFilePath = this.getPluginConfigurationFilePath(pluginData, platformData);

if(this.$fs.exists(pluginConfigurationFilePath).wait()) {
this.merge(pluginData, platformData).wait();
}
Expand Down Expand Up @@ -347,7 +319,7 @@ export class PluginsService implements IPluginsService {
doc.parseFromString(xml, 'text/xml');
}

private merge(pluginData: IPluginData, platformData: IPlatformData): IFuture<void> {
private mergeCore(pluginData: IPluginData, platformData: IPlatformData): IFuture<void> {
return (() => {
let pluginConfigurationFilePath = this.getPluginConfigurationFilePath(pluginData, platformData);
let configurationFilePath = platformData.configurationFilePath;
Expand All @@ -368,6 +340,30 @@ export class PluginsService implements IPluginsService {
}).future<void>()();
}

private merge(pluginData: IPluginData, platformData: IPlatformData, mergeCondition?: (_pluginData: IPluginData) => boolean): IFuture<void> {
return (() => {
let tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, constants.TNS_MODULES_FOLDER_NAME);
let nodeModules = this.$broccoliBuilder.getChangedNodeModules(tnsModulesDestinationPath, platformData.normalizedPlatformName.toLowerCase()).wait();

_(nodeModules)
.keys()
.map(nodeModule => this.getNodeModuleData(path.join(nodeModule, "package.json")).wait())
.map(nodeModuleData => this.convertToPluginData(nodeModuleData))
.filter(data => data.isPlugin && this.$fs.exists(this.getPluginConfigurationFilePath(data, platformData)).wait())
.forEach((data, index) => {
if(index === 0) {
this.initializeConfigurationFileFromCache(platformData).wait();
}

if(!mergeCondition || (mergeCondition && mergeCondition(data))) {
this.mergeCore(data, platformData).wait();
}
})
.value();

}).future<void>()();
}

private getPluginConfigurationFilePath(pluginData: IPluginData, platformData: IPlatformData): string {
let pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(platformData.normalizedPlatformName.toLowerCase());
let pluginConfigurationFilePath = path.join(pluginPlatformsFolderPath, platformData.configurationFileName);
Expand Down
1 change: 0 additions & 1 deletion lib/tools/broccoli/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let through = require("through2");

export class Builder implements IBroccoliBuilder {
constructor(private $fs: IFileSystem,
private $nodeModulesTree: INodeModulesTree,
private $projectData: IProjectData,
private $projectDataService: IProjectDataService,
private $injector: IInjector,
Expand Down
1 change: 1 addition & 0 deletions test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PlatformData implements IPlatformData {
frameworkVersion = "";
appDestinationDirectoryPath = "";
appResourcesDestinationDirectoryPath = "";
relativeToFrameworkConfigurationFilePath = "";
}

class ErrorsNoFailStub implements IErrors {
Expand Down
Loading