@@ -34,7 +34,7 @@ export default class PlatformIOCoreStage extends BaseStage {
3434 }
3535
3636 configureBuiltInPython ( ) {
37- if ( ! this . params . useBuiltinPython || ! this . params . useBuiltinPIOCore ) {
37+ if ( ! this . params . useBuiltinPython ) {
3838 return ;
3939 }
4040 const builtInPythonDir = PlatformIOCoreStage . getBuiltInPythonDir ( ) ;
@@ -44,89 +44,19 @@ export default class PlatformIOCoreStage extends BaseStage {
4444 }
4545
4646 async check ( ) {
47- if ( ! this . params . useBuiltinPIOCore ) {
48- this . status = BaseStage . STATUS_SUCCESSED ;
49- return true ;
50- }
51- try {
52- await fs . access ( core . getEnvBinDir ( ) ) ;
53- } catch ( err ) {
54- throw new Error ( 'PlatformIO Core has not been installed yet!' ) ;
47+ if ( this . params . useBuiltinPIOCore ) {
48+ try {
49+ await fs . access ( core . getEnvBinDir ( ) ) ;
50+ } catch ( err ) {
51+ throw new Error ( 'PlatformIO Core has not been installed yet!' ) ;
52+ }
5553 }
5654 // check that PIO Core is installed and load its state an patch OS environ
5755 await this . loadCoreState ( ) ;
5856 this . status = BaseStage . STATUS_SUCCESSED ;
5957 return true ;
6058 }
6159
62- async install ( withProgress = undefined ) {
63- if ( ! withProgress ) {
64- withProgress = ( ) => { } ;
65- }
66-
67- if ( this . status === BaseStage . STATUS_SUCCESSED ) {
68- return true ;
69- }
70- if ( ! this . params . useBuiltinPIOCore ) {
71- this . status = BaseStage . STATUS_SUCCESSED ;
72- return true ;
73- }
74- this . status = BaseStage . STATUS_INSTALLING ;
75- withProgress ( 'Preparing for installation' , 10 ) ;
76-
77- try {
78- // shutdown all PIO Home servers which block python.exe on Windows
79- await home . shutdownAllServers ( ) ;
80-
81- if ( this . params . useBuiltinPython ) {
82- withProgress ( 'Downloading portable Python interpreter' , 10 ) ;
83- try {
84- await installPortablePython ( PlatformIOCoreStage . getBuiltInPythonDir ( ) ) ;
85- } catch ( err ) {
86- console . warn ( err ) ;
87- // cleanup
88- try {
89- await fs . rmdir ( PlatformIOCoreStage . getBuiltInPythonDir ( ) , {
90- recursive : true ,
91- } ) ;
92- } catch ( err ) { }
93- }
94- }
95-
96- withProgress ( 'Installing PlatformIO Core' , 20 ) ;
97- const scriptArgs = [ ] ;
98- if ( this . useDevCore ( ) ) {
99- scriptArgs . push ( '--dev' ) ;
100- }
101- console . info (
102- await callInstallerScript (
103- await this . whereIsPython ( { prompt : true } ) ,
104- scriptArgs
105- )
106- ) ;
107-
108- // check that PIO Core is installed and load its state an patch OS environ
109- withProgress ( 'Loading PlatformIO Core state' , 40 ) ;
110- await this . loadCoreState ( ) ;
111-
112- withProgress ( 'Installing PlatformIO Home' , 10 ) ;
113- await this . installPIOHome ( ) ;
114- } catch ( err ) {
115- misc . reportError ( err ) ;
116- throw err ;
117- }
118-
119- withProgress ( 'Completed!' , 10 ) ;
120- return true ;
121- }
122-
123- useDevCore ( ) {
124- return (
125- this . params . useDevelopmentPIOCore ||
126- ( this . params . pioCoreVersionSpec || '' ) . includes ( '-' )
127- ) ;
128- }
129-
13060 async loadCoreState ( ) {
13161 const stateJSONPath = path . join (
13262 core . getTmpDir ( ) ,
@@ -140,12 +70,17 @@ export default class PlatformIOCoreStage extends BaseStage {
14070 ...[
14171 'check' ,
14272 'core' ,
143- this . params . disableAutoUpdates ? '--no-auto-upgrade' : '--auto-upgrade' ,
73+ this . params . disableAutoUpdates || ! this . params . useBuiltinPIOCore
74+ ? '--no-auto-upgrade'
75+ : '--auto-upgrade' ,
14476 ]
14577 ) ;
14678 if ( this . params . pioCoreVersionSpec ) {
14779 scriptArgs . push ( ...[ '--version-spec' , this . params . pioCoreVersionSpec ] ) ;
14880 }
81+ if ( ! this . params . useBuiltinPIOCore ) {
82+ scriptArgs . push ( '--global' ) ;
83+ }
14984 scriptArgs . push ( ...[ '--dump-state' , stateJSONPath ] ) ;
15085 console . info ( await callInstallerScript ( await this . whereIsPython ( ) , scriptArgs ) ) ;
15186
@@ -157,14 +92,23 @@ export default class PlatformIOCoreStage extends BaseStage {
15792
15893 // Add PIO Core virtualenv to global PATH
15994 // Setup `platformio` CLI globally for a Node.JS process
160- proc . extendOSEnvironPath ( 'PLATFORMIO_PATH' , [
161- core . getEnvBinDir ( ) ,
162- core . getEnvDir ( ) ,
163- ] ) ;
95+ if ( this . params . useBuiltinPIOCore ) {
96+ proc . extendOSEnvironPath ( 'PLATFORMIO_PATH' , [
97+ core . getEnvBinDir ( ) ,
98+ core . getEnvDir ( ) ,
99+ ] ) ;
100+ }
164101
165102 return true ;
166103 }
167104
105+ useDevCore ( ) {
106+ return (
107+ this . params . useDevelopmentPIOCore ||
108+ ( this . params . pioCoreVersionSpec || '' ) . includes ( '-' )
109+ ) ;
110+ }
111+
168112 async whereIsPython ( { prompt = false } = { } ) {
169113 let status = this . params . pythonPrompt . STATUS_TRY_AGAIN ;
170114 this . configureBuiltInPython ( ) ;
@@ -196,6 +140,68 @@ export default class PlatformIOCoreStage extends BaseStage {
196140 ) ;
197141 }
198142
143+ async install ( withProgress = undefined ) {
144+ if ( this . status === BaseStage . STATUS_SUCCESSED ) {
145+ return true ;
146+ }
147+ if ( ! this . params . useBuiltinPIOCore ) {
148+ this . status = BaseStage . STATUS_FAILED ;
149+ throw new Error (
150+ 'Could not find compatible PlatformIO Core. Please enable `platformio-ide.useBuiltinPIOCore` setting and restart IDE.'
151+ ) ;
152+ }
153+ this . status = BaseStage . STATUS_INSTALLING ;
154+
155+ if ( ! withProgress ) {
156+ withProgress = ( ) => { } ;
157+ }
158+ withProgress ( 'Preparing for installation' , 10 ) ;
159+ try {
160+ // shutdown all PIO Home servers which block python.exe on Windows
161+ await home . shutdownAllServers ( ) ;
162+
163+ if ( this . params . useBuiltinPython ) {
164+ withProgress ( 'Downloading portable Python interpreter' , 10 ) ;
165+ try {
166+ await installPortablePython ( PlatformIOCoreStage . getBuiltInPythonDir ( ) ) ;
167+ } catch ( err ) {
168+ console . warn ( err ) ;
169+ // cleanup
170+ try {
171+ await fs . rmdir ( PlatformIOCoreStage . getBuiltInPythonDir ( ) , {
172+ recursive : true ,
173+ } ) ;
174+ } catch ( err ) { }
175+ }
176+ }
177+
178+ withProgress ( 'Installing PlatformIO Core' , 20 ) ;
179+ const scriptArgs = [ ] ;
180+ if ( this . useDevCore ( ) ) {
181+ scriptArgs . push ( '--dev' ) ;
182+ }
183+ console . info (
184+ await callInstallerScript (
185+ await this . whereIsPython ( { prompt : true } ) ,
186+ scriptArgs
187+ )
188+ ) ;
189+
190+ // check that PIO Core is installed and load its state an patch OS environ
191+ withProgress ( 'Loading PlatformIO Core state' , 40 ) ;
192+ await this . loadCoreState ( ) ;
193+
194+ withProgress ( 'Installing PlatformIO Home' , 10 ) ;
195+ await this . installPIOHome ( ) ;
196+ } catch ( err ) {
197+ misc . reportError ( err ) ;
198+ throw err ;
199+ }
200+
201+ withProgress ( 'Completed!' , 10 ) ;
202+ return true ;
203+ }
204+
199205 installPIOHome ( ) {
200206 return new Promise ( ( resolve ) => {
201207 core . runPIOCommand (
0 commit comments