int main(int argc, char* argv[]) { #if 0 argv[1] = "input.xib"; argv[2] = "output.nib"; argc = 3; #endif TELEMETRY_INIT(L"AIF-47606e3a-4264-4368-8f7f-ed6ec3366dca"); if (checkTelemetryOptIn()) { TELEMETRY_ENABLE(); } else { TELEMETRY_DISABLE(); } std::tr2::sys::path fName(argv[1]); TELEMETRY_SET_INTERNAL(isMSFTInternalMachine()); string machineID = getMachineID(); if (!machineID.empty()) { TELEMETRY_SET_MACHINEID(machineID.c_str()); } TELEMETRY_EVENT_DATA(L"Xib2NibStart", fName.filename()); pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(argv[1]); if (!result) { printf("Error opening %s\n", argv[1]); TELEMETRY_FLUSH(); exit(2); return -1; } pugi::xml_node rootNode = doc.first_child(); const char* type = getNodeAttrib(rootNode, "type"); if (!type) { printf("Unable to find input type\n"); TELEMETRY_FLUSH(); exit(3); return -1; } if (strcmp(rootNode.name(), "document") == 0 && strcmp(type, "com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB") == 0) { if (argc < 3) { printf("Usage: xib2nib input.storyboard <outputdir>\n"); TELEMETRY_FLUSH(); exit(1); return -1; } struct stat st = { 0 }; stat(argv[2], &st); if (!(((st.st_mode) & S_IFMT) == S_IFDIR) && _mkdir(argv[2]) != 0) { printf("Unable to create directory %s err=%d\n", argv[2], errno); return -1; } strcpy(_g_outputDirectory, argv[2]); ConvertStoryboard(doc); } else if (strstr(type, ".XIB") != NULL) { if (argc < 3) { printf("Usage: xib2nib input.xib output.nib\n"); TELEMETRY_FLUSH(); exit(1); return -1; } FILE* fpOut = fopen(argv[2], "wb"); if (!fpOut) { printf("Error opening %s\n", argv[2]); TELEMETRY_FLUSH(); exit(3); return -1; } if (strcmp(rootNode.name(), "document") == 0) { ConvertXIB3ToNib(fpOut, doc); } else { ConvertXIBToNib(fpOut, doc); } fclose(fpOut); } else { printf("Unable to determine input type type=\"%s\"\n", type); TELEMETRY_FLUSH(); exit(4); return -1; } TELEMETRY_EVENT_DATA(L"Xib2NibFinish", fName.filename()); TELEMETRY_FLUSH(); exit(0); }
int main(int argc, char* argv[]) { StringSet targets, configurations, schemes; String sdkRoot, projectPath, xcconfigPath, workspacePath; String logVerbosity("warning"); int projectSet = 0; int workspaceSet = 0; int interactiveFlag = 0; int relativeSdkFlag = 0; int genProjectionsFlag = 0; int allTargets = 0; int allSchemes = 0; int mode = GenerateMode; static struct option long_options[] = { {"version", no_argument, 0, 0}, {"usage", no_argument, 0, 0}, {"help", no_argument, 0, 0}, {"interactive", no_argument, &interactiveFlag, 1}, {"loglevel", required_argument, 0, 0}, {"sdk", required_argument, 0, 0}, {"list", no_argument, &mode, ListMode}, {"project", required_argument, &projectSet, 1}, {"target", required_argument, 0, 0}, {"alltargets", no_argument, &allTargets, 1}, {"configuration", required_argument, 0, 0}, {"xcconfig", required_argument, 0, 0}, {"workspace", required_argument, &workspaceSet, 1}, {"scheme", required_argument, 0, 0}, {"allschemes", required_argument, &allSchemes, 1}, {"relativepath", no_argument, &relativeSdkFlag, 1}, { "genprojections", no_argument, &genProjectionsFlag, 1 }, {0, 0, 0, 0} }; int numOptions = sizeof(long_options) / sizeof(struct option) - 1; while (1) { int option_index = 0; int c = getopt_long_only(argc, argv, "", long_options, &option_index); if (c == -1) { break; } else if (c || option_index < 0 || option_index >= numOptions) { printUsage(argv[0], false); exit(EXIT_FAILURE); } // Process options switch (option_index) { case 0: printVersion(argv[0]); exit(EXIT_SUCCESS); break; case 1: printUsage(argv[0], false); exit(EXIT_SUCCESS); break; case 2: printUsage(argv[0], true); exit(EXIT_SUCCESS); break; case 4: logVerbosity = strToLower(optarg); break; case 5: sdkRoot = optarg; break; case 7: projectPath = optarg; break; case 8: targets.insert(optarg); break; case 10: configurations.insert(optarg); break; case 11: xcconfigPath = optarg; break; case 12: workspacePath = optarg; break; case 13: schemes.insert(optarg); break; default: // Do nothing break; } } // Set AI Telemetry_Init TELEMETRY_INIT(L"AIF-23c336e0-1e7e-43ba-a5ce-eb9dc8a06d34"); if (checkTelemetryOptIn()) { TELEMETRY_ENABLE(); } else { TELEMETRY_DISABLE(); } TELEMETRY_SET_INTERNAL(isMSFTInternalMachine()); String machineID = getMachineID(); if (!machineID.empty()) { TELEMETRY_SET_MACHINEID(machineID.c_str()); } TELEMETRY_EVENT_DATA(L"VSImporterStart", getProductVersion().c_str()); // Process non-option ARGV-elements VariableCollectionManager& settingsManager = VariableCollectionManager::get(); while (optind < argc) { String arg = argv[optind]; if (arg == "/?") { // Due to issue 6715724, flush before exiting TELEMETRY_EVENT_DATA(L"VSImporterIncomplete", "printUsage"); TELEMETRY_FLUSH(); printUsage(argv[0], true); exit(EXIT_SUCCESS); } else if (arg.find_first_of('=') != String::npos) { settingsManager.processGlobalAssignment(arg); } else { sbValidateWithTelemetry(0, "Unsupported argument: " + arg); } optind++; } // Set output format settingsManager.setGlobalVar("VSIMPORTER_OUTPUT_FORMAT", "WinStore10"); // Set logging level SBLogLevel logLevel; if (logVerbosity == "debug") logLevel = SB_DEBUG; else if (logVerbosity == "info") logLevel = SB_INFO; else if (logVerbosity == "warning") logLevel = SB_WARN; else if (logVerbosity == "error") logLevel = SB_ERROR; else if (!logVerbosity.empty()) { sbValidateWithTelemetry(0, "Unrecognized logging verbosity: " + logVerbosity); } SBLog::setVerbosity(logLevel); // Look for a project file in current directory, if one hasn't been explicitly specified if (!projectSet && !workspaceSet) { StringList projects; findFiles(".", "*.xcodeproj", DT_DIR, false, projects); StringList workspaces; findFiles(".", "*.xcworkspace", DT_DIR, false, workspaces); if (!workspaces.empty()) { sbValidateWithTelemetry(workspaces.size() == 1, "Multiple workspaces found. Select the workspace to use with the -workspace option."); workspacePath = workspaces.front(); workspaceSet = 1; } else if (!projects.empty()) { sbValidateWithTelemetry(projects.size() == 1, "Multiple projects found. Select the project to use with the -project option."); projectPath = projects.front(); projectSet = 1; } else { sbValidateWithTelemetry(0, "The current directory does not contain a project or workspace."); } } // Set the architecture String arch = "msvc"; settingsManager.setGlobalVar("ARCHS", arch); settingsManager.setGlobalVar("CURRENT_ARCH", arch); // Make sure workspace arguments are valid if (workspaceSet) { sbValidateWithTelemetry(!projectSet, "Cannot specify both a project and a workspace."); } // Disallow specifying schemes and targets together sbValidateWithTelemetry((schemes.empty() && !allSchemes) || (targets.empty() && !allTargets), "Cannot specify schemes and targets together."); // Process allTargets and allSchemes flags if (allSchemes) schemes.clear(); if (allTargets) targets.clear(); // Initialize global settings String binaryDir = sb_dirname(getBinaryLocation()); sbValidateWithTelemetry(!binaryDir.empty(), "Failed to resolve binary directory."); settingsManager.setGlobalVar("VSIMPORTER_BINARY_DIR", binaryDir); settingsManager.setGlobalVar("VSIMPORTER_INTERACTIVE", interactiveFlag ? "YES" : "NO"); settingsManager.setGlobalVar("VSIMPORTER_RELATIVE_SDK_PATH", relativeSdkFlag ? "YES" : "NO"); if (!sdkRoot.empty()) { sdkRoot = joinPaths(getcwd(), sdkRoot); } else { sdkRoot = joinPaths(binaryDir, ".."); } settingsManager.setGlobalVar("WINOBJC_SDK_ROOT", sdkRoot); // Add useful environment variables to global settings String username; sbValidateWithTelemetry(sb_getenv("USERNAME", username), "Failed to get current username."); settingsManager.setGlobalVar("USER", username); // Read xcconfig file specified from the command line if (!xcconfigPath.empty()) settingsManager.processGlobalConfigFile(xcconfigPath); // Read xcconfig file specified by the XCODE_XCCONFIG_FILE environment variable String xcconfigFile; if (sb_getenv("XCODE_XCCONFIG_FILE", xcconfigFile)) settingsManager.processGlobalConfigFile(xcconfigFile); // Validate WinObjC SDK directory checkWinObjCSDK(); // Create a workspace SBWorkspace *mainWorkspace; if (workspaceSet) { mainWorkspace = SBWorkspace::createFromWorkspace(workspacePath); } else if (projectSet) { mainWorkspace = SBWorkspace::createFromProject(projectPath); } else { sbAssertWithTelemetry(0); // non-reachable } if (mode == ListMode) { mainWorkspace->printSummary(); } else if (mode == GenerateMode) { if (!schemes.empty() || allSchemes) { mainWorkspace->queueSchemes(schemes, configurations); } else { mainWorkspace->queueTargets(targets, configurations); } mainWorkspace->generateFiles(genProjectionsFlag); } else { sbAssertWithTelemetry(0); // non-reachable } TELEMETRY_EVENT_DATA(L"VSImporterComplete", getProductVersion().c_str()); TELEMETRY_FLUSH(); return EXIT_SUCCESS; }
void NIBWriter::WriteData() { fwrite("NIBArchive", 10, 1, fpOut); int headerPos = ftell(fpOut); NIBHeader header = { 0 }; fwrite(&header, sizeof(header), 1, fpOut); // Write out class names StringCombiner classNames; header._classNamesOffset = ftell(fpOut); for ( int i = 0; i < _outputObjects.size(); i ++ ) { XIBObject *pObject = _outputObjects[i]; if (pObject->_outputClassName == NULL) { printf("Unable to find class mapping for required object <%s>\n", pObject->_node.name()); TELEMETRY_EVENT_DATA(L"MissingClassMapping", pObject->_node.name()); TELEMETRY_FLUSH(); exit(-1); } pObject->_outputClassNameIdx = classNames.AddString(pObject->_outputClassName); pObject->_outputObjectIdx = i; } for ( int i = 0; i < classNames._numStrings; i ++ ) { char *pName = classNames._stringTable[i]; int len = strlen(pName) + 1; WriteInt(len, 2); if ( len == 0x1b ) { int filler = 6; fwrite(&filler, 1, 4, fpOut); } fwrite(pName, 1, len, fpOut); header._numClassNames ++; } // Write out key names StringCombiner keyNames; header._keyNamesOffset = ftell(fpOut); for ( int i = 0; i < _outputObjects.size(); i ++ ) { XIBObject *pObject = _outputObjects[i]; for ( int j = 0; j < pObject->_outputMembers.size(); j ++ ) { pObject->_outputMembers[j]->_outputNameIdx = keyNames.AddString(pObject->_outputMembers[j]->_name); } } for ( int i = 0; i < keyNames._numStrings; i ++ ) { char *pName = keyNames._stringTable[i]; int len = strlen(pName) + 1; WriteInt(len, 1); fwrite(pName, 1, len, fpOut); header._numKeyNames ++; } // Write out items header._itemsOffset = ftell(fpOut); for ( int i = 0; i < _outputObjects.size(); i ++ ) { XIBObject *pObject = _outputObjects[i]; pObject->_outputMembersIdx = header._numItems; for ( int j = 0; j < pObject->_outputMembers.size(); j ++ ) { XIBMember *cur = pObject->_outputMembers[j]; // Write out name index WriteInt(cur->_outputNameIdx, 1); /*( printf("%s\n", cur->_name); if ( strcmp(cur->_name, "UICenter") == 0 ) { printf("Hi\n"); } */ // Write out item type + data cur->_obj->WriteData(this); header._numItems ++; } } // Write out objects header._objectsOffset = ftell(fpOut); for ( int i = 0; i < _outputObjects.size(); i ++ ) { XIBObject *pObject = _outputObjects[i]; // Write out class name index WriteInt(pObject->_outputClassNameIdx, 1); // Item index WriteInt(pObject->_outputMembersIdx, 1); // Item count WriteInt(pObject->_outputMembers.size(), 1); header._numObjects ++; } fseek(fpOut, headerPos, SEEK_SET); fwrite(&header, sizeof(header), 1, fpOut); }