コード例 #1
0
ファイル: vsimporter.cpp プロジェクト: Acorld/WinObjC-Heading
static void checkWinObjCSDK()
{
  const BuildSettings bs(NULL);
  String sdkRoot = bs.getValue("WINOBJC_SDK_ROOT");
  String baseErrMsg = "Invalid WINOBJC_SDK_ROOT specified: \"" + platformPath(sdkRoot) + "\". ";
  sbValidate(!sb_realpath(sdkRoot).empty(), baseErrMsg + "The SDK directory does not exist.");

  String templateDir = bs.getValue("VSIMPORTER_TEMPLATES_DIR");
  sbValidate(!sb_realpath(templateDir).empty(), baseErrMsg + "The SDK directory is missing vsimporter templates.");
}
void SBFrameworksBuildPhase::loadFrameworkBlockListFromFile(const String& fileName)
{
    // Get the path to the file which has the block list.
    const BuildSettings bs(NULL);
    String templateDir = bs.getValue("VSIMPORTER_TEMPLATES_DIR");
    
    // If we have reached this far the folder is guaranteed to exist as we must have already called checkWinObjCSDK().
    assert(!sb_realpath(templateDir).empty());
    
    String blockListFilePath = joinPaths(templateDir, fileName);
    ifstream file(blockListFilePath);
    if (file.is_open())
    {
        String line;
        while (getline(file, line))
        {
            StringVec tokens;
            tokenize(line, tokens, "-> ");
            if (tokens.size() == 0)
            {
                // empty line
                continue;
            }

            // We do not expect more than 2 tokens per line.
            // First is the blocked library name and possibly a second token which is the replacement library name.
            sbValidate(tokens.size() <= 2, 
                "Invalid Block List: Only one blocked library and an optional replacement library separated by '->' are allowed per line");
            
            String blockedLibrary = tokens[0];

            // We may or may not have the replacement library specified.
            String replaceWithLibrary = "";
            if (tokens.size() > 1)
            {
                replaceWithLibrary = tokens[1];

                // Check if the library replacements form a cycle.
                auto it = s_blockedLibraries.find(replaceWithLibrary);
                while (it != s_blockedLibraries.end())
                {
                    replaceWithLibrary = it->second;
                    sbValidate(blockedLibrary != replaceWithLibrary, 
                        blockedLibrary + " is trying to cyclically replace itself with another blocked library.");
                    it = s_blockedLibraries.find(replaceWithLibrary);
                }
            }

            s_blockedLibraries.insert(pair<String, String>(blockedLibrary, replaceWithLibrary));
        }
        file.close();
    }
}
コード例 #3
0
ファイル: VCProject.cpp プロジェクト: CadeLaRen/WinObjC
bool VCProject::writeTemplate(const std::string& filePath, const LabelHandlerFnMap& handlers) const
{
  // Open the template
  pugi::xml_document projDoc;
  pugi::xml_parse_result result = projDoc.load_file(filePath.c_str());
  sbValidate(result, "Failed to open template file: " + filePath);
  pugi::xml_node projRoot = projDoc.first_child();

  for (pugi::xml_node child = projRoot.first_child(); child; child = child.next_sibling()) {
    // Check each child for a VSImporterLabel attribute
    pugi::xml_attribute sblabelAttr = child.attribute("VSImporterLabel");
    std::string sblabelValue = sblabelAttr.value();

    // Get rid of the attribute, if one was found
    if (sblabelAttr) {
      child.remove_attribute(sblabelAttr);
    } else {
      continue;
    }

    // Handle the label
    auto nodeHandlerIt = handlers.find(sblabelValue);
    if (nodeHandlerIt != handlers.end()) {
      callMemberFunction(this, nodeHandlerIt->second)(child);
    } else {
      SBLog::warning() << "Unrecognized VSImporterLabel attribute \"" << sblabelValue << "\" in " << filePath << std::endl;
    }
  }

  // Output tree
  return projDoc.save_file(filePath.c_str(), "  ");
}
コード例 #4
0
ファイル: vsimporter.cpp プロジェクト: Acorld/WinObjC-Heading
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 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},
    {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_FAILURE);

    // Process options
    switch (option_index) {
    case 0:
      printVersion(argv[0]);
      break;
    case 1:
      printUsage(argv[0], false, EXIT_SUCCESS);
      break;
    case 2:
      printUsage(argv[0], true, 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", "WinStore10");

  // 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_FLUSH();
        printUsage(argv[0], true, EXIT_SUCCESS);
    } else if (arg.find_first_of('=') != String::npos) {
      settingsManager.processGlobalAssignment(arg);
    } else {
      sbValidate(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())
    sbValidate(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()) {
      sbValidate(workspaces.size() == 1, "Multiple workspaces found. Select the workspace to use with the -workspace option.");
      workspacePath = workspaces.front();
      workspaceSet = 1;
    } else if (!projects.empty()) {
      sbValidate(projects.size() == 1, "Multiple projects found. Select the project to use with the -project option.");
      projectPath = projects.front();
      projectSet = 1;
    } else {
      sbValidate(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) {
    sbValidate(!projectSet, "Cannot specify both a project and a workspace.");
    sbValidate(targets.empty(), "Cannot specify target(s) when specifying a workspace.");
  }

  // Disallow specifying schemes and targets together
  sbValidate((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());
  sbValidate(!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;
  sbValidate(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 {
    sbAssert(0); // non-reachable
  }

  if (mode == ListMode) {
    mainWorkspace->printSummary();
  } else if (mode == GenerateMode) {
    if (allTargets) {
      mainWorkspace->queueAllTargets(configurations);
    } else if (projectSet) {
      mainWorkspace->queueTargets(targets, configurations);
    } else if (workspaceSet) {
      mainWorkspace->queueSchemes(schemes, configurations);
    } else {
      sbAssert(0); // non-reachable
    }
    mainWorkspace->generateFiles();
  } else {
    sbAssert(0); // non-reachable
  }

  TELEMETRY_EVENT_DATA(L"VSImporterComplete", "WinStore10");
  TELEMETRY_FLUSH();

  return EXIT_SUCCESS;
}