@@ -39,8 +39,6 @@ def GDB_NAME():
39
39
return f"{ COMPILER_TRIPLE } -gdb"
40
40
41
41
42
- CMAKE_TOOLCHAIN_NAME = "pico_arm_gcc.cmake"
43
-
44
42
VSCODE_LAUNCH_FILENAME = "launch.json"
45
43
VSCODE_C_PROPERTIES_FILENAME = "c_cpp_properties.json"
46
44
VSCODE_CMAKE_KITS_FILENAME = "cmake-kits.json"
@@ -475,29 +473,12 @@ def semver_compare_ge(first, second):
475
473
return first_tuple >= second_tuple
476
474
477
475
478
- def CheckPrerequisites ():
476
+ def CheckSystemType ():
479
477
global isMac , isWindows , isx86
480
478
isMac = platform .system () == "Darwin"
481
479
isWindows = platform .system () == "Windows"
482
480
isx86 = platform .machine ().lower () in ["x86_64" , "amd64" ]
483
481
484
- # Do we have a compiler?
485
- return shutil .which (COMPILER_NAME (), 1 , os .environ ["Path" if isWindows else "PATH" ])
486
-
487
-
488
- def CheckSDKPath (gui ):
489
- sdkPath = os .getenv ("PICO_SDK_PATH" )
490
-
491
- if sdkPath == None :
492
- m = "Unable to locate the Raspberry Pi Pico SDK, PICO_SDK_PATH is not set"
493
- print (m )
494
- elif not os .path .isdir (sdkPath ):
495
- m = "Unable to locate the Raspberry Pi Pico SDK, PICO_SDK_PATH does not point to a directory"
496
- print (m )
497
- sdkPath = None
498
-
499
- return sdkPath
500
-
501
482
502
483
def GetFilePath (filename ):
503
484
if os .path .islink (__file__ ):
@@ -513,18 +494,6 @@ def ParseCommandLine():
513
494
)
514
495
parser = argparse .ArgumentParser (description = "Pico Project generator" )
515
496
parser .add_argument ("name" , nargs = "?" , help = "Name of the project" )
516
- parser .add_argument (
517
- "-t" ,
518
- "--tsv" ,
519
- help = "Select an alternative pico_configs.tsv file" ,
520
- default = GetFilePath ("pico_configs.tsv" ),
521
- )
522
- parser .add_argument (
523
- "-o" ,
524
- "--output" ,
525
- help = "Set an alternative CMakeList.txt filename" ,
526
- default = "CMakeLists.txt" ,
527
- )
528
497
parser .add_argument (
529
498
"-x" ,
530
499
"--examples" ,
@@ -537,15 +506,6 @@ def ParseCommandLine():
537
506
action = "store_true" ,
538
507
help = "Add example code for UART support with the Pico SDK" ,
539
508
)
540
- parser .add_argument (
541
- "-l" , "--list" , action = "store_true" , help = "List available features"
542
- )
543
- parser .add_argument (
544
- "-c" ,
545
- "--configs" ,
546
- action = "store_true" ,
547
- help = "List available project configuration items" ,
548
- )
549
509
parser .add_argument (
550
510
"-f" , "--feature" , action = "append" , help = "Add feature to generated project"
551
511
)
@@ -567,15 +527,6 @@ def ParseCommandLine():
567
527
action = "store_true" ,
568
528
help = "Convert an examples folder to standalone project" ,
569
529
)
570
- parser .add_argument (
571
- "-b" , "--build" , action = "store_true" , help = "Build after project created"
572
- )
573
- parser .add_argument (
574
- "-g" ,
575
- "--gui" ,
576
- action = "store_true" ,
577
- help = "Run a GUI version of the project generator" ,
578
- )
579
530
parser .add_argument (
580
531
"-p" ,
581
532
"--project" ,
@@ -645,10 +596,6 @@ def ParseCommandLine():
645
596
default = "pico" ,
646
597
help = "Select board type (see --boardlist for available boards)" ,
647
598
)
648
- parser .add_argument (
649
- "-bl" , "--boardlist" , action = "store_true" , help = "List available board types"
650
- )
651
- parser .add_argument ("-cp" , "--cpath" , help = "Override default VSCode compiler path" )
652
599
parser .add_argument (
653
600
"-root" ,
654
601
"--projectRoot" ,
@@ -687,6 +634,11 @@ def ParseCommandLine():
687
634
action = "store_true" ,
688
635
help = "Enable CMake Tools extension integration" ,
689
636
)
637
+ parser .add_argument (
638
+ "-uhome" ,
639
+ "--userHome" ,
640
+ help = "Full path to user's home directory" ,
641
+ )
690
642
691
643
return parser .parse_args ()
692
644
@@ -957,7 +909,7 @@ def GenerateCMake(folder, params):
957
909
# Standard include directories
958
910
file .write ("# Add the standard include files to the build\n " )
959
911
file .write (f"target_include_directories({ projectName } PRIVATE\n " )
960
- file .write (" ${CMAKE_CURRENT_LIST_DIR}\n " )
912
+ file .write (" " + " ${CMAKE_CURRENT_LIST_DIR}\n " )
961
913
file .write (")\n \n " )
962
914
963
915
# Selected libraries/features
@@ -980,7 +932,6 @@ def GenerateCMake(folder, params):
980
932
def generateProjectFiles (
981
933
projectPath ,
982
934
projectName ,
983
- sdkPath ,
984
935
projects ,
985
936
debugger ,
986
937
sdkVersion ,
@@ -1338,40 +1289,7 @@ def generateProjectFiles(
1338
1289
os .chdir (oldCWD )
1339
1290
1340
1291
1341
- def LoadConfigurations ():
1342
- try :
1343
- with open (args .tsv ) as tsvfile :
1344
- reader = csv .DictReader (tsvfile , dialect = "excel-tab" )
1345
- for row in reader :
1346
- configuration_dictionary .append (row )
1347
- except :
1348
- print ("No Pico configurations file found. Continuing without" )
1349
-
1350
-
1351
- def LoadBoardTypes (sdkPath ):
1352
- # Scan the boards folder for all header files, extract filenames, and make a list of the results
1353
- # default folder is <PICO_SDK_PATH>/src/boards/include/boards/*
1354
- # If the PICO_BOARD_HEADER_DIRS environment variable is set, use that as well
1355
-
1356
- loc = sdkPath / "src/boards/include/boards"
1357
- boards = []
1358
- for x in Path (loc ).iterdir ():
1359
- if x .suffix == ".h" :
1360
- boards .append (x .stem )
1361
-
1362
- loc = os .getenv ("PICO_BOARD_HEADER_DIRS" )
1363
-
1364
- if loc != None :
1365
- for x in Path (loc ).iterdir ():
1366
- if x .suffix == ".h" :
1367
- boards .append (x .stem )
1368
-
1369
- return boards
1370
-
1371
-
1372
- def DoEverything (parent , params ):
1373
- global CMAKE_TOOLCHAIN_NAME
1374
-
1292
+ def DoEverything (params ):
1375
1293
if not os .path .exists (params ["projectRoot" ]):
1376
1294
print ("Invalid project path" )
1377
1295
sys .exit (- 1 )
@@ -1404,7 +1322,11 @@ def DoEverything(parent, params):
1404
1322
# Copy the SDK finder cmake file to our project folder
1405
1323
# Can be found here <PICO_SDK_PATH>/external/pico_sdk_import.cmake
1406
1324
shutil .copyfile (
1407
- params ["sdkPath" ] / "external" / "pico_sdk_import.cmake" ,
1325
+ os .path .join (
1326
+ params ["userHome" ] + relativeSDKPath (params ["sdkVersion" ]),
1327
+ "external" ,
1328
+ "pico_sdk_import.cmake" ,
1329
+ ),
1408
1330
projectPath / "pico_sdk_import.cmake" ,
1409
1331
)
1410
1332
@@ -1467,46 +1389,10 @@ def DoEverything(parent, params):
1467
1389
if os .path .exists (CMAKECACHE_FILENAME ):
1468
1390
os .remove (CMAKECACHE_FILENAME )
1469
1391
1470
- cpus = os .cpu_count ()
1471
- if cpus == None :
1472
- cpus = 1
1473
-
1474
- if isWindows :
1475
- if shutil .which ("ninja" ) or (
1476
- params ["ninjaPath" ] != None and params ["ninjaPath" ] != ""
1477
- ):
1478
- # When installing SDK version 1.5.0 on windows with installer pico-setup-windows-x64-standalone.exe, ninja is used
1479
- cmakeCmd = params ["cmakePath" ] + " -G Ninja .."
1480
- makeCmd = params ["ninjaPath" ] + " "
1481
- else :
1482
- # Everything else assume nmake
1483
- cmakeCmd = params ["cmakePath" ] + ' -G "NMake Makefiles" ..'
1484
- makeCmd = "nmake "
1485
- else :
1486
- # Ninja now works OK under Linux, so if installed use it by default. It's faster.
1487
- if shutil .which ("ninja" ) or (
1488
- params ["ninjaPath" ] != None and params ["ninjaPath" ] != ""
1489
- ):
1490
- cmakeCmd = params ["cmakePath" ] + " -G Ninja .."
1491
- makeCmd = params ["ninjaPath" ] + " "
1492
- else :
1493
- cmakeCmd = params ["cmakePath" ] + " .."
1494
- makeCmd = "make -j" + str (cpus )
1495
-
1496
- os .system (cmakeCmd )
1497
-
1498
- # Extract CMake Toolchain File
1499
- if os .path .exists (CMAKECACHE_FILENAME ):
1500
- cacheFile = open (CMAKECACHE_FILENAME , "r" )
1501
- for line in cacheFile :
1502
- if re .search ("CMAKE_TOOLCHAIN_FILE:FILEPATH=" , line ):
1503
- CMAKE_TOOLCHAIN_NAME = line .split ("=" )[- 1 ].split ("/" )[- 1 ].strip ()
1504
-
1505
1392
if params ["projects" ]:
1506
1393
generateProjectFiles (
1507
1394
projectPath ,
1508
1395
params ["projectName" ],
1509
- params ["sdkPath" ],
1510
1396
params ["projects" ],
1511
1397
params ["debugger" ],
1512
1398
params ["sdkVersion" ],
@@ -1518,12 +1404,6 @@ def DoEverything(parent, params):
1518
1404
params ["useCmakeTools" ],
1519
1405
)
1520
1406
1521
- if params ["wantBuild" ]:
1522
- os .system (makeCmd )
1523
- print (
1524
- "\n If the application has built correctly, you can now transfer it to the Raspberry Pi Pico board"
1525
- )
1526
-
1527
1407
os .chdir (oldCWD )
1528
1408
1529
1409
@@ -1547,111 +1427,58 @@ def DoEverything(parent, params):
1547
1427
else :
1548
1428
COMPILER_TRIPLE = RISCV_TRIPLE
1549
1429
1550
- # Check we have everything we need to compile etc
1551
- c = CheckPrerequisites ()
1552
-
1553
- ## TODO Do both warnings in the same error message so user does have to keep coming back to find still more to do
1554
-
1555
- if c == None :
1556
- m = f"Unable to find the `{ COMPILER_NAME ()} ` compiler\n "
1557
- m += "You will need to install an appropriate compiler to build a Raspberry Pi Pico project\n "
1558
- m += "See the Raspberry Pi Pico documentation for how to do this on your particular platform\n "
1559
-
1560
- print (m )
1561
- sys .exit (- 1 )
1430
+ # Populate isMac, isWindows, isx86 variables
1431
+ CheckSystemType ()
1562
1432
1563
- if (
1564
- args .name == None
1565
- and not args .gui
1566
- and not args .list
1567
- and not args .configs
1568
- and not args .boardlist
1569
- ):
1433
+ if args .name == None :
1570
1434
print ("No project name specfied\n " )
1571
1435
sys .exit (- 1 )
1572
1436
1573
1437
# Check if we were provided a compiler path, and override the default if so
1574
- if args .cpath :
1575
- compilerPath = Path (args .cpath )
1576
- elif args .toolchainVersion :
1438
+ if args .toolchainVersion :
1577
1439
compilerPath = Path (
1578
1440
codeToolchainPath (args .toolchainVersion ) + "/bin/" + COMPILER_NAME ()
1579
1441
)
1580
1442
else :
1581
- compilerPath = Path (c )
1582
-
1583
- # load/parse any configuration dictionary we may have
1584
- LoadConfigurations ()
1585
-
1586
- p = CheckSDKPath (args .gui )
1587
-
1588
- if p == None :
1443
+ print ("No toolchain version specfied\n " )
1589
1444
sys .exit (- 1 )
1590
1445
1591
- sdkPath = Path (p )
1592
-
1593
- boardtype_list = LoadBoardTypes (sdkPath )
1594
- boardtype_list .sort ()
1595
-
1596
1446
projectRoot = Path (os .getcwd ()) if not args .projectRoot else Path (args .projectRoot )
1597
1447
1598
- if args .list or args .configs or args .boardlist :
1599
- if args .list :
1600
- print ("Available project features:\n " )
1601
- for feat in features_list :
1602
- print (feat .ljust (6 ), "\t " , features_list [feat ][GUI_TEXT ])
1603
- print ("\n " )
1604
-
1605
- if args .configs :
1606
- print ("Available project configuration items:\n " )
1607
- for conf in configuration_dictionary :
1608
- print (conf ["name" ].ljust (40 ), "\t " , conf ["description" ])
1609
- print ("\n " )
1610
-
1611
- if args .boardlist :
1612
- print ("Available board types:\n " )
1613
- for board in boardtype_list :
1614
- print (board )
1615
- print ("\n " )
1616
-
1617
- sys .exit (0 )
1618
- else :
1619
- params = {
1620
- "sdkPath" : sdkPath ,
1621
- "projectRoot" : projectRoot ,
1622
- "projectName" : args .name ,
1623
- "wantGUI" : False ,
1624
- "wantOverwrite" : args .overwrite ,
1625
- "wantConvert" : args .convert or args .example ,
1626
- "wantExample" : args .example ,
1627
- "wantThreadsafeBackground" : False ,
1628
- "wantPoll" : False ,
1629
- "boardtype" : args .boardtype ,
1630
- "wantBuild" : args .build ,
1631
- "features" : args .feature ,
1632
- "projects" : args .project ,
1633
- "configs" : (),
1634
- "wantRunFromRAM" : args .runFromRAM ,
1635
- "wantEntryProjName" : args .entryProjName ,
1636
- "wantExamples" : args .examples ,
1637
- "wantUARTExample" : args .uartExample ,
1638
- "wantUART" : args .uart ,
1639
- "wantUSB" : args .usb ,
1640
- "wantCPP" : args .cpp ,
1641
- "debugger" : args .debugger ,
1642
- "exceptions" : args .cppexceptions ,
1643
- "rtti" : args .cpprtti ,
1644
- "ssid" : "" ,
1645
- "password" : "" ,
1646
- "sdkVersion" : args .sdkVersion ,
1647
- "toolchainVersion" : args .toolchainVersion ,
1648
- "picotoolVersion" : args .picotoolVersion ,
1649
- "ninjaPath" : args .ninjaPath ,
1650
- "cmakePath" : args .cmakePath ,
1651
- "openOCDVersion" : args .openOCDVersion ,
1652
- "exampleLibs" : args .exampleLibs if args .exampleLibs is not None else [],
1653
- "useCmakeTools" : args .useCmakeTools ,
1654
- }
1655
-
1656
- DoEverything (None , params )
1657
- sys .exit (0 )
1448
+ params = {
1449
+ "projectRoot" : projectRoot ,
1450
+ "userHome" : args .userHome ,
1451
+ "projectName" : args .name ,
1452
+ "wantOverwrite" : args .overwrite ,
1453
+ "wantConvert" : args .convert or args .example ,
1454
+ "wantExample" : args .example ,
1455
+ "wantThreadsafeBackground" : False ,
1456
+ "wantPoll" : False ,
1457
+ "boardtype" : args .boardtype ,
1458
+ "features" : args .feature ,
1459
+ "projects" : args .project ,
1460
+ "configs" : (),
1461
+ "wantRunFromRAM" : args .runFromRAM ,
1462
+ "wantEntryProjName" : args .entryProjName ,
1463
+ "wantExamples" : args .examples ,
1464
+ "wantUARTExample" : args .uartExample ,
1465
+ "wantUART" : args .uart ,
1466
+ "wantUSB" : args .usb ,
1467
+ "wantCPP" : args .cpp ,
1468
+ "debugger" : args .debugger ,
1469
+ "exceptions" : args .cppexceptions ,
1470
+ "rtti" : args .cpprtti ,
1471
+ "ssid" : "" ,
1472
+ "password" : "" ,
1473
+ "sdkVersion" : args .sdkVersion ,
1474
+ "toolchainVersion" : args .toolchainVersion ,
1475
+ "picotoolVersion" : args .picotoolVersion ,
1476
+ "ninjaPath" : args .ninjaPath ,
1477
+ "cmakePath" : args .cmakePath ,
1478
+ "openOCDVersion" : args .openOCDVersion ,
1479
+ "exampleLibs" : args .exampleLibs if args .exampleLibs is not None else [],
1480
+ "useCmakeTools" : args .useCmakeTools ,
1481
+ }
1482
+
1483
+ DoEverything (params )
1484
+ sys .exit (0 )
0 commit comments