@@ -36,18 +36,17 @@ import { Component, ComponentFileItem } from './EIDEProjectModules';
3636import { GlobalEvent } from './GlobalEvents' ;
3737import { SettingManager } from './SettingManager' ;
3838import { ExceptionToMessage } from './Message' ;
39- import { AbstractProject } from './EIDEProject' ;
39+ import { AbstractProject , VirtualSource } from './EIDEProject' ;
4040import { ArrayDelRepetition } from '../lib/node-utility/Utility' ;
4141
4242export class DependenceManager implements ManagerInterface {
4343
44- static readonly DEPENDENCE_DIR = `.eide/ deps` ;
44+ static readonly DEPS_VFOLDER_NAME = '< deps>' ;
4545 static readonly RTE_FILE_NAME = 'RTE_Components.h' ;
4646 static readonly toolchainDepName = 'toolchain' ;
4747
4848 private project : AbstractProject ;
4949 private prjType : ProjectType | undefined ;
50- private depDir : File | undefined ;
5150
5251 private componentDefines : Map < string , string > ;
5352
@@ -61,79 +60,65 @@ export class DependenceManager implements ManagerInterface {
6160 }
6261
6362 Init ( ) {
64- const rootDir = this . project . GetRootDir ( ) ;
6563 this . prjType = this . project . GetConfiguration ( ) . config . type ;
66- this . depDir = File . fromArray ( [ rootDir . path , File . normalize ( DependenceManager . DEPENDENCE_DIR ) ] ) ;
6764 this . LoadComponents ( ) ;
6865 }
6966
70- InstallComponent ( packName : string , component : Component , clearDir : boolean = true ) {
71-
72- // try add dep root to project before install a component
73- this . tryAddCompRootDirToProject ( ) ;
74-
75- const config = this . project . GetConfiguration ( ) ;
76- const toolchain = this . project . getToolchain ( ) ;
77-
78- const groupDir = File . fromArray ( [ this . getDepDir ( ) . path , packName ] ) ;
79- const componentDir = File . fromArray ( [ groupDir . path , component . groupName ] ) ;
80-
81- componentDir . CreateDir ( true ) ;
82- if ( clearDir ) { DeleteAllChildren ( componentDir ) ; }
67+ InstallComponent ( packName : string , component : Component ) {
8368
69+ const config = this . project . GetConfiguration ( ) ;
70+ const toolchain = this . project . getToolchain ( ) ;
8471 const packageManager = this . project . GetPackManager ( ) ;
72+ const vSource = this . project . getVirtualSourceManager ( ) ;
8573
8674 const item_filter = function ( item : ComponentFileItem ) : boolean {
8775 return ( item . attr != 'template' )
8876 && ( item . condition ? packageManager . CheckCondition ( item . condition , toolchain ) : true ) ;
8977 }
9078
9179 /* filter files */
92- const asmList = component . asmList . filter ( item_filter ) ;
93- const cFileList = component . cFileList . filter ( item_filter ) ;
80+ const asmList = component . asmList . filter ( item_filter ) ;
81+ const cFileList = component . cFileList . filter ( item_filter ) ;
9482 const headerList = component . headerList . filter ( item_filter ) ;
9583 const linkerList = component . linkerList ?. filter ( item_filter ) ;
9684
9785 const conditionList : Set < string > = new Set ( ) ;
9886
9987 // copy file
10088 asmList . forEach ( ( item ) => {
101- componentDir . CopyFile ( new File ( item . path ) ) ;
10289 if ( item . condition ) {
10390 conditionList . add ( item . condition ) ;
10491 }
10592 } ) ;
10693 cFileList . forEach ( ( item ) => {
107- componentDir . CopyFile ( new File ( item . path ) ) ;
10894 if ( item . condition ) {
10995 conditionList . add ( item . condition ) ;
11096 }
11197 } ) ;
11298 headerList . forEach ( ( item ) => {
113- componentDir . CopyFile ( new File ( item . path ) ) ;
11499 if ( item . condition ) {
115100 conditionList . add ( item . condition ) ;
116101 }
117102 } ) ;
118103 linkerList ?. forEach ( ( item ) => {
119- componentDir . CopyFile ( new File ( item . path ) ) ;
120104 if ( item . condition ) {
121105 conditionList . add ( item . condition ) ;
122106 }
123107 } ) ;
124108
109+ // add source files
110+ const _srcfiles = ArrayDelRepetition ( headerList . concat ( cFileList , asmList ) . map ( f => f . path ) ) ;
111+ this . createComponentDir ( packName , component . groupName ) ;
112+ vSource . addFiles (
113+ VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME , packName , component . groupName ) , _srcfiles ) ;
114+
125115 // add condiions to cache
126116 this . addComponentCache ( packName , component . groupName , Array . from ( conditionList ) ) ;
127117
128118 const incList = component . incDirList . map ( item => item . path ) ;
129-
130- // add dependence dir
131- incList . push ( componentDir . path ) ;
132-
133119 const dep : Dependence = {
134120 name : component . groupName ,
135121 incList : incList ,
136- sourceDirList : [ componentDir . path ] ,
137122 libList : component . libList ? component . libList . map < string > ( ( item ) => { return item . path ; } ) : [ ] ,
138123 defineList : component . defineList || [ ]
139124 } ;
@@ -149,12 +134,16 @@ export class DependenceManager implements ManagerInterface {
149134
150135 private InstallBuildInComponent ( packName : string , component : Component ) {
151136
152- const config = this . project . GetConfiguration ( ) ;
137+ const config = this . project . GetConfiguration ( ) ;
138+ const sources = ArrayDelRepetition ( component . cFileList . concat ( component . asmList ) . map ( f => f . path ) ) ;
139+
140+ if ( sources . length > 0 ) {
141+ this . createComponentDir ( packName , component . groupName ) ;
142+ }
153143
154144 const dep : Dependence = {
155145 name : component . groupName ,
156146 incList : component . incDirList . map ( item => item . path ) ,
157- sourceDirList : [ ] ,
158147 libList : component . libList ? component . libList . map < string > ( ( item ) => { return item . path ; } ) : [ ] ,
159148 defineList : component . defineList || [ ]
160149 } ;
@@ -172,20 +161,13 @@ export class DependenceManager implements ManagerInterface {
172161
173162 const config = this . project . GetConfiguration ( ) ;
174163
175- const componentDir = File . fromArray ( [ this . getDependenceRootFolder ( ) . path , packName , componentName ] ) ;
176- if ( componentDir . IsDir ( ) ) {
177- DeleteDir ( componentDir ) ;
178- }
164+ this . deleteComponentDir ( packName , componentName ) ;
179165
180166 if ( config . IsExisted ( packName , componentName ) ) {
181167 config . RemoveDependence ( packName , componentName ) ;
182168 }
183169
184- // force delete build-in folder
185- const depRootFoler = new File ( componentDir . dir ) ;
186- if ( depRootFoler . IsDir ( ) ) {
187- DeleteDir ( depRootFoler ) ;
188- }
170+ this . deletePackageDir ( packName ) ;
189171
190172 // remove from cache
191173 this . removeComponentCache ( packName , componentName ) ;
@@ -197,17 +179,14 @@ export class DependenceManager implements ManagerInterface {
197179
198180 const config = this . project . GetConfiguration ( ) ;
199181
200- const componentDir = File . fromArray ( [ this . getDepDir ( ) . path , packName , componentName ] ) ;
201- if ( componentDir . IsDir ( ) ) {
202- DeleteDir ( componentDir ) ;
203- }
182+ this . deleteComponentDir ( packName , componentName ) ;
204183
205184 if ( config . IsExisted ( packName , componentName ) ) {
206185 config . RemoveDependence ( packName , componentName ) ;
207186 }
208187
209188 if ( config . IsDependenceEmpty ( packName ) ) { // delete folder if no deps
210- DeleteDir ( new File ( componentDir . dir ) ) ;
189+ this . deletePackageDir ( packName ) ;
211190 }
212191
213192 // remove from cache
@@ -242,13 +221,6 @@ export class DependenceManager implements ManagerInterface {
242221 this . ClearObsoleteComponentDependence ( ) ; // clear invalid dependencies
243222 }
244223
245- getDependenceRootFolder ( ) : File {
246- if ( this . depDir === undefined ) {
247- throw new Error ( 'eide depDir is undefined' ) ;
248- }
249- return this . depDir ;
250- }
251-
252224 // force flush toolchain dependence
253225 flushToolchainDep ( notCacheEvt ?: boolean ) {
254226 try {
@@ -323,17 +295,43 @@ export class DependenceManager implements ManagerInterface {
323295
324296 //--
325297
326- private tryAddCompRootDirToProject ( ) {
327- const depRoot = this . getDependenceRootFolder ( ) ;
328- if ( ! depRoot . IsDir ( ) ) depRoot . CreateDir ( false ) ;
329- const prjConfig = this . project . GetConfiguration ( ) ;
330- prjConfig . addSrcDirAtFirst ( depRoot . path ) ;
331- prjConfig . CustomDep_AddIncDir ( depRoot ) ;
298+ private createDepsRootFolder ( ) {
299+ const vSource = this . project . getVirtualSourceManager ( ) ;
300+ vSource . addFolder ( DependenceManager . DEPS_VFOLDER_NAME ) ;
301+ }
302+
303+ private createComponentDir ( pkg_name : string , component_name : string ) {
304+ this . createDepsRootFolder ( ) ;
305+ const vSource = this . project . getVirtualSourceManager ( ) ;
306+ vSource . addFolder ( pkg_name , VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME ) ) ;
307+ vSource . addFolder ( component_name , VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME , pkg_name ) ) ;
308+ }
309+
310+ private deleteComponentDir ( pkg_name : string , component_name : string ) {
311+ const vSource = this . project . getVirtualSourceManager ( ) ;
312+ vSource . removeFolder (
313+ VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME , pkg_name , component_name ) ) ;
314+ }
315+
316+ private deleteDepsRootFolder ( ) {
317+ const vSource = this . project . getVirtualSourceManager ( ) ;
318+ vSource . removeFolder (
319+ VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME ) ) ;
332320 }
333321
334- private getDepDir ( ) : File {
335- this . depDir ?. CreateDir ( false ) ;
336- return < File > this . depDir ;
322+ private deletePackageDir ( pkg_name : string ) {
323+ const vSource = this . project . getVirtualSourceManager ( ) ;
324+ vSource . removeFolder (
325+ VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME , pkg_name ) ) ;
326+ /* remove deps root folder if it's empty */
327+ const folder = vSource . getFolder ( VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME ) ) ;
328+ if ( folder && folder . folders . length == 0 ) {
329+ if ( folder . files . length == 0 )
330+ this . deleteDepsRootFolder ( ) ;
331+ else if ( folder . files . length == 1 &&
332+ NodePath . basename ( folder . files [ 0 ] . path ) == DependenceManager . RTE_FILE_NAME )
333+ this . deleteDepsRootFolder ( ) ;
334+ }
337335 }
338336
339337 private isAutoGenRTEHeader ( ) : boolean {
@@ -353,17 +351,10 @@ export class DependenceManager implements ManagerInterface {
353351
354352 if ( prjConfig . IsExisted ( packInfo . name , component . groupName ) ) {
355353
356- const componentDirPath = this . getDepDir ( ) . path + File . sep
357- + packInfo . name + File . sep
358- + component . groupName ;
359-
360354 const incList = component . incDirList . map ( ( item ) : string => { return item . path ; } ) ;
361- incList . push ( componentDirPath ) ;
362-
363355 const dep : Dependence = {
364356 name : component . groupName ,
365357 incList : incList ,
366- sourceDirList : [ componentDirPath ] ,
367358 libList : component . libList ?. map < string > ( ( item ) => { return item . path ; } ) || [ ] ,
368359 defineList : [ ]
369360 } ;
@@ -381,13 +372,22 @@ export class DependenceManager implements ManagerInterface {
381372
382373 if ( isAutoGenerate ) {
383374 this . GenerateRTEComponentsFile ( Array . from ( this . componentDefines . values ( ) ) ) ;
375+ prjConfig . CustomDep_AddIncDirAtFirst ( this . project . getRootDir ( ) ) ;
384376 }
385377 }
386378
387379 private AddRTEComponents ( component : Component ) {
388380 if ( this . isAutoGenRTEHeader ( ) && ! this . componentDefines . has ( component . groupName ) ) {
389381 this . componentDefines . set ( component . groupName , component . RTE_define || '' ) ;
390382 this . GenerateRTEComponentsFile ( Array . from ( this . componentDefines . values ( ) ) ) ;
383+ /* add RTE header to resource manager */
384+ const vSource = this . project . getVirtualSourceManager ( ) ;
385+ const vFile = vSource . getFile ( VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME , DependenceManager . RTE_FILE_NAME ) ) ;
386+ if ( ! vFile ) {
387+ vSource . addFile ( VirtualSource . toAbsPath ( DependenceManager . DEPS_VFOLDER_NAME ) ,
388+ File . from ( this . project . getRootDir ( ) . path , DependenceManager . RTE_FILE_NAME ) . path ) ;
389+ this . project . GetConfiguration ( ) . CustomDep_AddIncDirAtFirst ( this . project . getRootDir ( ) ) ;
390+ }
391391 }
392392 }
393393
@@ -422,13 +422,13 @@ export class DependenceManager implements ManagerInterface {
422422
423423 content = content . concat ( lines , contentTail ) ;
424424
425- const rteFile = File . fromArray ( [ this . getDepDir ( ) . path , DependenceManager . RTE_FILE_NAME ] ) ;
425+ const rteFile = File . from ( this . project . getRootDir ( ) . path , DependenceManager . RTE_FILE_NAME ) ;
426426 rteFile . Write ( content . join ( os . EOL ) ) ;
427427 }
428428
429429 private DeleteRTEComponentsHeader ( ) {
430430 try {
431- const rte_header = File . fromArray ( [ this . getDepDir ( ) . path , DependenceManager . RTE_FILE_NAME ] ) ;
431+ const rte_header = File . from ( this . project . getRootDir ( ) . path , DependenceManager . RTE_FILE_NAME ) ;
432432 if ( rte_header . IsFile ( ) ) { fs . unlinkSync ( rte_header . path ) ; }
433433 } catch ( error ) {
434434 // do nothing
0 commit comments