mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
CB-11771 Deep symlink directories to target project instead of linking the directory itself
When installing a plugin with custom library using the --link option the whole directory is symlinked and temporary files leak into the original plugin directory on build. This leads to broken builds if the same plugin is linked in 2 projects targeting different Cordova versions. This closes #326
This commit is contained in:
parent
d7c1dc5517
commit
2e37d2c253
28
bin/templates/cordova/lib/pluginHandlers.js
vendored
28
bin/templates/cordova/lib/pluginHandlers.js
vendored
@ -231,17 +231,9 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
|
|||||||
throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project');
|
throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project');
|
||||||
|
|
||||||
shell.mkdir('-p', path.dirname(dest));
|
shell.mkdir('-p', path.dirname(dest));
|
||||||
var srcStat = fs.statSync(src);
|
|
||||||
if (link) {
|
if (link) {
|
||||||
//CB-11683 We need to handle linking to directories on our own because Windows doesn't.
|
symlinkFileOrDirTree(src, dest);
|
||||||
var type;
|
} else if (fs.statSync(src).isDirectory()) {
|
||||||
if (srcStat.isDirectory()) {
|
|
||||||
type = 'dir';
|
|
||||||
} else {
|
|
||||||
type = 'file';
|
|
||||||
}
|
|
||||||
fs.symlinkSync(path.relative(path.dirname(dest), src), dest, type);
|
|
||||||
} else if (srcStat.isDirectory()) {
|
|
||||||
// XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
|
// XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
|
||||||
shell.cp('-Rf', src+'/*', dest);
|
shell.cp('-Rf', src+'/*', dest);
|
||||||
} else {
|
} else {
|
||||||
@ -258,6 +250,22 @@ function copyNewFile (plugin_dir, src, project_dir, dest, link) {
|
|||||||
copyFile(plugin_dir, src, project_dir, dest, !!link);
|
copyFile(plugin_dir, src, project_dir, dest, !!link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function symlinkFileOrDirTree(src, dest) {
|
||||||
|
if (fs.existsSync(dest)) {
|
||||||
|
shell.rm('-Rf', dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.statSync(src).isDirectory()) {
|
||||||
|
shell.mkdir('-p', dest);
|
||||||
|
fs.readdirSync(src).forEach(function(entry) {
|
||||||
|
symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fs.symlinkSync(path.relative(fs.realpathSync(path.dirname(dest)), src), dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// checks if file exists and then deletes. Error if doesn't exist
|
// checks if file exists and then deletes. Error if doesn't exist
|
||||||
function removeFile (project_dir, src) {
|
function removeFile (project_dir, src) {
|
||||||
var file = path.resolve(project_dir, src);
|
var file = path.resolve(project_dir, src);
|
||||||
|
Loading…
Reference in New Issue
Block a user