@@ -468,11 +468,6 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
468468 const std::string CmakeHelpFile =
469469 appendPath (OutRoot.getCanonicalPath ().str (), " dpct.cmake" );
470470 std::ifstream InFile (CmakeHelpFile);
471- if (!InFile) {
472- std::string ErrMsg = " Failed to open file: " + CmakeHelpFile;
473- ShowStatus (MigrationErrorReadWriteCMakeHelperFile, std::move (ErrMsg));
474- dpctExit (MigrationErrorReadWriteCMakeHelperFile);
475- }
476471
477472 const std::string VersionStr = Major + " ." + Minor;
478473 const int CompatibilityValue = std::stoi (Major) * 10 + std::stoi (Minor);
@@ -516,24 +511,14 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
516511 OutFile.close ();
517512}
518513
519- static void loadMainSrcFileInfo (clang::tooling::UnifiedPath OutRoot ) {
520- std::string YamlFilePath = appendPath (OutRoot .getCanonicalPath (). str (),
521- DpctGlobalInfo::getYamlFileName ()) ;
514+ static void loadMainSrcFileInfo (clang::tooling::UnifiedPath YamlFilePath ) {
515+ if (! llvm::sys::fs::exists (YamlFilePath .getCanonicalPath ()))
516+ return ;
522517 auto PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
523- if (llvm::sys::fs::exists (YamlFilePath)) {
524- if (loadFromYaml (YamlFilePath, *PreTU) != 0 ) {
525- llvm::errs () << getLoadYamlFailWarning (YamlFilePath);
526- }
527-
528- if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts () ||
529- DpctGlobalInfo::migrateCMakeScripts ()) {
530- std::string Major = PreTU->SDKVersionMajor ;
531- std::string Minor = PreTU->SDKVersionMinor ;
532- if (!Major.empty () && !Minor.empty ()) {
533- updateCompatibilityVersionInfo (OutRoot, Major, Minor);
534- }
535- }
518+ if (loadFromYaml (YamlFilePath, *PreTU) != 0 ) {
519+ llvm::errs () << getLoadYamlFailWarning ();
536520 }
521+ DpctGlobalInfo::setMainSourceYamlTUR (PreTU);
537522
538523 for (auto &Entry : PreTU->MainSourceFilesDigest ) {
539524 if (Entry.HasCUDASyntax )
@@ -635,6 +620,12 @@ void showReportHeader() {
635620}
636621
637622void checkIncMigrationOrExit () {
623+ auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR ();
624+ if (!PreTU) {
625+ PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
626+ DpctGlobalInfo::setMainSourceYamlTUR (PreTU);
627+ return ;
628+ }
638629 if (!MigrateBuildScriptOnly &&
639630 clang::dpct::DpctGlobalInfo::isIncMigration ()) {
640631 std::string Msg;
@@ -679,7 +670,6 @@ int migrateBuildScripts(const clang::tooling::UnifiedPath &InRoot,
679670}
680671
681672void doBuildScriptMigration () {
682- loadMainSrcFileInfo (OutRootPath);
683673 collectBuildScripts (InRootPath, OutRootPath);
684674 migrateBuildScripts (InRootPath, OutRootPath);
685675}
@@ -817,6 +807,9 @@ int runDPCT(int argc, const char **argv) {
817807 std::string OutRootPathCUDACodepin = " " ;
818808 CudaIncludePath = CudaInclude;
819809 SDKPath = SDKPathOpt;
810+
811+ loadMainSrcFileInfo (OutRootPath.getCanonicalPath () + " /MainSourceFiles.yaml" );
812+
820813 std::transform (
821814 RuleFile.begin (), RuleFile.end (),
822815 std::back_insert_iterator<std::vector<clang::tooling::UnifiedPath>>(
@@ -1343,19 +1336,6 @@ int runDPCT(int argc, const char **argv) {
13431336 UseDPCPPExtensions.getNumOccurrences ());
13441337 setValueToOptMap (clang::dpct::OPTION_NoDRYPattern, NoDRYPattern.getValue (),
13451338 NoDRYPattern.getNumOccurrences ());
1346- setValueToOptMap (clang::dpct::OPTION_CompilationsDir, CompilationsDir,
1347- OptParser->isPSpecified ());
1348- #ifdef _WIN32
1349- if (!VcxprojFilePath.getPath ().empty ()) {
1350- setValueToOptMap (clang::dpct::OPTION_VcxprojFile,
1351- VcxprojFilePath.getCanonicalPath ().str (),
1352- OptParser->isVcxprojfileSpecified ());
1353- } else {
1354- setValueToOptMap (clang::dpct::OPTION_VcxprojFile,
1355- VcxprojFilePath.getPath ().str (),
1356- OptParser->isVcxprojfileSpecified ());
1357- }
1358- #endif
13591339 setValueToOptMap (clang::dpct::OPTION_ProcessAll, ProcessAll.getValue (),
13601340 ProcessAll.getNumOccurrences ());
13611341 setValueToOptMap (clang::dpct::OPTION_SyclNamedLambda, SyclNamedLambda.getValue (),
@@ -1395,11 +1375,17 @@ int runDPCT(int argc, const char **argv) {
13951375 parseFormatStyle ();
13961376 }
13971377 // OC_Action: only migrate Build scripts.
1378+ if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts () ||
1379+ DpctGlobalInfo::migrateCMakeScripts ()) {
1380+ std::string Major = DpctGlobalInfo::getMainSourceYamlTUR ()->SDKVersionMajor ;
1381+ std::string Minor = DpctGlobalInfo::getMainSourceYamlTUR ()->SDKVersionMinor ;
1382+ if (!Major.empty () && !Minor.empty ()) {
1383+ updateCompatibilityVersionInfo (OutRoot, Major, Minor);
1384+ }
1385+ }
13981386 if (MigrateBuildScriptOnly) {
1399- loadMainSrcFileInfo (OutRootPath);
14001387 collectBuildScriptsSpecified (OptParser, InRootPath, OutRootPath);
14011388 migrateBuildScripts (InRootPath, OutRootPath);
1402-
14031389 ShowStatus (MigrationBuildScriptCompleted);
14041390 dpctExit (MigrationSucceeded, false );
14051391 }
0 commit comments