aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util.cc
Commit message (Collapse)AuthorAge
* 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: 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: platform-dependent lock handlingGravatar Laszlo Csomor2016-11-28
| | | | | | | | | | Move blaze::AcquireLock and blaze::ReleaseLock into blaze_util_<platform>. See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140200355
* 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: 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
* Bazel client: wrap some POSIX functionsGravatar Laszlo Csomor2016-11-10
| | | | | | | | | | | | | | This change: - starts using blaze_util::CanAccess and blaze_util::PathExists instead of access(2) - implements and starts using blaze_util::GetCwd instead of getcwd(2) - implements and starts using blaze_util::ChangeDirectory instead of chdir(2) - adds tests for the new wrapper methods -- MOS_MIGRATED_REVID=138750297
* C++ refactor: time getters now return millisecondsGravatar Laszlo Csomor2016-11-08
| | | | | | | | | | | | | | Previously they returned nanoseconds but all call sites converted those to milliseconds. This is not only a simplification of the semantics and renaming of the methods to make the returned units and the purpose clear, but also preparation for the Windows/MSVC implementations of these methods. -- MOS_MIGRATED_REVID=138383956
* 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
* More client fixes:Gravatar Lukacs Berki2016-09-13
| | | | | | | | - Use an explicit cast to void to tell the compiler that we are intentionally ignoring return values. - Delete the unused function GetPeerProcessId() -- MOS_MIGRATED_REVID=132970162
* Various minor fixes in the client:Gravatar Lukacs Berki2016-09-09
| | | | | | | | | - Don't call setrlimit() (it was needed to make 32-bit JVMs work with >3GB heaps) - Remove a non-functional way to tweak the Linux scheduler - Cosmetic fixes -- MOS_MIGRATED_REVID=132653426
* 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
* Placate the compiler.Gravatar Sasha Smundak2016-07-26
| | | | | | | | | | | | Address the following warnings from the compiler: * "control reaches end of non-void function [-Wreturn-type]" * "dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]" * "ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]" * "ignoring return value of 'int ftruncate(int, __off_t)', declared with attribute warn_unused_result [-Wunused-result]" * "ignoring return value of 'int dup(int)', declared with attribute warn_unused_result [-Wunused-result]" -- MOS_MIGRATED_REVID=128375065
* 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
* Acquire the server lock even if the client uses gRPC.Gravatar Lukacs Berki2016-04-28
| | | | | | | | | This is so that only one server instance is started up if two clients are started in a workspace that doesn't have a running server yet. More work towards #930. This may break Windows in case flock() doesn't work there as expected. In anticipation of this, locking is moved to blaze_util_platform.h / blaze_util.cc . -- MOS_MIGRATED_REVID=121013078
* Make compilation on Windows work again.Gravatar Lukacs Berki2016-04-28
| | | | | | | | | Fixes #1205 . -- Change-Id: Ifd35cf141737f755b499a786cf9663153cd2cf53 Reviewed-on: https://bazel-review.googlesource.com/#/c/3513/ MOS_MIGRATED_REVID=120998788
* Use native process control on Windows to launch subprocesses.Gravatar Lukacs Berki2016-04-27
| | | | | | | | | This is necessary because msys2 signals don't work on native Win32 processes, for example, java.exe . Forcefully terminating the process still doesn't work because it uses signals. It's a-coming. -- MOS_MIGRATED_REVID=120903711
* 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
* Fixed bugs blocking bazel shell test on WindowsGravatar Yun Peng2016-04-20
| | | | | | | -- Change-Id: I6a2f9026fda578905ccb72b317223eaca16b882b Reviewed-on: https://bazel-review.googlesource.com/#/c/3440 MOS_MIGRATED_REVID=120228541
* 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
* Fix compile warningsGravatar Kristina Chodorow2015-09-09
| | | | | | | | | | | | | | | | | | | | | | | | | | This was printing: src/main/cpp/blaze_util.cc: In function 'bool blaze::WriteFile(const string&, const string&)': src/main/cpp/blaze_util.cc:211:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] return r == content.size(); ^ src/main/cpp/blaze_util.cc: In function 'bool blaze::CheckJavaVersionIsAtLeast(const string&, const string&)': src/main/cpp/blaze_util.cc:334:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (i = 0; i < jvm_version_vect.size() && i < version_spec_vect.size(); ^ src/main/cpp/blaze_util.cc:334:73: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (i = 0; i < jvm_version_vect.size() && i < version_spec_vect.size(); ^ src/main/cpp/blaze_util.cc:344:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (i < version_spec_vect.size()) { ^ src/main/cpp/blaze_util.cc:345:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (; i < version_spec_vect.size(); i++) { This also fixes that we weren't checking write()'s return code. -- MOS_MIGRATED_REVID=102656105
* Port to FreeBSD.Gravatar Doug Rabson2015-08-26
| | | | | | | -- Change-Id: I4e65cc583e758d2f7e45209ffcb37f6a871e2ed7 Reviewed-on: https://bazel-review.git.corp.google.com/#/c/1840 MOS_MIGRATED_REVID=101462155
* 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
* Fix some C++ compiler warnings to comply with -Wall.Gravatar Ulf Adams2015-07-27
| | | | | | | | | Some progress towards #311. -- Change-Id: I9276519d4a97d358b7c4f4e34a861522d75dd495 Reviewed-on: https://bazel-review.googlesource.com/#/c/1710 MOS_MIGRATED_REVID=99019961
* launcher: observe umask in MakeDirectories.Gravatar Han-Wen Nienhuys2015-06-01
| | | | | -- MOS_MIGRATED_REVID=94905648
* 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
* 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
* Cleanup: Build file.cc as part of util library.Gravatar Thiago Farina2015-04-14
| | | | | | | | | | | | | | | | | | | | | | Looks like in the transition it was forgotten to be moved to the new location. As an effect of this change it was discovered that file.cc had an dependency back on blaze_util.cc (from client binary for die/pdie functions). In order to fix that dependency we have had to move die/pdie functions into util library (added errors.(cc|h)) for this. Tested on Linux with the following command lines: $ ./compile.sh $ ./output/bazel build //src/main/cpp:all $ ./output/bazel build //src:bazel $ ./bootstrap_test.sh all -- Change-Id: I70fb1b6189dc5af31f816332d76efe380ef26302 MOS_MIGRATED_REVID=90987514
* Fix TODO in recursive directory creationGravatar Kristina Chodorow2015-04-08
| | | | | -- MOS_MIGRATED_REVID=90517845
* Read the whole file descriptor instead of reading part of it for java ↵Gravatar Damien Martin-Guillerez2015-02-10
| | | | | | | | | -version parsing. The one-time read sometime fails when the JAVA_TOOL_OPTIONS is set making Bazel unable to detect JDK version. -- MOS_MIGRATED_REVID=85984806
* Update from Google.Gravatar Han-Wen Nienhuys2015-02-25
-- MOE_MIGRATED_REVID=85702957