diff --git a/Mcode/+matpatch/Patch.m b/Mcode/+matpatch/Patch.m index 6669c64..8eefa5d 100644 --- a/Mcode/+matpatch/Patch.m +++ b/Mcode/+matpatch/Patch.m @@ -232,7 +232,17 @@ function harvest(this) info.MatlabVersion, matpatch.Shed.matlabVersion); return end - % TODO: Detect whether a Unix-y diff is installed on Windows + % Detect whether a Unix-y diff is installed on Windows + if ispc + [status, output] = system('diff --version'); + if status ~= 0 + logger.warn('Can''t find a diff command.'); + logger.info('This is probably because you don''t have diffutils installed.'); + logger.info('Try installing diffutils from http://gnuwin32.sourceforge.net/packages/diffutils.htm'); + logger.info('And make sure to add them to your %%PATH%%.') + return + end + end % We can't diff directly against the Matlab installation, because we want % to ignore non-existent files only on one side. So create a staging @@ -262,19 +272,11 @@ function harvest(this) userInfo.Name, userInfo.Email, datestr(now), ... info.MatlabVersion, computer); matpatch.Shed.spew(this.patchFile, header); - if isunix - cmd = sprintf('LC_ALL=C diff -Nru "%s" . >> "%s"', ... - tempDir, this.patchFile); - else - % Just hope that there is a Unix-y diff installed - cmd = sprintf('diff -Nru "%s" . >> "%s"', ... - tempDir, this.patchFile); - end - [status,output] = system(cmd); - if status ~= 0 - mperror('Running diff failed: %s', output); - return - end + cmd = sprintf('diff -Nru "%s" . >> "%s"', ... + tempDir, this.patchFile); + [~,~] = system(cmd); + % We're just ignoring the exit status because diff returns nonzero if + % the files differ, and we can't differentiate that from failure. matpatch.Shed.rmrf(tempDir); diff --git a/Mcode/+matpatch/Shed.m b/Mcode/+matpatch/Shed.m index 0a5e7b5..91fc1c4 100644 --- a/Mcode/+matpatch/Shed.m +++ b/Mcode/+matpatch/Shed.m @@ -51,7 +51,7 @@ function cpr(src, dest) function rmrf(target) % Recursively, forcibly remove files if ispc - cmd = sprintf('del /S /F "%s"', target); + cmd = sprintf('del /S /F /Q "%s"', target); else cmd = sprintf('rm -rf "%s"', target); end @@ -76,7 +76,7 @@ function spew(file, txt) if fid < 1 error("Failed opening file '%s' for writing: %s", file, msg); end - RAII.fid = @() fclose(fid); %#ok + RAII.fid = onCleanup(@() fclose(fid)); fprintf(fid, '%s', txt); end diff --git a/Mcode/+matpatch/activate.m b/Mcode/+matpatch/activate.m index b1fba75..cf70ba0 100644 --- a/Mcode/+matpatch/activate.m +++ b/Mcode/+matpatch/activate.m @@ -33,4 +33,4 @@ function activate(patchNameOrPrefix) matpatch.Shed.activatePatch(patchName); -logger.info("Walked over to patch %s", patchName); +logger.info("Now gardening patch %s", patchName); diff --git a/README.md b/README.md index 07aa5b0..8183e1b 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,14 @@ But do that at your own risk; it is an unsupported configuration. WARNING! Matlab is proprietary, commerical software. Its contents are the intellectual property of MathWorks. The patches you create are derived works of Matlab, and will also contain MathWorks' intellectual property. Do not give access to your patches to anyone unless you have verified that they have a currently active Matlab license! +## Requirements + +On Windows, you need to install [GNU diffutils](http://gnuwin32.sourceforge.net/packages/diffutils.htm) or something else that gives you a Unix-y `diff` command. + +MatPatchGardener requires the latest release of Matlab. +(There's not much point in producing patches for older releases.) +As of this writing, that's Matlab R2019b. + ## Quick Start ```matlab @@ -50,12 +58,6 @@ The easiest way to do this is to cd to the `Mcode/` directory under the MatPatch If this is your first time gardening, `matpatch.wakeup` will walk you through an interactive setup of your user info. -## Requirements - -MatPatchGardener requires the latest release of Matlab. -(There's not much point in producing patches for older releases.) -As of this writing, that's Matlab R2019b. - ## Author MatPatchGardner is written by [Andrew Janke](https://apjanke.net).