-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework particle.include and particle.ignore for CLI compile #646
Changes from 7 commits
c81f495
df1c33e
f1958d1
20e3aac
85cd050
8e3bc78
9907954
ddcdb7e
ae25437
eeac2ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -749,7 +749,7 @@ module.exports = class CloudCommand extends CLICommandBase { | |||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
if (!alwaysIncludeThisFile && settings.notSourceExtensions.includes(ext)){ | ||||||||||
if (!alwaysIncludeThisFile && settings.notSourceExtensions.includes(ext)){ // not source files | ||||||||||
continue; | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -779,11 +779,24 @@ module.exports = class CloudCommand extends CLICommandBase { | |||||||||
*/ | ||||||||||
_processDirIncludes(fileMapping, dirname, { followSymlinks } = {}){ | ||||||||||
dirname = path.resolve(dirname); | ||||||||||
let files = new Set(); | ||||||||||
|
||||||||||
const includesFile = path.join(dirname, settings.dirIncludeFilename); | ||||||||||
const ignoreFile = path.join(dirname, settings.dirExcludeFilename); | ||||||||||
let hasIncludeFile = false; | ||||||||||
this._getDefaultIncludes(files, dirname, { followSymlinks }); | ||||||||||
this._getCustomIncludes(files, dirname, { followSymlinks }); | ||||||||||
this._getDefaultIgnores(files, dirname, { followSymlinks }); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put default ignores before custom includes so it's possible to re-include something that got ignored. |
||||||||||
this._getCustomIgnores(files, dirname, { followSymlinks }); | ||||||||||
|
||||||||||
// Add files to fileMapping | ||||||||||
Array.from(files.values()).sort(); | ||||||||||
files.forEach((file) => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly this works but you're not getting the benefits of the sort
Suggested change
|
||||||||||
// source relative to the base directory of the fileMapping (current directory) | ||||||||||
const source = path.relative(fileMapping.basePath, file); | ||||||||||
const target = path.relative(dirname, file); | ||||||||||
fileMapping.map[target] = source; | ||||||||||
}); | ||||||||||
} | ||||||||||
|
||||||||||
_getDefaultIncludes(files, dirname, { followSymlinks }) { | ||||||||||
// Recursively find source files | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically speaking, the default list should probably only have the following specific patterns that are found in src/ and lib/src only:
We don't want to pick up anything in lib/usage/*.ino for example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eberseth Thanks for your feedback! I've made the suggested modifications. Just to confirm, are there any other significant patterns we should consider, given that we now focus on In summary:
A simple yes/no from you is sufficient for me to make the expected modifications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Thanks for the inputs. @rickkas7. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eberseth To continue supporting certain legacy project structures, I will keep the changes to the original ones I had. To make changes to remove support for legacy formats, I am leaning towards getting the requirements sorted more clearly and will create a separate PR with those changes. For now, let's keep this PR focused on the particle.include and ignore files. |
||||||||||
let includes = [ | ||||||||||
'**/*.h', | ||||||||||
|
@@ -793,45 +806,57 @@ module.exports = class CloudCommand extends CLICommandBase { | |||||||||
'**/*.ino', | ||||||||||
'**/*.cpp', | ||||||||||
'**/*.c', | ||||||||||
'**/build.mk', | ||||||||||
'project.properties' | ||||||||||
]; | ||||||||||
|
||||||||||
if (fs.existsSync(includesFile)){ | ||||||||||
//grab and process all the files in the include file. | ||||||||||
const result = utilities.globList(dirname, includes, { followSymlinks }); | ||||||||||
result.forEach((file) => files.add(file)); | ||||||||||
} | ||||||||||
|
||||||||||
includes = utilities.trimBlankLinesAndComments( | ||||||||||
utilities.readAndTrimLines(includesFile) | ||||||||||
); | ||||||||||
hasIncludeFile = true; | ||||||||||
_getCustomIncludes(files, dirname, { followSymlinks }) { | ||||||||||
const includeFiles = utilities.globList(dirname, ['**/particle.include'], { followSymlinks }); | ||||||||||
const result = []; | ||||||||||
|
||||||||||
for (const includeFile of includeFiles) { | ||||||||||
const includeDir = path.dirname(includeFile); | ||||||||||
const globsToInclude = utilities.trimBlankLinesAndComments(utilities.readAndTrimLines(includeFile)); | ||||||||||
if (!globsToInclude || !globsToInclude.length) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
const globList = globsToInclude.map(g => g); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is thing line for? |
||||||||||
const includePaths = utilities.globList(includeDir, globList, { followSymlinks }); | ||||||||||
result.push(...includePaths); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just do |
||||||||||
} | ||||||||||
|
||||||||||
let files = utilities.globList(dirname, includes, { followSymlinks }); | ||||||||||
result.forEach((file) => files.add(file)); | ||||||||||
} | ||||||||||
|
||||||||||
if (fs.existsSync(ignoreFile)){ | ||||||||||
const ignores = utilities.trimBlankLinesAndComments( | ||||||||||
utilities.readAndTrimLines(ignoreFile) | ||||||||||
); | ||||||||||
_getDefaultIgnores(files, dirname, { followSymlinks }) { | ||||||||||
// Recursively find default ignore files | ||||||||||
let ignores = [ | ||||||||||
'lib/*/examples/**/*.*' | ||||||||||
]; | ||||||||||
|
||||||||||
const ignoredFiles = utilities.globList(dirname, ignores, { followSymlinks }); | ||||||||||
files = utilities.compliment(files, ignoredFiles); | ||||||||||
} | ||||||||||
const result = utilities.globList(dirname, ignores, { followSymlinks }); | ||||||||||
result.forEach((file) => files.delete(file)); | ||||||||||
} | ||||||||||
|
||||||||||
// Add files to fileMapping | ||||||||||
files.forEach((file) => { | ||||||||||
// source relative to the base directory of the fileMapping (current directory) | ||||||||||
const source = path.relative(fileMapping.basePath, file); | ||||||||||
_getCustomIgnores(files, dirname, { followSymlinks }) { | ||||||||||
const ignoreFiles = utilities.globList(dirname, ['**/particle.ignore'], { followSymlinks }); | ||||||||||
const result = []; | ||||||||||
|
||||||||||
// If using an include file, only base names are supported since people are using those to | ||||||||||
// link across relative folders | ||||||||||
let target; | ||||||||||
if (hasIncludeFile){ | ||||||||||
target = path.basename(file); | ||||||||||
} else { | ||||||||||
target = path.relative(dirname, file); | ||||||||||
for (const ignoreFile of ignoreFiles) { | ||||||||||
const ignoreDir = path.dirname(ignoreFile); | ||||||||||
const globsToIgnore = utilities.trimBlankLinesAndComments(utilities.readAndTrimLines(ignoreFile)); | ||||||||||
if (!globsToIgnore || !globsToIgnore.length) { | ||||||||||
continue; | ||||||||||
} | ||||||||||
fileMapping.map[target] = source; | ||||||||||
}); | ||||||||||
const globList = globsToIgnore.map(g => g); | ||||||||||
const ignoredPaths = utilities.globList(ignoreDir, globList, { followSymlinks }); | ||||||||||
result.push(...ignoredPaths); | ||||||||||
} | ||||||||||
result.forEach((file) => files.delete(file)); | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intention to stack the settings on top of each other? For example, the
_getDefaultIncludes()
will add a bunch of patterns then_getCustomIncludes()
will add to the existing pattern list, and so on? Or if the custom list is present it will clear any of the default patterns?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The custom list will not clear the list of files added by the default list. The difference is in files added by the system (_getDefaultIncludes) vs. user (_getCustomIncludes)
Here's what you can expect from this functionality:
_getDefaultIncludes
will add the default files as provided in the list into a resultant array that will get sent to the cloud compiler. Default list doesn't look at user inputs. It checks the patterns from the system._getCustomIncludes
will include more files as per the patterns in theparticle.include
file as specified by the user. Files added in step1 are not cleared._getDefaultIgnores
will remove any files as specified by the system (currently only lib/helper/examples/)_getCustomIgnores
will remove any files as specified by the user in theparticle.ignore
file.