aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util.h
Commit message (Collapse)AuthorAge
* blaze_util::ConvertPath should not make paths absolute.Gravatar ccalvarin2018-06-07
| | | | | | | | | It does not claim to, and this was already true for posix platforms. Windows platforms, however, always made the path absolute, which was a hard-to-diagnose difference between the two. Similarly, MakeAbsolute was relying on this to be correct for windows, so this change splits the implementation and keeps the behavior consistent. While we're here, also remove the empty-string behavior from MakeAbsolute, and instead make it clear at all sites that this behavior is present and affects accepted flag syntax. We may want to remove this later. RELNOTES: None. PiperOrigin-RevId: 199663395
* Move path-manipulation functions to own library file.Gravatar ccalvarin2018-06-05
| | | | | | | | | | | Leave functions that make file accesses in the file library, and general blaze utilities in the blaze_util file, but move the functions that boil down to string manipulation and path formatting to their own file. (With the exception of getCWD, since absolute path syntax is relevant here.) Doing this largely to consolidate all Windows path control into a single place, so that it's easier to notice inconsistencies. For instance, ConvertPath currently makes Windows paths absolute, but not Posix paths, and MakeAbsolute relies on this behavior. In addition, JoinPath assumes Posix path syntax, which leads to some odd looking paths. These will be fixed in a followup change. (Found these issues while working on #4502, trying to fix the windows-specific system bazelrc.) RELNOTES: None. PiperOrigin-RevId: 199368226
* Keep LANG/LANGUAGE and related environment variables for the process spawned ↵Gravatar lberki2018-04-18
| | | | | | | by "blaze run --direct_run". RELNOTES: None. PiperOrigin-RevId: 193391379
* Remove startup JVM version checkGravatar cushon2018-03-29
| | | | | | | | | | | | This was added during the JDK 7->8 transition to improve the diagnostic when an older-than-supported host_javabase was used. The version number handling doesn't work with JDK 9 (see [1]), and using Bazel binaries with a bundled host_javabase avoid the error entirely so the message is less important. [1] http://openjdk.java.net/jeps/223 PiperOrigin-RevId: 190944476
* Update the client's skeleton logging framework to use it for --client_debug.Gravatar ccalvarin2018-03-21
| | | | | | | | | We are still unable to turn this on to write to files, but there are currently 2 logging systems in use in the client: the inactive one, and the print-to-stderr option triggered by --client_debug. Combine these, so we can use the same logging format for both. Also combine it with the VerboseLogging functionality - it was not documented anywhere and seems redundant. RELNOTES: None. PiperOrigin-RevId: 189979051
* Use std::to_string for non-mingw/cygwinGravatar Loo Rong Jie2018-02-27
| | | | | | | | | | `std::to_string` is faster than `std::stringstream`. This issue only presents in older versions of Mingw/Cygwin. My Mingw64 GCC 7.1.0 has `std::to_string`. I can't determine the exact version of GCC that fixed the issue. Closes #4493. PiperOrigin-RevId: 187145391
* Support negated flags in SearchNullaryOption with last-wins semantics.Gravatar ajmichael2018-01-24
| | | | | | | `blaze --nomaster_bazelrc --master_bazelrc` now uses the master bazelrc. RELNOTES: None PiperOrigin-RevId: 183083839
* Delete unused BlazeUtil#SearchNullaryOptionEverywhere.Gravatar lpino2017-09-20
| | | | PiperOrigin-RevId: 169370539
* Polish blaze_util.ccGravatar lpino2017-08-11
| | | | PiperOrigin-RevId: 164850909
* Implement bash.exe detection logic.Gravatar Dmitry Lomov2017-07-19
| | | | | | | | | | | | | | | | The logic is as follows: 1) search for msys installation 2) search got git-on-Windows installation 3) search in PATH. This happens on every client startup unless BAZEL_SH enviornment variable is set. My measurements show that the time required for this detection is negligible (<10 msec in the worst case). Change-Id: If130e2491a9df5a23954d303f2ccdb932eeed1db PiperOrigin-RevId: 162466913
* Ensure that shutdown commands end the server process before completionGravatar mschaller2017-07-12
| | | | | | | | | | | | | | | | | | | | This change ensures that the server process is terminated before the client process terminates, when evaluating a command that shuts down the server. When completing such a command, the server communicates to the client that the server will terminate itself by setting a termination_expected bit in the final RunResponse message. The client then waits up to 60s for the server process to actually terminate. If it does not, then the client SIGKILLs the server. Also makes the gRPC server stop accepting new commands before the shutdown command completes. Drive-by fix to comments on Search{Un,Null}aryOption. RELNOTES: Commands that shut down the server (like "shutdown") now ensure that the server process has terminated before the client process terminates. PiperOrigin-RevId: 161537480
* cpp: remove all code supporting kServerPidSymlinkGravatar Thiago Farina2017-05-09
| | | | | | | | By this time (6 months later) Bazel clients should no longer need this. Change-Id: Ib058065a0ff3eedc777e95c7d06602ca6744d42a PiperOrigin-RevId: 155478543
* Make Search{Unary,Nullary}Option skip the rest of the args if "--" is found.Gravatar Luis Fernando Pino Duque2017-03-27
| | | | | | -- PiperOrigin-RevId: 151145409 MOS_MIGRATED_REVID=151145409
* Bazel client: get rid of RunProgramGravatar Laszlo Csomor2016-12-15
| | | | | | | | | | | | | | | | | | Move GetJvmVersion from blaze_util to blaze_util_platform, and remove the RunProgram declaration from blaze_util.h. Since GetJvmVersion is the only user of RunProgram this is safe to do, and allows making RunProgram static as well as simplifying its implementation on Windows, while also changing it to use CreateProcessW instead of CreateProcessA. See https://github.com/bazelbuild/bazel/issues/2181 -- PiperOrigin-RevId: 142122045 MOS_MIGRATED_REVID=142122045
* Add SearchUnaryOptions and SearchNullaryOptions to improve the parsingGravatar Luis Fernando Pino Duque2016-12-09
| | | | | | | | | | | | of the startup options. This allows us to do the following: - Avoid using the product name when reporting startup option parsing errors. - Passing --bazelrc as a command argument throws an error (fix for issue #1659). -- PiperOrigin-RevId: 141445030 MOS_MIGRATED_REVID=141445030
* Bazel client: add/remove include statementsGravatar Laszlo Csomor2016-12-06
| | | | | | -- PiperOrigin-RevId: 141157873 MOS_MIGRATED_REVID=141157873
* Bazel client: more platform-specific logicGravatar Laszlo Csomor2016-11-28
| | | | | | | | | | Move terminal-querying functions and GetUserName from blaze_util.cc into blaze_util_<platform>. See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140346402
* Bazel client: platform-specific {Read,Write}FileGravatar Laszlo Csomor2016-11-28
| | | | | | | | | | | | | | | | Move blaze::ReadFile and blaze::WriteFile to file.h and file_platform.h (thus into the blaze_util namespace), and update references. This allows us to implement these methods in a platform-specific way. Also move UnlinkPath. See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140328273
* Bazel client: mock out read/write callsGravatar Laszlo Csomor2016-11-28
| | | | | | | | | | | | | | | | | | | | | | | | | Make blaze::ReadFileDescriptor(int fd, ...) and blaze::WriteFile(int fd, ...) platform-independent by mocking out the read(2) and write(2) calls. Also rename ReadFileDescriptor to ReadFrom and introduce a new WriteTo method that encapsulates WriteFile's prior logic. In particular these functions now take a read_func/write_func function argument instead of a file descriptor, so the read(2)/write(2) calls can be mocked out. This allows us to use these functions on Windows too, where read(2)/write(2) are not implemented, and we can inject a different read_func/write_func. See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140195973
* Bazel client: depend less on <unistd.h>Gravatar Laszlo Csomor2016-11-24
| | | | | | | | | | | | | | | | | We moved most of the functionality (e.g. _exit, SetupStreams) into blaze_util_<platform> or changed to alternative functions (fwrite + stderr instead of write + STDERR_HANDLE). This change brings us closer to compiling blaze.cc with MSVC. We still have to move signal handlers out of blaze.cc as well as code dealing with the server PID. See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140123945
* Bazel client: delete and don't use the server.pidGravatar Laszlo Csomor2016-11-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upon startup the Bazel client checks if there's already a running server process and if so then connects to it. We achieve this by checking if there's a symlink in the server directory called served.pid, pointing to /proc/<server_pid>. If so, we read the symlink's target and extract the PID; otherwise we check if there's a file in the server's directory (server.pid.txt) that contains the PID and read it from there. Since the PID file is always there, we don't need the symlink, plus on Windows we don't support symlinks anyway, which is the real motivation for this change. Just ignoring the PID symlink is not enough, we need to actively delete it so that switching between Bazel versions (one that writes a PID symlink and one that doesn't) won't result in having a symlink and PID file with different PIDs and clients trying to kill the wrong server process / not killing one that they should. See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140117287
* Bazel client: fix compiler warningsGravatar Laszlo Csomor2016-11-22
| | | | | -- MOS_MIGRATED_REVID=139899429
* Bazel client: reduce dependency on POSIX APIGravatar Laszlo Csomor2016-11-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can now compile blaze_util_windows.cc with MSVC, yay! (when building //src:bazel --cpu=x64_windows_msvc -k). There are a lot of #ifdef's and TODOs so this is a modest victory for now. In this change: - change blaze::MakeDirectories to return bool instead of int, since that's how it was used anyway, and to expect the permission mask as unsigned int instead of mode_t, since the former is good enough and compatible with mode_t on POSIX while mode_t is not defined on Windows - move blaze::MakeDirectories into blaze_util_<platform> - implement envvar-handling in blaze_util_<platform> and use it everywhere See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=139887503
* Provide a SplitCommandLine method in the option processorGravatar Luis Fernando Pino Duque2016-11-21
| | | | | | | | | | | | | that takes a given command line args and splits it into the corresponding {binary, startup_args, command, command_args}. The purpose of this function is to help split the responsibilities of the ParseOptions function by processing the startup options independently (i.e. rc files detection and processing) from the command options. This will be combined with ParseOptions in a subsequent CL. -- MOS_MIGRATED_REVID=139773786
* Bazel client: reduce dependency on <unistd.h>Gravatar Laszlo Csomor2016-11-18
| | | | | | | | | | | | | | | | | | In this change: - rename WriteFileToStreamOrDie to WriteFileToStderrOrDie (since we only ever used it for stderr) - replace open/write/read/close operations with blaze_util::ReadFile/WriteFile - wrap ToString(getpid()) in a utility function - move SyncFile to file_<platform> -- MOS_MIGRATED_REVID=139560397
* cpp: header hygienizationGravatar Thiago Farina2016-10-18
| | | | | | | | | | | * remove "using std::" declarations from header files * add missing "std::" to some string declarations at some header files * add "using std::string;" to some source files where necessary -- Change-Id: Ib64f62b5add499d6171fa922227194ac992fa542 Reviewed-on: https://bazel-review.googlesource.com/#/c/6630/ MOS_MIGRATED_REVID=136355671
* cpp: convert ServerPidFile() and ServerPidSymlink() into constantsGravatar Thiago Farina2016-09-21
| | | | | | | | | | | These two functions have no logic inside it, they just return a string, and a string that does not change, so they might be better expressed as real C/C++ constants. This might as well generate some better (and less) code anyway. -- Change-Id: I78673c537c17c2665a74c5778e45a4d41a5f7b50 Reviewed-on: https://bazel-review.googlesource.com/#/c/6114 MOS_MIGRATED_REVID=133805201
* Roll back commit a34c4febbbdfba6c045598101ca9a491cfde7dd9 in favor of not ↵Gravatar Lukacs Berki2016-09-14
| | | | | | | | | verifying the identity of the process killed on interrupt. When the server dies, the client follows soon after, so this is kind of OK. -- MOS_MIGRATED_REVID=133110872
* Don't use fancy STL data structures (including string) in ↵Gravatar Lukacs Berki2016-09-06
| | | | | | | KillServerProcess() so that we don't call malloc() in signal handlers. -- MOS_MIGRATED_REVID=132232499
* Update bazel's emacs check for 25.1's INSIDE_EMACS move.Gravatar Googler2016-09-01
| | | | | | | | | | History in https://github.com/emacs-mirror/emacs/blo[]f125aa3de06fa0180a83ec7b5a26970309eeeb6/etc/NEWS#L1769-L1773 RELNOTES: Emacs' [C-x `], a.k.a. next-error, works again in emacsen >= 25.1 -- MOS_MIGRATED_REVID=131851164
* cpp: fix documentation of return value of GetNullaryOption() functionGravatar Thiago Farina2016-07-26
| | | | | | | | | | GetNullaryOption() is a function whose return type is bool, which can only return two possible values, true or false, and thus can not return NULL. -- Change-Id: If9fc622d7132b15268bdcc76aed8d04fe5b92bc7 Reviewed-on: https://bazel-review.googlesource.com/#/c/4140/2 MOS_MIGRATED_REVID=128448779
* Remove the check for the existence of the server process in the signal ↵Gravatar Lukacs Berki2016-06-21
| | | | | | | | | handler in the client. This makes Ctrl-C work on Windows somewhat: in particular, in non-batch mode and while no actions are running. -- MOS_MIGRATED_REVID=125318172
* Revert server.pid to be a symlink so that old server version can shut down ↵Gravatar Lukacs Berki2016-04-26
| | | | | | | | | new ones. Add server.pid.txt that contains the same information in text form. ExecuteDaemon() on Windows will simply not write server.pid . -- MOS_MIGRATED_REVID=120802055
* Factor out various ways to execute subprocesses into separate functions.Gravatar Lukacs Berki2016-04-25
| | | | | | | This is so that they can be implemented properly for Windows. For now, though, they are left in blaze_util.cc since the Windows implementations aren't there yet. -- MOS_MIGRATED_REVID=120709884
* cpp: keep the documentation of MakeAbsolute() function up-to-dateGravatar Thiago Farina2016-04-22
| | | | | | | | | | | | | | commit 2ad804cef42f: ("Fixed bugs blocking bazel shell test on Windows"), updated the documentation in blaze_util.cc but forgot to update the same doc comment in the header file. To prevent this from happening again, this copies the added sentence to the header file and deletes the documentation from the source file. -- Change-Id: I240b3a31d7b457ef4d50558f1ca54619666b8d2c Reviewed-on: https://bazel-review.googlesource.com/#/c/3470 MOS_MIGRATED_REVID=120561630
* Remove unused declared function AddJVMSpecificArguments.Gravatar Nathan Harmata2016-03-11
| | | | | | | | | Kudos to @tfarina for pointing out this dead function declaration. An older commit (prior to bazel being open sourced) moved the file out of blaze_util.cc but forgot to delete the function declaration from the header file. And a subsequent change (also before bazel was open sourced) renamed/moved the implementation to a place that is now internal-only. -- MOS_MIGRATED_REVID=116980458
* cpp: some minor changes to the usage of DeleteFile() functionGravatar Thiago Farina2016-03-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This functions was introduced by commit bf98f39d5d69: "Add the ability to customize the bazel client's...", but at that time it didn't update EnsureCorrectRunningVersion() function, that uses unlink() function, to use DeleteFile() as well. So this patch updates EnsureCorrectRunningVersion() to make use of it now. While there is nothing wrong with the current name, it is not very much correct from the documentation point. If the path is a symlink, unlink() will just the symbolic link and the file won't be removed (affected at all). Otherwise, if it is just a normal file, it will just decrement the link count of the file and when that count reaches zero (0) then the file will longer be accessible. So while at it we renamed the function to UnlinkPath(), but could just stay as DeleteFile() if we wanted. In this process we also improved the documentation for this function to be a little more clear and removed moved it from the source file, since the header file already has it. For further reference, adhere to the documentation in http://pubs.opengroup.org/onlinepubs/009695399/functions/unlink.html. -- Change-Id: I0fc569f3324322cbc67a8fb540836c127f5c3399 Reviewed-on: https://bazel-review.googlesource.com/#/c/3061/ MOS_MIGRATED_REVID=116769254
* Add the ability to customize the bazel client's exit code used when the ↵Gravatar Nathan Harmata2016-01-08
| | | | | | | bazel server exits abruptly. -- MOS_MIGRATED_REVID=111641619
* Rationalize copyright headersGravatar Damien Martin-Guillerez2015-09-25
| | | | | | | | | | | The headers were modified with `find . -type f -exec 'sed' '-Ei' 's|Copyright 201([45]) Google|Copyright 201\1 The Bazel Authors|' '{}' ';'` And manual edit for not Google owned copyright. Because of the nature of ijar, I did not modified the header of file owned by Alan Donovan. The list of authors were extracted from the git log. It is missing older Google contributors that can be added on-demand. -- MOS_MIGRATED_REVID=103938715
* Avoid command line argument mangling on Windows.Gravatar Dmitry Lomov2015-08-12
| | | | | | | | | | | | | | exec(3) under mingw converts every command line argument that looks like Unix path into Windows path when executing non-mingw images (criteria for non-mingw image is that the image does not depend on msys-<version>.dll). This affects bazel labels (`//foo:bar` becomes `/foo:bar` for example). This CL: 1) Replaces usage of execv(3) with Windows-native CreateProcess. 2) Converts all command line arguments that are indeed paths into Windows paths. -- MOS_MIGRATED_REVID=100386350
* Use custom util instead of std::to_string.Gravatar Googler2015-07-23
| | | | | | | std::to_string is not avcaliable on mingw. -- MOS_MIGRATED_REVID=98923935
* Cleanup: Remove unused Is64BitBlazeJavabase() function declaration.Gravatar Thiago Farina2015-06-01
| | | | | | | | | | This function has only a declaration, no implementation and thus no uses. Confirmed that it has no uses internally as well. -- Change-Id: Ifd9214b546f304077e4d729bf22abf6b49cc6af1 Reviewed-on: https://bazel-review.googlesource.com/1411 MOS_MIGRATED_REVID=94763256
* Remove unused helper functions.Gravatar Han-Wen Nienhuys2015-05-27
| | | | | -- MOS_MIGRATED_REVID=94577279
* Cleanup: Pass std::string arguments by reference (this avoids makingGravatar Thiago Farina2015-05-18
| | | | | | | | | | | | | unnecessary copies) and label them const, per the Google style guide. Tested: $ ./bootstrap_test.sh all -- Change-Id: I17636703cf43283f71b9b913c130a51065bd896b Reviewed-on: https://bazel-review.googlesource.com/1350 MOS_MIGRATED_REVID=93876332
* Remove race condition from directory creation in launcherGravatar Kristina Chodorow2015-05-15
| | | | | | | | | If someone ran two Bazel commands at the same time, the second mkdir call could fail because the first had already created the directory MakeDirectories was being called on. -- MOS_MIGRATED_REVID=93531813
* Update include guards.Gravatar Han-Wen Nienhuys2015-05-15
| | | | | -- MOS_MIGRATED_REVID=93413161
* Cleanup: Remove GetJvm() function declaration.Gravatar Thiago Farina2015-05-07
| | | | | | | | There is no implementation and thus nobody is calling/using it. -- Change-Id: I2cf184e3d80eb0ef2b04ea4617697e8426cc7a58 MOS_MIGRATED_REVID=93018104
* Cleanup: Do not include unnecessary headers in blaze_util.h.Gravatar Thiago Farina2015-04-28
| | | | | | | | | | | | The header only uses std::string, std::vector, int and char types, and thus all these headers do not need to be included there. If necessary, they should be included in the relevant source files instead. -- Change-Id: Id1849a0f427016dcf732fe6bfc673e599e8d4b14 MOS_MIGRATED_REVID=92192506
* Move blaze_exit_code.h into util/ directory.Gravatar Thiago Farina2015-04-24
| | | | | | | | This is so util/ files do not depend on anything from higer level. -- Change-Id: I522be6722851f25e79d9c2b85275856cbbd978de MOS_MIGRATED_REVID=91882837
* Header cleanups.Gravatar Han-Wen Nienhuys2015-04-22
| | | | | -- MOS_MIGRATED_REVID=91681168