@@ -468,11 +468,6 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
468
468
const std::string CmakeHelpFile =
469
469
appendPath (OutRoot.getCanonicalPath ().str (), " dpct.cmake" );
470
470
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
- }
476
471
477
472
const std::string VersionStr = Major + " ." + Minor;
478
473
const int CompatibilityValue = std::stoi (Major) * 10 + std::stoi (Minor);
@@ -517,39 +512,31 @@ void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
517
512
}
518
513
519
514
static void loadMainSrcFileInfo (clang::tooling::UnifiedPath YamlFilePath) {
520
- auto PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
521
515
if (llvm::sys::fs::exists (YamlFilePath.getCanonicalPath ())) {
516
+ auto PreTU =
517
+ std::make_shared<clang::tooling::TranslationUnitReplacements>();
522
518
if (loadFromYaml (YamlFilePath, *PreTU) != 0 ) {
523
519
llvm::errs () << getLoadYamlFailWarning ();
524
520
}
525
521
DpctGlobalInfo::setMainSourceYamlTUR (PreTU);
526
522
527
- if (MigrateBuildScriptOnly && !DpctGlobalInfo::migratePythonScripts () ||
528
- DpctGlobalInfo::migrateCMakeScripts ()) {
529
- std::string Major = PreTU->SDKVersionMajor ;
530
- std::string Minor = PreTU->SDKVersionMinor ;
531
- if (!Major.empty () && !Minor.empty ()) {
532
- updateCompatibilityVersionInfo (OutRoot, Major, Minor);
533
- }
523
+ for (auto &Entry : PreTU->MainSourceFilesDigest ) {
524
+ if (Entry.HasCUDASyntax )
525
+ MainSrcFilesHasCudaSyntex.insert (Entry.MainSourceFile );
534
526
}
535
- }
536
-
537
- for (auto &Entry : PreTU->MainSourceFilesDigest ) {
538
- if (Entry.HasCUDASyntax )
539
- MainSrcFilesHasCudaSyntex.insert (Entry.MainSourceFile );
540
- }
541
527
542
- // Currently, when "--use-experimental-features=device_global" and
543
- // "--use-experimental-features=all" are specified, the migrated code should
544
- // be compiled with C++20 or later.
545
- auto Iter = PreTU->OptionMap .find (" ExperimentalFlag" );
546
- if (Iter != PreTU->OptionMap .end ()) {
547
- if (Iter->second .Specified ) {
548
- const std::string Value = Iter->second .Value ;
549
- unsigned int UValue = std::stoul (Value);
550
- if (UValue & (1 << static_cast <unsigned >(
551
- ExperimentalFeatures::Exp_DeviceGlobal))) {
552
- LANG_Cplusplus_20_Used = true ;
528
+ // Currently, when "--use-experimental-features=device_global" and
529
+ // "--use-experimental-features=all" are specified, the migrated code should
530
+ // be compiled with C++20 or later.
531
+ auto Iter = PreTU->OptionMap .find (" ExperimentalFlag" );
532
+ if (Iter != PreTU->OptionMap .end ()) {
533
+ if (Iter->second .Specified ) {
534
+ const std::string Value = Iter->second .Value ;
535
+ unsigned int UValue = std::stoul (Value);
536
+ if (UValue & (1 << static_cast <unsigned >(
537
+ ExperimentalFeatures::Exp_DeviceGlobal))) {
538
+ LANG_Cplusplus_20_Used = true ;
539
+ }
553
540
}
554
541
}
555
542
}
@@ -634,6 +621,12 @@ void showReportHeader() {
634
621
}
635
622
636
623
void checkIncMigrationOrExit () {
624
+ auto PreTU = DpctGlobalInfo::getMainSourceYamlTUR ();
625
+ if (!PreTU) {
626
+ PreTU = std::make_shared<clang::tooling::TranslationUnitReplacements>();
627
+ DpctGlobalInfo::setMainSourceYamlTUR (PreTU);
628
+ return ;
629
+ }
637
630
if (!MigrateBuildScriptOnly &&
638
631
clang::dpct::DpctGlobalInfo::isIncMigration ()) {
639
632
std::string Msg;
@@ -816,7 +809,7 @@ int runDPCT(int argc, const char **argv) {
816
809
CudaIncludePath = CudaInclude;
817
810
SDKPath = SDKPathOpt;
818
811
819
- loadMainSrcFileInfo (OutRootPath.getCanonicalPath () + " /MainSourceFiles.yaml" );
812
+ loadMainSrcFileInfo (OutRootPath.getCanonicalPath () + " /MainSourceFiles.yaml" ); // 1
820
813
821
814
std::transform (
822
815
RuleFile.begin (), RuleFile.end (),
@@ -1342,8 +1335,6 @@ int runDPCT(int argc, const char **argv) {
1342
1335
UseDPCPPExtensions.getNumOccurrences ());
1343
1336
setValueToOptMap (clang::dpct::OPTION_NoDRYPattern, NoDRYPattern.getValue (),
1344
1337
NoDRYPattern.getNumOccurrences ());
1345
- setValueToOptMap (clang::dpct::OPTION_CompilationsDir, CompilationsDir,
1346
- OptParser->isPSpecified ());
1347
1338
#ifdef _WIN32
1348
1339
if (!VcxprojFilePath.getPath ().empty ()) {
1349
1340
setValueToOptMap (clang::dpct::OPTION_VcxprojFile,
@@ -1387,14 +1378,24 @@ int runDPCT(int argc, const char **argv) {
1387
1378
setValueToOptMap (clang::dpct::OPTION_UseSYCLCompat, UseSYCLCompat.getValue (),
1388
1379
UseSYCLCompat.getNumOccurrences ());
1389
1380
1390
- checkIncMigrationOrExit ();
1381
+ checkIncMigrationOrExit (); // 2
1391
1382
}
1392
1383
1393
1384
if (DpctGlobalInfo::getFormatRange () != clang::format::FormatRange::none) {
1394
1385
parseFormatStyle ();
1395
1386
}
1396
1387
// OC_Action: only migrate Build scripts.
1397
1388
if (MigrateBuildScriptOnly) {
1389
+ if (!DpctGlobalInfo::migratePythonScripts () ||
1390
+ DpctGlobalInfo::migrateCMakeScripts ()) {
1391
+ std::string Major =
1392
+ DpctGlobalInfo::getMainSourceYamlTUR ()->SDKVersionMajor ;
1393
+ std::string Minor =
1394
+ DpctGlobalInfo::getMainSourceYamlTUR ()->SDKVersionMinor ;
1395
+ if (!Major.empty () && !Minor.empty ()) {
1396
+ updateCompatibilityVersionInfo (OutRoot, Major, Minor);
1397
+ }
1398
+ }
1398
1399
collectBuildScriptsSpecified (OptParser, InRootPath, OutRootPath);
1399
1400
migrateBuildScripts (InRootPath, OutRootPath);
1400
1401
0 commit comments